feat(api): add experimental env var propagators#3574
Conversation
Add experimental EnvVarExtractor and EnvVarInjector helpers behind the otel_unstable feature flag, document the new API, and add an env-var-propagation example for parent/child process TraceContext propagation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3574 +/- ##
=======================================
+ Coverage 83.2% 83.3% +0.1%
=======================================
Files 130 131 +1
Lines 28231 28457 +226
=======================================
+ Hits 23491 23713 +222
- Misses 4740 4744 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Align the experimental environment variable carriers with the latest spec guidance by removing hidden from_env snapshot helpers and requiring callers to provide environment entries explicitly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add targeted comments to the env-var-propagation example so the parent/child process flow and explicit environment extraction are easier to follow. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds experimental support in the opentelemetry API crate for using environment variables as a TextMapPropagator carrier, enabling parent/child-process context propagation per the OpenTelemetry env-carriers specification (behind the otel_unstable feature).
Changes:
- Introduces
EnvVarExtractorandEnvVarInjectorcarriers underopentelemetry::propagationgated byotel_unstable, including key normalization per spec. - Updates crate docs/README and changelog to document the new experimental API and feature flag.
- Adds a new end-to-end example (
examples/env-var-propagation) demonstrating propagation across a real process boundary.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| opentelemetry/src/propagation/mod.rs | Exposes the new env-var carrier module and re-exports the new types under otel_unstable. |
| opentelemetry/src/propagation/env.rs | Implements the env-var extractor/injector carriers and normalization logic, plus unit tests. |
| opentelemetry/src/lib.rs | Documents the new example link and clarifies what otel_unstable enables. |
| opentelemetry/README.md | Adds user-facing documentation pointing to the env-var propagation helpers and example. |
| opentelemetry/CHANGELOG.md | Records the new experimental API under vNext. |
| opentelemetry/Cargo.toml | Adds the otel_unstable feature and temp-env dev-dependency for tests. |
| examples/env-var-propagation/src/main.rs | New runnable example that injects context into child env vars and extracts in the child process. |
| examples/env-var-propagation/README.md | Documents the example behavior and how to run it. |
| examples/env-var-propagation/Cargo.toml | New example crate manifest enabling otel_unstable on opentelemetry. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
https://github.com/open-telemetry/opentelemetry-rust/actions/runs/28400305177/job/84149540890?pr=3574 looks like a transient error |
|
Thank you for your contribution! This PR has been automatically marked as stale because it has not had activity in the last 14 days. This may be due to a delay in review on our side or awaiting a response from you; either is fine, and we appreciate your patience. It will be closed in 14 days if no further activity occurs. Pushing a new commit or leaving a comment will remove the stale label and keep the PR open. |
|
Env var carriers are now RC: |
Fixes #3285
Related to open-telemetry/opentelemetry-specification#5142
Changes
This adds experimental support for the OpenTelemetry environment-variable carrier specification so Rust applications can propagate context across parent/child process boundaries without relying on network transports.
Follows https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/context/env-carriers.md
EnvVarExtractorandEnvVarInjectorunderopentelemetry::propagation, gated behindotel_unstableGet,Set, andKeysEnvVarExtractor::from_fieldsas the recommended extraction path, reading only the normalized environment variables advertised by the active propagatorEnvVarExtractor::from_os_entriesas the full-scan fallback for propagators that needkeys()over the whole carrierEnvVarInjectorfocused on injected propagation variables and make it consumable bystd::process::Command::envsexamples/env-var-propagationshowing parent/child process propagation withTraceContextPropagatorDesign notes
EnvVarExtractorstores environment values internally becauseExtractor::getreturns borrowed&strvalues, whilestd::env::var_osreturns owned values. Storing the selected values gives the carrier stable storage to borrow from and giveskeys()a consistent view.Most propagators only need direct
get()calls for known fields, sofrom_fields(propagator.fields())avoids enumerating the entire process environment in the common case.from_os_entries(std::env::vars_os())remains available for propagators that scan carrier keys, such as legacy prefix-based formats.EnvVarInjectordoes not mutate the parent process environment. Callers inject into a fresh carrier and pass it toCommand::envs;Commandcontinues to inherit the rest of the parent environment by default.Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial, user-facing changes