[API] Support environment variable context propagation#7174
Merged
Conversation
Add support for using environment variables as context propagation carriers. Contributes to open-telemetry#6776.
Add runnable example for using environment variables as context propagation carriers.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7174 +/- ##
==========================================
+ Coverage 89.69% 89.75% +0.05%
==========================================
Files 272 273 +1
Lines 13366 13514 +148
==========================================
+ Hits 11989 12129 +140
- Misses 1377 1385 +8
Flags with carried forward coverage won't be shown. Click here to find out more.
|
4 tasks
Fix the examples link.
Add test for additional coverage gaps.
Avoid duplication and use built-in APIs for .NET 8+.
Fix-up usage of `EnvironmentVariableScope`.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds first-class support for propagating OpenTelemetry context/baggage via environment variables, aligning with the OpenTelemetry environment variable carrier spec.
Changes:
- Introduces
EnvironmentVariableCarrierAPI for capture/get/set + key normalization inOpenTelemetry.Api. - Adds unit tests, fuzz tests, and benchmarks validating normalization and round-trip behavior.
- Adds documentation and a runnable example demonstrating parent/child process propagation via environment variables.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/OpenTelemetry.Api/Context/Propagation/EnvironmentVariableCarrier.cs |
New carrier implementation for capturing and using env vars as propagation carriers. |
src/OpenTelemetry.Api/.publicApi/Stable/PublicAPI.Unshipped.txt |
Declares new stable public APIs for EnvironmentVariableCarrier. |
src/OpenTelemetry.Api/README.md |
Documents environment variable propagation usage and links to the spec. |
test/OpenTelemetry.Api.Tests/OpenTelemetry.Api.Tests.csproj |
Links EnvironmentVariableScope helper into API tests. |
test/OpenTelemetry.Api.Tests/Context/Propagation/EnvironmentVariableCarrierTests.cs |
New unit tests covering normalization/capture/get/set and propagator round-trips. |
test/OpenTelemetry.Api.FuzzTests/Context/Propagation/Generators.cs |
Adds generators for env-var keys and opaque values. |
test/OpenTelemetry.Api.FuzzTests/Context/Propagation/EnvironmentVariableCarrierFuzzTests.cs |
New fuzz tests for normalization validity and round-trip invariants. |
test/Benchmarks/Context/Propagation/EnvironmentVariableCarrierBenchmarks.cs |
Adds benchmarks for capture/extract/inject. |
examples/EnvironmentVariables/Program.cs |
New end-to-end example demonstrating env-var propagation across processes. |
examples/EnvironmentVariables/Examples.EnvironmentVariables.csproj |
Adds example project for the new scenario. |
OpenTelemetry.slnx |
Includes the new example project in the solution. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Update XML documentation. - Remove redundant code.
pellared
approved these changes
Apr 30, 2026
pellared
reviewed
Apr 30, 2026
Prevent any possibility of deadlock reading stdout and stderr.
- Update CHANGELOG. - Update README. - Move prefix length to local. - Add `char.IsAsciiLetterUpper()` polyfill. - Use new char polyfills,
pellared
approved these changes
Apr 30, 2026
Make `EnvironmentVariableCarrier` part of the experimental API surface.
Only capture the process' environment variables once.
- Add link to feedback/stabilisation issue. - Fix references to renamed API.
Make line shorter.
Add OTEL1005.md.
- Grant IVT to Benchmarks. - Fix broken link.
Add IVT for OpenTelemetry.Api.FuzzTests.
Add IVT for example project.
4 tasks
Kielek
reviewed
May 4, 2026
Remove duplication.
Kielek
approved these changes
May 5, 2026
Merged
via the queue into
open-telemetry:main
with commit May 5, 2026
bcf3940
183 of 186 checks passed
pull Bot
pushed a commit
to CodeWeaver13/opentelemetry-specification
that referenced
this pull request
May 7, 2026
pellared
added a commit
to cijothomas/opentelemetry-specification
that referenced
this pull request
Jun 2, 2026
…y#5102) Towards open-telemetry#5040 ## Changes Clarifies the environment variable propagation carrier key normalization requirements: - `Set` writes values using normalized key names. - `Get` normalizes both the requested propagator key and carrier keys before matching. - `Keys` returns normalized key names. ## Motivation The existing text defined how key names are normalized, but it did not explicitly say where that normalization applies. This PR clarifies that normalization is part of the carrier behavior for writing, reading, and listing keys. This follows the robustness principle: carriers write the normalized representation, while getters can still accept a non-normalized environment variable key if it normalizes to the requested propagation key. For example, a non-normalized `traceparent` environment variable can still be used by the propagation getter when matching `TRACEPARENT`. This retrospects open-telemetry#4944 (comment) now that implementations are in place. ## Implementation references - Go: open-telemetry/opentelemetry-go-contrib#8761 - .NET: open-telemetry/opentelemetry-dotnet#7174 - Java: open-telemetry/opentelemetry-java#8233 - Python: open-telemetry/opentelemetry-python#5119 - Swift: open-telemetry/opentelemetry-swift-core#47 Related Java discussion: open-telemetry/opentelemetry-java#8233 (comment)
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.
Contributes to #6776
Changes
Add support for using environment variables as context propagation carriers.
I've done this as stable (rather than experimental) for now until there's some reviews of the overall shape and whether it should be experimental, or whether it's just the chicken-and-egg case of it only being experimental because there aren't enough implementations yet.
I'll do the additional fix-ups to make this experimental if needed later, as well as update the CHANGELOG.
Example output from the example project:
Benchmarks
Expand to view
Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changes