[API] Normalize empty environment variable names#7424
Conversation
Normalize an empty value to `_`. See open-telemetry/opentelemetry-specification#5163.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7424 +/- ##
==========================================
+ Coverage 89.84% 90.26% +0.42%
==========================================
Files 276 279 +3
Lines 14611 15584 +973
==========================================
+ Hits 13127 14067 +940
- Misses 1484 1517 +33
Flags with carried forward coverage won't be shown. Click here to find out more.
|
…try#5163) Issue discovered by @MrAlias in open-telemetry/opentelemetry-go-contrib#9112 (comment) Also see open-telemetry#5163 (comment) Prototypes: - open-telemetry/opentelemetry-go-contrib@0fedf62 - open-telemetry/opentelemetry-dotnet#7424 - open-telemetry/opentelemetry-swift-core#86 - open-telemetry/opentelemetry-python#5328 - open-telemetry/opentelemetry-js#6827 - open-telemetry/opentelemetry-java#8481 For values to be fully portable across POSIX-compliant systems and shell utilities, the standard dictates that environment variable names must consist solely of uppercase letters, digits, and underscores (_), and must not begin with a digit. While some individual implementations might tolerate unusual characters, an empty string lacks any valid characters entirely and cannot act as a recognizable identifier. I verified that on Ubuntu it is not possible to set a env var with an empty name. --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: xiang17 <xili9@microsoft.com>
There was a problem hiding this comment.
Pull request overview
Updates the experimental EnvironmentVariableCarrier key normalization logic in OpenTelemetry.Api to align with the updated environment variable carrier specification by ensuring empty propagation keys normalize to a valid environment variable name.
Changes:
- Normalize an empty key (
"") to a single underscore ("_") inEnvironmentVariableCarrier.NormalizeKey. - Update normalization documentation to explicitly describe the empty-key behavior.
- Extend unit tests to cover the empty-key normalization case.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| test/OpenTelemetry.Api.Tests/Context/Propagation/EnvironmentVariableCarrierTests.cs | Adds coverage asserting NormalizeKey("") returns "_". |
| src/OpenTelemetry.Api/Context/Propagation/EnvironmentVariableCarrier.cs | Implements empty-key normalization and updates remarks; ensures empty keys are not treated as already-normalized. |
| src/OpenTelemetry.Api/CHANGELOG.md | Documents the experimental behavior change for empty key normalization. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: xiang17 <xili9@microsoft.com>
open-telemetry/opentelemetry-specification#5163.
Changes
Normalize an empty value to
_./cc @pellared
Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changesChanges in public API reviewed (if applicable)