Skip to content

feat(propagation): adopt envcar carrier for TRACEPARENT#36

Merged
tobert merged 1 commit into
mainfrom
feat/envcar-traceparent
Jun 30, 2026
Merged

feat(propagation): adopt envcar carrier for TRACEPARENT#36
tobert merged 1 commit into
mainfrom
feat/envcar-traceparent

Conversation

@tobert

@tobert tobert commented Jun 30, 2026

Copy link
Copy Markdown
Owner

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/envcar carrier instead of hand-formatting TRACEPARENT= strings.

Design: Postel's law (per maintainer guidance)

Accept leniently, emit strictly.

  • Readenvcar.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 standard propagation.TraceContext propagator is deliberately not used on the read side because it's spec-strict (rejects upper-case + all-zero).
  • Emit — injection is routed through propagation.TraceContext.Inject + an envcar.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.go holds the bridge: envCarrierTraceparent, injectTraceparent, spanContextFromTraceparent. config_span.go reads through it; exec.go injects the child env through it.

Compatibility

  • --tp-* flags, OTEL_CLI_* env vars, --tp-required/--tp-ignore-env, the {{traceparent}} arg substitution, and the shell-sourceable tp-carrier file format are unchanged (w3c/traceparent stays the file parser/encoder — envcar is env-only).
  • The existing upper-case-TRACEPARENT fixture 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.
  • Functional fixture — otel-cli exec normalizes an upper-case TRACEPARENT into 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)

Refs #31, #33

🤖 Generated with Claude Code

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>
@tobert tobert merged commit 9c82aa3 into main Jun 30, 2026
1 check passed
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.

feat(propagation): adopt contrib/propagators/envcar for env carrier (TRACEPARENT)

1 participant