feat(otel): configure W3C trace propagation for distributed tracing#2506
Open
tdabasinskas wants to merge 1 commit intodocker:mainfrom
Open
feat(otel): configure W3C trace propagation for distributed tracing#2506tdabasinskas wants to merge 1 commit intodocker:mainfrom
tdabasinskas wants to merge 1 commit intodocker:mainfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two small additions so traces emitted by the existing OTel SDK chain across processes:
Set the global
TextMapPropagatorto W3C TraceContext + Baggage incmd/root/otel.go. Without this, the SDK records spans locally but never injectstraceparenton outbound requests.Wrap the outbound transport in
pkg/httpclientwithotelhttp.NewTransport, gated onOTEL_EXPORTER_OTLP_ENDPOINT— the same env var that already gates exporter creation ininitOTelSDK.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.