Skip to content

feat: add prototype for EnvVarsCarrier (env var propagation)#3521

Draft
jsurany wants to merge 16 commits into
open-telemetry:mainfrom
jsurany:env-vars-carrier
Draft

feat: add prototype for EnvVarsCarrier (env var propagation)#3521
jsurany wants to merge 16 commits into
open-telemetry:mainfrom
jsurany:env-vars-carrier

Conversation

@jsurany

@jsurany jsurany commented May 21, 2026

Copy link
Copy Markdown

Fixes #3285
Design discussion issue (if applicable) N/A?

Changes

Please provide a brief description of the changes here.

  • Added EnvVarsCarrier type that implements Extractor and Injector traits, with the normalization described in the spec.
  • EnvVarsCarrier pulls the environment in from_env, with normalization
  • The Extractor trait seemed straightforward, but Injector felt up to interpretation. In this design, the injection only modifies the internal map on the EnvVarsCarrier type (keys are always normalized).
  • added environment variable to .cargo/config.toml for testing the carrier's initialization. This seemed better than adding unsafe code to the tests.

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)

Would like some feedback on if this is the correct way to have implemented this feature, and advice on managing the changelog.

@jsurany jsurany requested a review from a team as a code owner May 21, 2026 21:53
@linux-foundation-easycla

linux-foundation-easycla Bot commented May 21, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@jsurany jsurany changed the title add prototype for EnvVarsCarrier (env var propagation) feat: add prototype for EnvVarsCarrier (env var propagation) May 21, 2026
@codecov

codecov Bot commented May 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.0%. Comparing base (c14b570) to head (714680e).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@          Coverage Diff           @@
##            main   #3521    +/-   ##
======================================
  Coverage   82.9%   83.0%            
======================================
  Files        130     131     +1     
  Lines      27484   27586   +102     
======================================
+ Hits       22796   22902   +106     
+ Misses      4688    4684     -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.

Comment thread opentelemetry-sdk/src/propagation/env_vars_carrier.rs Outdated
Comment thread opentelemetry-sdk/src/propagation/env_vars_carrier.rs Outdated
Comment thread opentelemetry/src/propagation/env_vars_carrier.rs

@TommyCpp TommyCpp 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.

Most implementation leave this in API and the carrier is SDK agnostic, so we should move it to api create(opentelemetry/src/propagation)

@jsurany

jsurany commented May 26, 2026

Copy link
Copy Markdown
Author

Most implementation leave this in API and the carrier is SDK agnostic, so we should move it to api create(opentelemetry/src/propagation)

moved the change.

Would it be OK if I rebase? I didn't update my git config for this PR and as a result the EasyCLA thinks that the early commits are coming from a different account (one that I don't use anymore).

@jsurany jsurany requested a review from TommyCpp May 26, 2026 15:53
Comment thread opentelemetry/src/propagation/env_vars_carrier.rs Outdated
Comment thread opentelemetry/src/propagation/env_vars_carrier.rs
Comment thread opentelemetry/src/propagation/env_vars_carrier.rs
@pellared

pellared commented Jun 2, 2026

Copy link
Copy Markdown
Member

EasyCLA is failing.

@jsurany jsurany requested a review from pellared June 2, 2026 19:28
jsurany and others added 12 commits June 2, 2026 17:19
* fix(sdk): enforce W3C Baggage limits in BaggagePropagator extract path

BaggagePropagator::extract_with_context parsed each list-member of an
inbound `baggage` header in full -- splitting on `;`, decoding the
percent-encoded key/value, allocating Vec<String> for property segments,
and constructing a KeyValueMetadata -- before passing the result to
Baggage::insert_with_metadata. The storage-side limit
(MAX_KEY_VALUE_PAIRS=64, MAX_LEN_OF_ALL_PAIRS=8192) silently dropped
entries once full, but per-entry allocation work continued for every
attacker-supplied member.

This change applies the W3C Baggage limits at the propagator boundary:

- Reject the header when its byte length exceeds MAX_BAGGAGE_LENGTH
  (8192). The header is logged at warn level and an empty Context is
  returned.
- Cap the outer comma-split iterator with .take(MAX_BAGGAGE_ITEMS) so
  parsing stops after 64 list-members regardless of header content.

The injection path is unchanged; the existing Baggage storage type
already enforces both limits when entries are added.

Two unit tests cover the new behavior:

- extract_drops_header_exceeding_max_length verifies that an oversized
  header produces an empty Baggage.
- extract_caps_entry_count_at_max_baggage_items verifies that more than
  64 syntactically valid entries are truncated to 64.

References:
- W3C Baggage limits: https://www.w3.org/TR/baggage/#limits

Signed-off-by: tonghuaroot <tonghuaroot@gmail.com>

* Clarify CHANGELOG: 8192-byte over-limit drops, 64-entry over-limit truncates

Address reviewer feedback that 'dropped at the propagator boundary' was
ambiguous: the over-length header path drops the whole header, while the
over-count path truncates to the first 64 list members. Split the wording
into two clauses so the behavior is unambiguous.

Signed-off-by: tonghuaroot <tonghuaroot@gmail.com>

---------

Signed-off-by: tonghuaroot <tonghuaroot@gmail.com>
Co-authored-by: Scott Gerring <scottgerring@users.noreply.github.com>
@jsurany jsurany force-pushed the env-vars-carrier branch from 317829f to 983f10c Compare June 2, 2026 21:20
@jsurany

jsurany commented Jun 2, 2026

Copy link
Copy Markdown
Author

Sorry, I had to rebase in order to change the contact info for past commits for EasyCLA to pass

@jsurany

jsurany commented Jun 4, 2026

Copy link
Copy Markdown
Author

@pellared @TommyCpp I think I've fixed everything. I don't think I'm responsible for the failing integration test, looks like it's from metrics. Let me know what you'd like me to do.

@pellared

pellared commented Jun 9, 2026

Copy link
Copy Markdown
Member

It might make sense to keep this as a draft until the following issue is resolved: open-telemetry/opentelemetry-specification#5143. PTAL when you have a chance, and feel free to share your thoughts there. Waiting could help us avoid extra PRs and save reviewers some time.

@jsurany

jsurany commented Jun 9, 2026

Copy link
Copy Markdown
Author

Converted to draft per above. Waiting for open-telemetry/opentelemetry-specification#5143

@pellared

Copy link
Copy Markdown
Member

Converted to draft per above. Waiting for open-telemetry/opentelemetry-specification#5143

open-telemetry/opentelemetry-specification#5144 is going to be merged soon. Feel free to adopt necessary changes in this PR.

@jsurany

jsurany commented Jun 11, 2026

Copy link
Copy Markdown
Author

open-telemetry/opentelemetry-specification#5144 is going to be merged soon. Feel free to adopt necessary changes in this PR.

@pellared the Set behavior is a bit weird now, isn't it?

  • when built from the environment, we only include already-normalized strings into the carrier
  • when Getting a value, we return no value if the request key is not normalized
  • when Seting a value, we normalize the key before writing the value.

It feels like the overall design would be more consistent if Set only works if the key is already normalized. Otherwise the user can set a value with a key, then try to use that same key to fetch the value later, only for the Get to reject it on the grounds that it's not normalized.

If we make it so Set fails for non-normalized keys, then the Keys API doesn't need to filter out non-normalized keys. It just reports on all keys, with the invariant that all keys in the map are already normalized.

EDIT - correction is that Getting a value still applies normalization, the only is_normalized filter application is when we are building the carrier from the existing environment. All other interactions use normalize on the key.

@kamphaus

Copy link
Copy Markdown

@jsurany Get must normalize its argument key before using the normalized key name for lookups.
That way using the same non-normalized key for both Get and Set operations works.

Comment thread opentelemetry/src/propagation/env_vars_carrier.rs Outdated
@jsurany

jsurany commented Jun 15, 2026

Copy link
Copy Markdown
Author

Ok I think I understand now.

@pellared

Copy link
Copy Markdown
Member

Is this a draft on purpose?

@cijothomas cijothomas requested review from Copilot and removed request for pellared June 17, 2026 07:40

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 an environment-variable-backed carrier to the opentelemetry crate’s propagation module to support the OpenTelemetry environment variable context propagation (“env-carriers”) mechanism discussed in #3285.

Changes:

  • Introduces EnvVarsCarrier implementing Extractor and Injector, including key normalization logic and from_env/empty constructors.
  • Re-exports EnvVarsCarrier from opentelemetry::propagation.
  • Adds Cargo [env] config entries used by unit tests that validate from_env() behavior.

Reviewed changes

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

File Description
opentelemetry/src/propagation/mod.rs Wires the new carrier module into the propagation API surface via re-export.
opentelemetry/src/propagation/env_vars_carrier.rs Implements the env-var carrier, normalization helpers, and unit tests.
.cargo/config.toml Defines test environment variables used by EnvVarsCarrier::from_env() tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +5 to +9
/// Propagates name-value pairs via environment variables.
///
/// This propagator provides a mechanism for propagating context information
/// across process boundaries using environment variables, usually for when
/// network protocols are not applicable.
Comment on lines +51 to +53
/// Create a new `EnvVarsCarrier` object, built from environment variables.
/// Environment variables are fetched and normalized at construction time.
pub fn from_env() -> Self {
Comment on lines 28 to 30
pub use composite::TextMapCompositePropagator;
pub use env_vars_carrier::EnvVarsCarrier;
pub use text_map_propagator::TextMapPropagator;
@jsurany

jsurany commented Jun 18, 2026

Copy link
Copy Markdown
Author

Hey, sorry the effort under which I made this PR has wrapped up and I now need to wait for a different set of approvals to go through to continue work on this PR. It could take up to 6 weeks. I'll finish up the remaining comments when I have approval again.

@pellared

Copy link
Copy Markdown
Member

This is only a prototype and at this point of time we rather need an actual experimental implementation. I suggest closing.

@kamphaus

Copy link
Copy Markdown

Superseded by #3574

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

9 participants