@@ -359,29 +359,35 @@ func TestInitProvider_WithHeaders(t *testing.T) {
359359func TestParentContext_WithValidTraceIDAndSpanID (t * testing.T ) {
360360 ctx := context .Background ()
361361
362+ // Initialize noop provider to set up the W3C propagator globally
363+ provider , err := tracing .InitProvider (ctx , nil )
364+ require .NoError (t , err )
365+ defer provider .Shutdown (ctx )
366+
362367 cfg := & config.TracingConfig {
363368 Endpoint : "https://example.com" ,
364369 TraceID : "4bf92f3577b34da6a3ce929d0e0e4736" ,
365370 SpanID : "00f067aa0ba902b7" ,
366371 }
367372
368373 parentCtx := tracing .ParentContext (ctx , cfg )
369- sc := trace .SpanFromContext (parentCtx ).SpanContext ()
370-
371- // ParentContext should inject a remote span context, not a local span.
372- // The remote span context is accessible via trace.SpanContextFromContext after
373- // trace.ContextWithRemoteSpanContext is used — check via propagation round-trip.
374- // Instead of checking SpanFromContext (which returns noop span in the absence of a started span),
375- // extract the remote span context directly.
376- remoteCtx := trace .SpanContextFromContext (parentCtx )
377- if ! remoteCtx .IsValid () {
378- // Check the context for the remote parent
379- // The remote span context might not be on the regular span context
380- t .Logf ("SpanFromContext returned: %v" , sc )
381- t .Logf ("SpanContextFromContext returned: %v" , remoteCtx )
382- }
383- // Verify the context is enriched (not the zero-value background context)
374+
375+ // The context must be enriched (different from background context)
384376 assert .NotEqual (t , ctx , parentCtx , "ParentContext must return an enriched context" )
377+
378+ // Verify the remote span context contains the correct traceId and spanId
379+ // by extracting it from the context and checking via propagation round-trip.
380+ prop := otel .GetTextMapPropagator ()
381+ carrier := propagation.MapCarrier {}
382+ prop .Inject (parentCtx , carrier )
383+ traceparent := carrier ["traceparent" ]
384+ require .NotEmpty (t , traceparent , "W3C traceparent must be present after injection" )
385+
386+ // traceparent format: 00-{traceId}-{spanId}-{flags}
387+ assert .Contains (t , traceparent , "4bf92f3577b34da6a3ce929d0e0e4736" ,
388+ "traceparent must contain the configured traceId" )
389+ assert .Contains (t , traceparent , "00f067aa0ba902b7" ,
390+ "traceparent must contain the configured spanId" )
385391}
386392
387393// TestParentContext_WithTraceIDOnly verifies that ParentContext works when only traceId is provided.
0 commit comments