mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 20:24:18 -06:00
31 lines
755 B
Go
31 lines
755 B
Go
package tracing
|
|
|
|
import (
|
|
"go.opentelemetry.io/otel"
|
|
tracesdk "go.opentelemetry.io/otel/sdk/trace"
|
|
"go.opentelemetry.io/otel/sdk/trace/tracetest"
|
|
)
|
|
|
|
type TracerForTestOption func(tp *tracesdk.TracerProvider)
|
|
|
|
func WithSpanProcessor(sp tracesdk.SpanProcessor) TracerForTestOption {
|
|
return TracerForTestOption(func(tp *tracesdk.TracerProvider) {
|
|
tp.RegisterSpanProcessor(sp)
|
|
})
|
|
}
|
|
|
|
func InitializeTracerForTest(opts ...TracerForTestOption) Tracer {
|
|
exp := tracetest.NewInMemoryExporter()
|
|
tp, _ := initTracerProvider(exp, "testing", tracesdk.AlwaysSample())
|
|
|
|
for _, opt := range opts {
|
|
opt(tp)
|
|
}
|
|
|
|
otel.SetTracerProvider(tp)
|
|
|
|
ots := &TracingService{Propagation: "jaeger,w3c", tracerProvider: tp}
|
|
_ = ots.initOpentelemetryTracer()
|
|
return ots
|
|
}
|