Skip to content

feat(api): add experimental env var propagators#3574

Open
pellared wants to merge 14 commits into
open-telemetry:mainfrom
pellared:pellared-env-var-propagation
Open

feat(api): add experimental env var propagators#3574
pellared wants to merge 14 commits into
open-telemetry:mainfrom
pellared:pellared-env-var-propagation

Conversation

@pellared

@pellared pellared commented Jun 29, 2026

Copy link
Copy Markdown
Member

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

  • Add EnvVarExtractor and EnvVarInjector under opentelemetry::propagation, gated behind otel_unstable
  • Normalize environment variable names according to the spec for Get, Set, and Keys
  • Keep the carrier format-agnostic and value-opaque; propagators remain responsible for parsing and validation
  • Add EnvVarExtractor::from_fields as the recommended extraction path, reading only the normalized environment variables advertised by the active propagator
  • Keep EnvVarExtractor::from_os_entries as the full-scan fallback for propagators that need keys() over the whole carrier
  • Keep EnvVarInjector focused on injected propagation variables and make it consumable by std::process::Command::envs
  • Document the API in crate docs and README, and add examples/env-var-propagation showing parent/child process propagation with TraceContextPropagator

Design notes

EnvVarExtractor stores environment values internally because Extractor::get returns borrowed &str values, while std::env::var_os returns owned values. Storing the selected values gives the carrier stable storage to borrow from and gives keys() a consistent view.

Most propagators only need direct get() calls for known fields, so from_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.

EnvVarInjector does not mutate the parent process environment. Callers inject into a fresh carrier and pass it to Command::envs; Command continues to inherit the rest of the parent environment by default.

Merge requirement checklist

  • CONTRIBUTING guidelines followed
  • Unit tests added/updated (if applicable)
  • Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • Changes in public API reviewed (if applicable)

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

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.67257% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.3%. Comparing base (54c3bb2) to head (8abb673).

Files with missing lines Patch % Lines
opentelemetry/src/propagation/env.rs 98.6% 3 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

pellared and others added 2 commits June 29, 2026 19:45
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>
@pellared
pellared marked this pull request as ready for review June 29, 2026 18:03
@pellared
pellared requested a review from a team as a code owner June 29, 2026 18:03
Copilot AI review requested due to automatic review settings June 29, 2026 18:03
@pellared
pellared marked this pull request as draft June 29, 2026 18:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 EnvVarExtractor and EnvVarInjector carriers under opentelemetry::propagation gated by otel_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.

Comment thread opentelemetry/src/propagation/env.rs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Comment thread opentelemetry/src/propagation/env.rs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Comment thread opentelemetry/src/propagation/env.rs
Comment thread examples/env-var-propagation/src/main.rs

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

@pellared
pellared marked this pull request as ready for review June 29, 2026 20:29
@pellared

Copy link
Copy Markdown
Member Author

@github-actions

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the Stale label Jul 14, 2026
@kamphaus

Copy link
Copy Markdown

Env var carriers are now RC:

@github-actions github-actions Bot removed the Stale label Jul 15, 2026
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.

[Feature]: Support the environment variable propagation spec in Rust

3 participants