Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/OpenTelemetry.Api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ Notes](../../RELEASENOTES.md).
sensitive.
([#6931](https://github.com/open-telemetry/opentelemetry-dotnet/pull/6931))

* Fixed `BaggagePropagator` to trim optional whitespace (OWS) around `=`
separators when parsing the `baggage` header, as required by the
[W3C Baggage specification](https://www.w3.org/TR/baggage/).
([#7009](https://github.com/open-telemetry/opentelemetry-dotnet/pull/7009))

* Fixed `BaggagePropagator` to strip baggage properties (e.g. `;metadata`)
from values when parsing the `baggage` header.
([#7009](https://github.com/open-telemetry/opentelemetry-dotnet/pull/7009))
Comment thread
martincostello marked this conversation as resolved.
Outdated

## 1.15.0

Released 2026-Jan-21
Expand Down
17 changes: 15 additions & 2 deletions src/OpenTelemetry.Api/Context/Propagation/BaggagePropagator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,21 @@ internal static bool TryExtractBaggage(
continue;
}

var key = WebUtility.UrlDecode(parts[0]);
var value = WebUtility.UrlDecode(parts[1]);
var rawValue = parts[1];

// semicolon is not a valid baggage-octet
#if NET
var semicolonIndex = rawValue.IndexOf(';', StringComparison.Ordinal);
#else
var semicolonIndex = rawValue.IndexOf(';');
#endif
if (semicolonIndex >= 0)
Comment thread
martincostello marked this conversation as resolved.
{
rawValue = rawValue.Substring(0, semicolonIndex);
}

var key = WebUtility.UrlDecode(parts[0].Trim());
var value = WebUtility.UrlDecode(rawValue.Trim());

if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(value))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public void ValidateEmptyValueSkipped()
Assert.Empty(propagationContext.Baggage.GetBaggage());
}

[Fact(Skip = "Fails due to spec mismatch, tracked in https://github.com/open-telemetry/opentelemetry-dotnet/issues/5210")]
[Fact]
public void ValidateOWSOnExtraction()
{
var carrier = new Dictionary<string, string>
Expand All @@ -259,7 +259,7 @@ public void ValidateOWSOnExtraction()
Assert.Equal("SomeValue2", baggage[1].Value);
}

[Fact(Skip = "Fails due to spec mismatch, tracked in https://github.com/open-telemetry/opentelemetry-dotnet/issues/5210")]
[Fact]
public void ValidateSemicolonMetadataIgnoredOnExtraction()
{
var carrier = new Dictionary<string, string>
Expand All @@ -276,6 +276,39 @@ public void ValidateSemicolonMetadataIgnoredOnExtraction()
Assert.Equal("SomeValue", baggage.Value);
}

[Fact]
public void ValidateOptionalWhiteSpaceExtractionDoesNotCorruptOnReinjection()
{
// Simulates a header emitted by .NET 10's W3C propagator
var carrier = new Dictionary<string, string>
{
{ BaggagePropagator.BaggageHeaderName, "correlationId = 12345, userId = user-abc" },
};

var extractedContext = this.baggage.Extract(default, carrier, Getter);

var outboundCarrier = new Dictionary<string, string>();
this.baggage.Inject(extractedContext, outboundCarrier, Setter);

Assert.Equal("correlationId=12345,userId=user-abc", outboundCarrier[BaggagePropagator.BaggageHeaderName]);
}

[Fact]
public void ValidateOptionalWhiteSpaceBeforeSemicolonIgnored()
{
var carrier = new Dictionary<string, string>
{
{ BaggagePropagator.BaggageHeaderName, "SomeKey=SomeValue ; propertyKey=propertyValue" },
Comment thread
martincostello marked this conversation as resolved.
};

var propagationContext = this.baggage.Extract(default, carrier, Getter);

var baggage = Assert.Single(propagationContext.Baggage.GetBaggage());

Assert.Equal("SomeKey", baggage.Key);
Assert.Equal("SomeValue", baggage.Value);
}

[Fact]
public void ValidatePercentEncoding()
{
Expand Down
Loading