Skip to content

Conversation

@marco-saia-datadog
Copy link
Member

@marco-saia-datadog marco-saia-datadog commented Oct 15, 2025

What does this PR do?

When a RUM Session ID is available, we set it in the Baggage header of intercepted network requests when using trackResources=true.

We don't account for pre-existing values in the Baggage header, so we end up overwriting it.

This PR adds support for user-defined Baggage headers by using comma-separated list strings, following the W3C Baggage specification.

Requirements for W3 compliance

NOTE: All invalid keys or values are dropped with a warning

  • Entry Format
    Each entry must contain at least one = separating key and value.

  • Key Validation
    Keys must follow RFC 7230 §3.2.6 token grammar.
    Allowed characters: !#$%&'*+-.^_|~0-9A-Za-z

  • Value Encoding
    Values are UTF-8 encoded.

    Characters outside the allowed baggage octet range (!, #–+, -–:, <–[, ]–~) are percent-encoded.

    Spaces, commas, semicolons, quotes, backslashes, and non-ASCII characters are encoded.

    Example:

     "Amélie"  => Am%C3%A9lie
     "us east" => us%20east
    
  • Properties (Metadata)

    Entries may include properties separated by semi-colons:

     key=value;prop1=value1;prop2
    

    Property keys must also follow RFC 7230 token grammar.

    Property values are percent-encoded using the same rules as the main value.

  • Whitespace Handling

    Leading and trailing whitespace around keys, values, and properties is trimmed.

    Internal whitespace (e.g. "foo = bar ; p1 = one") is normalized.

  • Limits (per W3C Spec §3.3.2)

    The resulting header must contain:

    • ≤ 64 list-members, otherwise a warning is logged.

    • ≤ 8192 bytes total size, otherwise a warning is logged.

    Entries beyond these limits may be ignored by consumers. We print a warning on our side, without dropping the entry.

  • Order Preservation

    Entries are formatted in the same order they appear in the original Set.

  • Logging and Error Handling

    Invalid entries and properties are not propagated.

    Each failure is logged via InternalLog with SdkVerbosity.WARN.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)
  • If this PR is auto-generated, please make sure also to manually update the code related to the change

@marco-saia-datadog marco-saia-datadog requested a review from a team as a code owner October 15, 2025 11:16
@marco-saia-datadog marco-saia-datadog marked this pull request as draft October 15, 2025 12:35
sbarrio
sbarrio previously approved these changes Oct 22, 2025
@marco-saia-datadog marco-saia-datadog marked this pull request as ready for review October 28, 2025 10:36
}
}
return result;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The encoding is custom since baggage headers support characters that would otherwise be escaped by functions like encodeURIComponent.

The logic is:

  • Converts the character to an iterable utf8 buffer
  • Converts each byte value to a hexadecimal string using toString(16)
  • Pads it to always have two digits with padStart(2, '0')
  • Uppercases it for canonical form.
  • Prefixes it with %.

For example, if you encode "é":

Buffer.from('é', 'utf8') -> [195, 169] (0xC3, 0xA9)

result -> %C3%A9

@marco-saia-datadog marco-saia-datadog force-pushed the marcosaia/RUM-12188/preserve-user-baggage-header branch from d0408fe to 6007a26 Compare October 28, 2025 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants