-
Notifications
You must be signed in to change notification settings - Fork 3
/
tracerProvider.go
46 lines (40 loc) · 1.43 KB
/
tracerProvider.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package jaegerKit
import (
"github.com/richelieu-yang/chimera/v2/src/core/interfaceKit"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/exporters/jaeger"
"go.opentelemetry.io/otel/sdk/resource"
"go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.17.0"
)
// NewTracerProvider
/*
参考官方demo: https://github.com/open-telemetry/opentelemetry-go/blob/main/example/jaeger/main.go
tracerProvider returns an OpenTelemetry TracerProvider configured to use
the Jaeger exporter that will send spans to the provided url. The returned
TracerProvider will also use a Resource configured with all the information
about the application.
@param url e.g."http://localhost:14268/api/traces"
*/
func NewTracerProvider(url string, rc *ResourceConfig) (*trace.TracerProvider, error) {
if err := interfaceKit.AssertNotNil(rc, "rc"); err != nil {
return nil, err
}
// Create the Jaeger exporter
exporter, err := jaeger.New(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(url)))
if err != nil {
return nil, err
}
tp := trace.NewTracerProvider(
// Always be sure to batch in production.
trace.WithBatcher(exporter),
// Record information about this application in a Resource.
trace.WithResource(resource.NewWithAttributes(
semconv.SchemaURL,
semconv.ServiceName(rc.ServiceName),
attribute.String("environment", rc.Environment),
attribute.Int64("ID", rc.ID),
)),
)
return tp, nil
}