Skip to content

Instantly share code, notes, and snippets.

@TonPC64
Created February 24, 2022 14:33
Show Gist options
  • Save TonPC64/b600bb3e333a547f073ef1c8c8bb23c8 to your computer and use it in GitHub Desktop.
Save TonPC64/b600bb3e333a547f073ef1c8c8bb23c8 to your computer and use it in GitHub Desktop.
init tracer provider and propagator
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