Created
February 24, 2022 14:33
-
-
Save TonPC64/b600bb3e333a547f073ef1c8c8bb23c8 to your computer and use it in GitHub Desktop.
init tracer provider and propagator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func init() { | |
var exporter sdktrace.SpanExporter | |
var err error | |
// use zipkin exporter | |
exporter, err = zipkin.New("http://zipkin:9411/api/v2/spans") | |
if err != nil { | |
panic(err) | |
} | |
// use jaeger exporter | |
exporter, err = jaeger.New(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint("http://jaeger:14268/api/traces"))) | |
if err != nil { | |
panic(err) | |
} | |
// new resource with attributes | |
resources := resource.NewWithAttributes( | |
semconv.SchemaURL, | |
semconv.ServiceNameKey.String("webserver-http"), | |
semconv.ServiceVersionKey.String("1.0.0"), | |
) | |
// new tracer provider | |
provider := sdktrace.NewTracerProvider( | |
sdktrace.WithBatcher(exporter), | |
sdktrace.WithSampler(sdktrace.AlwaysSample()), | |
sdktrace.WithResource(resources), | |
) | |
// inject tracer provider | |
otel.SetTracerProvider(provider) | |
// inject propagators | |
// use b3 default config (single header) | |
otel.SetTextMapPropagator(b3.New()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment