feat(propagation): adopt envcar carrier for TRACEPARENT#36
Merged
Conversation
Why: #33 / #390 - align env-based trace context propagation with the OTel env-carriers spec by reusing the shared go.opentelemetry.io/contrib carrier instead of hand-formatting TRACEPARENT= strings. Approach: Postel's law, per Amy's guidance. Accept leniently, emit strictly. - Read: envcar.Carrier.Get("traceparent") (spec key normalization) parsed by otel-cli's lenient w3c parser, so upper-case hex is still accepted and downcased rather than rejected. - Emit: route injection through propagation.TraceContext.Inject + an envcar.Carrier{SetEnvFunc}, which guarantees only spec-valid lower-case W3C is ever written, and refuses to emit an invalid/all-zero context. - New otelcli/propagation.go holds the bridge (envCarrierTraceparent, injectTraceparent, spanContextFromTraceparent). config_span.go reads via it; exec.go injects child env via it. Learned: the standard W3C propagator is strict (rejects upper-case + all-zero), so we deliberately keep our lenient parser on the read side and only delegate the *emit* side to the propagator. The pre-existing upper-case fixture stays green because we still accept it and already emit lower-case. Tests: - otelcli/propagation_test.go: graceful upper-case read, empty carrier, strict lower-case emit, and skip-invalid emit. All proven to fail when broken. - functional: exec normalizes an upper-case TRACEPARENT into the child env. Next: #34 - TRACESTATE + BAGGAGE via a composite propagator. Refs #31, #33 🤖 Claude <claude@anthropic.com>
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.
Closes #33. Part of #31 (mirrors equinix-labs/otel-cli#390).
Routes otel-cli's environment-variable trace context propagation through the shared
go.opentelemetry.io/contrib/propagators/envcarcarrier instead of hand-formattingTRACEPARENT=strings.Design: Postel's law (per maintainer guidance)
Accept leniently, emit strictly.
envcar.Carrier.Get("traceparent")(spec key-normalization) parsed by otel-cli's existing lenient W3C parser. Upper-case hex and other lenient input is still accepted and downcased, not rejected. The standardpropagation.TraceContextpropagator is deliberately not used on the read side because it's spec-strict (rejects upper-case + all-zero).propagation.TraceContext.Inject+ anenvcar.Carrier{SetEnvFunc}, which guarantees only spec-valid lower-case W3C is ever written into a child process env, and refuses to emit an invalid/all-zero context.New
otelcli/propagation.goholds the bridge:envCarrierTraceparent,injectTraceparent,spanContextFromTraceparent.config_span.goreads through it;exec.goinjects the child env through it.Compatibility
--tp-*flags,OTEL_CLI_*env vars,--tp-required/--tp-ignore-env, the{{traceparent}}arg substitution, and the shell-sourceabletp-carrierfile format are unchanged (w3c/traceparentstays the file parser/encoder — envcar is env-only).TRACEPARENTfixture stays green: we still accept it and already emit lower-case.Tests
otelcli/propagation_test.go— graceful upper-case read, empty carrier, strict lower-case emit, skip-invalid emit. Each verified to fail when the implementation is broken.otel-cli execnormalizes an upper-caseTRACEPARENTinto a strict lower-case value in the child's environment (proven to bite).Verification
go build✅ ·go vet ./...✅ ·gofmt -l .clean ✅ ·go test ./...(full functional + unit) ✅Follow-ups (noted, out of scope)
{{traceparent}}shadowing in exec non-recording mode;w3c/traceparent.LoadFromEnvnow has no production callers. (tracked in docs/issues.md)Refs #31, #33
🤖 Generated with Claude Code