github.com/thanos-io/thanos@v0.32.5/pkg/tracing/otlp/otlp_test.go (about) 1 // Copyright (c) The Thanos Authors. 2 // Licensed under the Apache License 2.0. 3 4 package otlp 5 6 import ( 7 "context" 8 "testing" 9 10 "github.com/efficientgo/core/testutil" 11 "github.com/thanos-io/thanos/pkg/tracing" 12 "github.com/thanos-io/thanos/pkg/tracing/migration" 13 14 "github.com/go-kit/log" 15 tracesdk "go.opentelemetry.io/otel/sdk/trace" 16 "go.opentelemetry.io/otel/sdk/trace/tracetest" 17 ) 18 19 // This test creates an OTLP tracer, starts a span and checks whether it is logged in the exporter. 20 func TestContextTracing_ClientEnablesTracing(t *testing.T) { 21 exp := tracetest.NewInMemoryExporter() 22 23 tracerOtel := newTraceProvider( 24 context.Background(), 25 tracesdk.NewSimpleSpanProcessor(exp), 26 log.NewNopLogger(), 27 "thanos", 28 tracesdk.AlwaysSample()) 29 tracer, _ := migration.Bridge(tracerOtel, log.NewNopLogger()) 30 clientRoot, _ := tracing.StartSpan(tracing.ContextWithTracer(context.Background(), tracer), "a") 31 32 testutil.Equals(t, 0, len(exp.GetSpans())) 33 34 clientRoot.Finish() 35 testutil.Equals(t, 1, len(exp.GetSpans())) 36 testutil.Equals(t, 1, tracing.CountSampledSpans(exp.GetSpans())) 37 }