package copilot import ( "context" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/propagation" ) // getTraceContext extracts the current W3C Trace Context (traceparent/tracestate) // from the Go context using the global OTel propagator. func getTraceContext(ctx context.Context) (traceparent, tracestate string) { carrier := propagation.MapCarrier{} otel.GetTextMapPropagator().Inject(ctx, carrier) return carrier.Get("traceparent"), carrier.Get("tracestate") } // contextWithTraceParent returns a new context with trace context extracted from // the provided W3C traceparent and tracestate headers. func contextWithTraceParent(ctx context.Context, traceparent, tracestate string) context.Context { if traceparent == "" { return ctx } carrier := propagation.MapCarrier{ "traceparent": traceparent, } if tracestate != "" { carrier["tracestate"] = tracestate } return otel.GetTextMapPropagator().Extract(ctx, carrier) }