Files
opencloud/pkg/tracing/tracing_test.go
T
Jörn Friedrich Dreyer dc7f4433a1 fix(tracing): set the global text map propagator
The go-micro tracing wrappers and otelhttp inject and extract the trace
context with the global propagator. Nobody set it, so it stayed the
default no-op: no traceparent went over the wire and every go-micro
service (settings, policies, eventhistory, search) started a new trace
instead of joining the caller's.

GetTraceProvider now also sets the global propagator to the W3C
TraceContext and Baggage propagator we already use elsewhere.

fixes https://github.com/opencloud-eu/opencloud/issues/3856

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
2026-11-05 16:20:47 +01:00

33 lines
933 B
Go

package tracing
import (
"context"
"testing"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/propagation"
"go.opentelemetry.io/otel/trace"
)
func TestGetTraceProviderSetsGlobalPropagator(t *testing.T) {
if _, err := GetTraceProvider(context.Background(), "none", "test"); err != nil {
t.Fatal(err)
}
sc := trace.NewSpanContext(trace.SpanContextConfig{
TraceID: trace.TraceID{1},
SpanID: trace.SpanID{1},
TraceFlags: trace.FlagsSampled,
})
carrier := propagation.MapCarrier{}
otel.GetTextMapPropagator().Inject(trace.ContextWithSpanContext(context.Background(), sc), carrier)
if carrier.Get("traceparent") == "" {
t.Fatal("global propagator did not inject a traceparent")
}
got := trace.SpanContextFromContext(otel.GetTextMapPropagator().Extract(context.Background(), carrier))
if got.TraceID() != sc.TraceID() {
t.Fatalf("extracted trace id %s, want %s", got.TraceID(), sc.TraceID())
}
}