Skip to content

feat(otel): configure W3C trace propagation for distributed tracing#2506

Open
tdabasinskas wants to merge 1 commit intodocker:mainfrom
cogvel:otel_prop
Open

feat(otel): configure W3C trace propagation for distributed tracing#2506
tdabasinskas wants to merge 1 commit intodocker:mainfrom
cogvel:otel_prop

Conversation

@tdabasinskas
Copy link
Copy Markdown
Contributor

Two small additions so traces emitted by the existing OTel SDK chain across processes:

  1. Set the global TextMapPropagator to W3C TraceContext + Baggage in cmd/root/otel.go. Without this, the SDK records spans locally but never injects traceparent on outbound requests.

  2. Wrap the outbound transport in pkg/httpclient with otelhttp.NewTransport, gated on OTEL_EXPORTER_OTLP_ENDPOINT — the same env var that already gates exporter creation in initOTelSDK.

When OTel is disabled — behavior is unchanged. When enabled, each outbound HTTP call emits a CLIENT span and carries traceparent, so cagent traces correlate with downstream gateway/proxy.

Set up composite text map propagator with TraceContext and Baggage to enable distributed tracing across service boundaries. Without this configuration, the SDK records spans locally but cannot chain them across HTTP requests.

Wrap HTTP client transport with otelhttp when OTEL_EXPORTER_OTLP_ENDPOINT is set. This ensures outbound requests emit CLIENT spans and inject the W3C traceparent header, while incoming requests extract trace context. The wrapping is gated on the same environment variable check used in initOTelSDK to avoid allocating spans or sending headers when OpenTelemetry is disabled.

Expose WrapWithOTel helper function so callers building custom transports can opt into the same env-gated instrumentation without duplicating the gating logic.
@tdabasinskas tdabasinskas requested a review from a team as a code owner April 25, 2026 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant