Skip to content

[Api] Fix empty tracestate extraction#7407

Merged
Kielek merged 2 commits into
open-telemetry:mainfrom
Kielek:tracestate-fix
Jun 12, 2026
Merged

[Api] Fix empty tracestate extraction#7407
Kielek merged 2 commits into
open-telemetry:mainfrom
Kielek:tracestate-fix

Conversation

@Kielek

@Kielek Kielek commented Jun 12, 2026

Copy link
Copy Markdown
Member

Broader fix of open-telemetry/opentelemetry-dotnet-contrib#4503

Changes

Normalize valid empty tracestate header values to null when extracting W3C trace context with TraceContextPropagator.

The W3C Trace Context specification requires vendors to accept empty tracestate headers, while recommending that senders avoid producing them:
https://www.w3.org/TR/trace-context/#tracestate-header-field-values

Before this change, a present-but-empty tracestate header extracted as ActivityContext.TraceState == "", while an absent tracestate header extracted as null. Both represent no trace state, but the observable difference can cause downstream code comparing OpenTelemetry-extracted context with runtime-created Activity context to treat them as different parents.

This change keeps malformed non-empty tracestate behavior unchanged, but normalizes valid empty or whitespace-only tracestate values to null.

Tests

Added coverage for present empty/whitespace tracestate values:

  • tracestate: ""
  • tracestate: " "
  • tracestate: " , "

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • [ ] Changes in public API reviewed (if applicable)

@github-actions github-actions Bot added pkg:OpenTelemetry.Api Issues related to OpenTelemetry.Api NuGet package pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package labels Jun 12, 2026
@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.71%. Comparing base (b01e1d6) to head (481e87a).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7407      +/-   ##
==========================================
- Coverage   89.72%   89.71%   -0.01%     
==========================================
  Files         276      276              
  Lines       14576    14576              
==========================================
- Hits        13078    13077       -1     
- Misses       1498     1499       +1     
Flag Coverage Δ
unittests-Project-Experimental 89.49% <100.00%> (-0.15%) ⬇️
unittests-Project-Stable 89.46% <100.00%> (-0.20%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
....Api/Context/Propagation/TraceContextPropagator.cs 90.98% <100.00%> (+0.29%) ⬆️

... and 3 files with indirect coverage changes

@Kielek
Kielek added this pull request to the merge queue Jun 12, 2026
Merged via the queue into open-telemetry:main with commit ddaa257 Jun 12, 2026
73 checks passed
@Kielek
Kielek deleted the tracestate-fix branch June 12, 2026 19:10
@martincostello martincostello added this to the v1.17.0 milestone Jul 3, 2026
This was referenced Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg:OpenTelemetry.Api Issues related to OpenTelemetry.Api NuGet package pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants