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)
| 49 | // Initialize initializes the tracing package and returns the tracer provider. |
| 50 | // If tracing is not enabled it returns a noop tracer provider instead. |
| 51 | func 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 | } |
no test coverage detected