[CONTEXT] Fix env carrier key normalization to be spec compliant#4141
Open
pranitaurlam wants to merge 1 commit into
Open
[CONTEXT] Fix env carrier key normalization to be spec compliant#4141pranitaurlam wants to merge 1 commit into
pranitaurlam wants to merge 1 commit into
Conversation
- Use ASCII-only normalization (was locale-dependent via std::isalnum) - Prefix key with '_' when it starts with a digit - Cache by normalized key so equivalent forms hit the same entry Fixes open-telemetry#4061
Author
|
Hi @marcalff @lalitb @ThomsonTan |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4141 +/- ##
==========================================
+ Coverage 82.01% 82.03% +0.02%
==========================================
Files 385 385
Lines 16093 16098 +5
==========================================
+ Hits 13197 13204 +7
+ Misses 2896 2894 -2
🚀 New features to boost your workflow:
|
lalitb
reviewed
Jun 8, 2026
| } | ||
|
|
||
| // Read from environment | ||
| const char *value = std::getenv(env_name.c_str()); |
Member
There was a problem hiding this comment.
This only looks up the normalized requested name. The spec says Get should also normalize key names already present in the carrier before matching, so this would not match an existing env key like x-b3-traceid. Should we snapshot/list the environment and match normalized names there?
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.
Fixes #4061
Changes
std::isalnum(locale-dependent) with explicit ASCII range checks (a-z,A-Z,0-9)_when normalized key starts with a digit, per the specGet()now caches by the normalized key, soGet("x-b3-traceid")andGet("X_B3_TRACEID")hit the same cache entry and map to the same env varX_B3_TRACEID<algorithm>and<cctype>sincestd::transform/std::isalnumare no longer usedSpec reference
https://opentelemetry.io/docs/specs/otel/context/env-carriers/#key-name-normalization
CC @marcalff @lalitb @ThomsonTan