Skip to content

Conversation

tobias-tengler
Copy link

@tobias-tengler tobias-tengler commented Sep 23, 2025

Fixes #6510

Changes

Updates OtlpExporterOptionsExtensions.GetHeaders to no longer throw for commas inside of header values.
Previously a valid header value like VL-Stream-Fields=service.name,service.environment would've thrown, since the comma would've been incorrectly interpreted as a delimiter to another header pair - now it's properly parsed.

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)

@tobias-tengler tobias-tengler requested a review from a team as a code owner September 23, 2025 13:17
Copy link

linux-foundation-easycla bot commented Sep 23, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@github-actions github-actions bot added the pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package label Sep 23, 2025
int commaIndex = headersSpan.IndexOf(',');
ReadOnlySpan<char> pair;
if (commaIndex == -1)
var key = headersSpan.Slice(0, nextEqualIndex).Trim().ToString();
Copy link
Contributor

@matt-hensley matt-hensley Sep 23, 2025

Choose a reason for hiding this comment

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

likely able to avoid the additional string allocations and only use spans for the new parsing logic

Copy link
Author

Choose a reason for hiding this comment

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

How do you mean? I'm already using Span for the parsing, but there's no way around allocating a string for the key and value at some point.

Copy link
Contributor

Choose a reason for hiding this comment

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

initial read looked like there were multiple ToString calls. looks reasonable to push those calls as late as possible

Copy link
Author

Choose a reason for hiding this comment

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

Do you have a concrete idea of how to do so? I'm not even sure if performance improvements in this part of the code matter that much. This isn't even on any hot path right?

@tobias-tengler tobias-tengler marked this pull request as draft September 23, 2025 14:12
@tobias-tengler tobias-tengler marked this pull request as ready for review September 23, 2025 14:42
@tebeco
Copy link

tebeco commented Sep 26, 2025

I feel like the headers shouldn't be a string at all TBH.
the day we'll need to send a Base64 value that's being padded with = what will happen ?

If we're sending headerS (multiples), it sounds like this should be a List<KeyValuePair<string, string>> or something similar @matt-hensley .
Just like Resource/Attribute

I'm not mentionning Dictionary<string, string> because i'm not sure it's good or not to deal with dup / de-dup in headers, I don't know the specs enough

Else it will turn into another footgun TBH

@tobias-tengler
Copy link
Author

tobias-tengler commented Sep 29, 2025

@tebeco I like the idea.
Just want to add that we for example define the headers as an environment variable that we pass to the string option, since we use different exporters for different environments.
If the API would change to just List<KeyValuePair<string, string>> we would have to do this parsing in user-land.

Which could be fine. It would just add churn for everyone currently using the string option.

@tebeco
Copy link

tebeco commented Sep 29, 2025

the other thing i haven't looked at all is performance
i don't know the impact of switching from string to List

what i remember is in aspnetcore they use a special StringValues value type because generally a header often only have one value

i have no knowledge of the OTEL specifics here

im just adding it here in case it rings a bell for someone

i hope it doesn't explode the scope of that evol'

@tebeco
Copy link

tebeco commented Sep 29, 2025

@tebeco I like the idea.

Just want to add that we for example define the headers as an environment variable that we pass to the string option, since we use different exporters for different environments.

If the API would change to just List<KeyValuePair<string, string>> we would have to do this parsing in user-land.

Which could be fine. It would just add churn for everyone currently using the string option.

yeah, i feel the pain, dealing with env var and array is generally not fun

unless you split env var to multiple aggregate yourself and then map it
similar to what dotnet config does for array (but that's not pretty)

i don't think there's such thing as escape in env var
and its also OS specific i assume

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug] Header value in OtlpExporterOptions.Headers can not contain comma
3 participants