Skip to content

W3CPropagator stops parsing baggage after malformed member instead of continuing with later valid members #129286

Closed

Description

@Kielek

Description

System.Diagnostics.W3CPropagator stops parsing the baggage header when it encounters a malformed key=value shape. This drops later valid baggage members from the same header.

The current implementation in TryExtractBaggage breaks out of parsing when the current entry has no key/value separator or has the separator at the beginning/end:

int keyValueSeparator = currentEntry.IndexOf(Equal);
if (keyValueSeparator <= 0 || keyValueSeparator >= currentEntry.Length - 1)
{
    break; // invalid format
}

Source: https://github.com/dotnet/runtime/blob/f59cad6eaf5bbe1c3da6aea07e998f686c0ef0bd/src/libraries/System.Diagnostics.DiagnosticSource/src/System/Diagnostics/W3CPropagator.cs

The W3C baggage specification defines a baggage-string as a list of list-members:

baggage-string = list-member 0*179( OWS "," OWS list-member )
list-member    = key OWS "=" OWS value *( OWS ";" OWS property )

Source: https://www.w3.org/TR/baggage/#definition

Pinned w3c/baggage source snapshot: https://github.com/w3c/baggage/blob/2187a480c633d501b2f1ef42ced9f6837461d6ec/baggage/HTTP_HEADER_FORMAT.md

For malformed baggage strings, the W3C baggage editor draft does not prescribe a single parsing strategy. It allows implementations to remove an offending list-member before propagating the rest, or to choose another invalid-input policy. Continuing after a malformed member therefore appears to be a valid and more interoperable policy.

This came up while reviewing baggage behavior across four OpenTelemetry implementations. The OpenTelemetry implementations generally skip invalid members and continue parsing later valid members:

Reproduction Steps

Extract baggage from a carrier containing one malformed member followed by a valid member:

baggage: valid1=value1,bad,valid2=value2

Minimal code shape:

using System.Diagnostics;

var propagator = DistributedContextPropagator.CreateDefaultPropagator();
var carrier = new Dictionary<string, string>
{
    ["baggage"] = "valid1=value1,bad,valid2=value2",
};

var baggage = propagator.ExtractBaggage(
    carrier,
    static (object? carrier, string fieldName, out string? fieldValue, out IEnumerable<string>? fieldValues) =>
    {
        var headers = (Dictionary<string, string>)carrier!;
        headers.TryGetValue(fieldName, out fieldValue);
        fieldValues = null;
    });

// Observe extracted keys.

Expected behavior

The malformed member bad should be ignored, and later valid members should still be extracted.

Expected extracted baggage:

valid1=value1
valid2=value2

This matches the common behavior seen in OpenTelemetry Go, Java, Rust, and .NET, and is compatible with the W3C baggage specification's permissive invalid-input handling.

Actual behavior

Parsing stops at bad, so valid2=value2 is not extracted.

Actual extracted baggage:

valid1=value1

If the malformed member is first, for example:

baggage: bad,valid=value

then no later valid baggage is extracted.

Regression?

No

Known Workarounds

Use a custom propagator or sanitize incoming baggage headers before passing them to DistributedContextPropagator, removing malformed list-members while keeping later valid members.

Configuration

Observed by reviewing the pinned dotnet/runtime implementation snapshot linked above.

Other information

It will be great to sync default behavior with other OTel implementations, especially .NET.
@cijothomas suggested to do this in open-telemetry/opentelemetry-dotnet#7374

Activity

  1. added
    untriaged
    on Jun 11, 2026
  2. dotnet-policy-service commented on Jun 11, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-meta
    See info in area-owners.md if you want to be subscribed.

  3. added and removed
    untriaged
    on Jun 11, 2026
  4. added this to the 11.0.0 milestone on Jun 11, 2026
  5. dotnet-policy-service commented on Jun 11, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @steveisok, @dotnet/area-system-diagnostics-tracing
    See info in area-owners.md if you want to be subscribed.

  6. locked and limited conversation to collaborators on Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions