MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / Initialize

Function Initialize

pkg/telemetry/tracing/tracing.go:51–80  ·  view source on GitHub ↗

Initialize initializes the tracing package and returns the tracer provider. If tracing is not enabled it returns a noop tracer provider instead.

(ctx context.Context, config *Config)

Source from the content-addressed store, hash-verified

49// Initialize initializes the tracing package and returns the tracer provider.
50// If tracing is not enabled it returns a noop tracer provider instead.
51func Initialize(ctx context.Context, config *Config) (otrace.TracerProvider, func(context.Context) error, error) {
52 if !config.Enable {
53 return noop.NewTracerProvider(), func(_ context.Context) error { return nil }, nil
54 }
55
56 exp, err := exporterFromConfig(ctx, config)
57 if err != nil {
58 return nil, nil, err
59 }
60 bsp := sdktrace.NewBatchSpanProcessor(exp)
61
62 rsc, err := initResource(ctx)
63 if err != nil {
64 return nil, nil, err
65 }
66
67 tp := sdktrace.NewTracerProvider(
68 sdktrace.WithSpanProcessor(bsp),
69 sdktrace.WithResource(rsc),
70 sdktrace.WithSampler(sdktrace.ParentBased(
71 sdktrace.TraceIDRatioBased(config.SampleProbability),
72 )),
73 )
74
75 otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(
76 propagation.TraceContext{},
77 propagation.Baggage{},
78 ))
79 return tp, tp.Shutdown, nil
80}

Callers 1

start.goFile · 0.92

Calls 2

exporterFromConfigFunction · 0.85
initResourceFunction · 0.85

Tested by

no test coverage detected