Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
13acd77
[OTLP] Add support for GZip compression
martincostello Apr 10, 2026
41c67d7
[OpenTelemetry] Pool SuppressInstrumentationScope
martincostello Apr 10, 2026
4d6b64d
[OpenTelemetry] Add MemoryDiagnoser
martincostello Apr 10, 2026
184db7d
[OpenTelemetry] Fix lint warning
martincostello Apr 10, 2026
3b0ccd0
[OpenTelemetry] Optimize trace sampling
martincostello Apr 10, 2026
c125346
[OTLP] Avoid allocating array
martincostello Apr 10, 2026
aed4dbc
[OTLP] Extend test coverage
martincostello Apr 10, 2026
e589b46
[OpenTelemetry] Fix lint warnings
martincostello Apr 10, 2026
6cb4afe
[OpenTelemetry] Revert accessibility modifier
martincostello Apr 10, 2026
0ab86a9
[OpenTelemetry] Address feedback
martincostello Apr 10, 2026
aa4156a
[OpenTelemetry] Address review comments
martincostello Apr 10, 2026
60b76a5
[OpenTelemetry] Address feedback
martincostello Apr 10, 2026
e833ae1
[OpenTelemetry] Fix lint warning
martincostello Apr 10, 2026
13137f9
[OTLP] Address feedback
martincostello Apr 10, 2026
d23b151
[OpenTelemetry] Benchmark BaggagePropagator
martincostello Apr 10, 2026
8929d32
[OpenTelemetry] Optimize BaggagePropagator
martincostello Apr 10, 2026
496807c
[OpenTelemetry] Optimize TraceContextPropagator
martincostello Apr 10, 2026
3a6d50d
[OpenTelemetry] Extend test coverage
martincostello Apr 11, 2026
75cafd5
[OpenTelemetry] Address feedback
martincostello Apr 11, 2026
5842eec
[Api] Add test for regression
martincostello Apr 11, 2026
c509aa3
[Api] Fix regression test
martincostello Apr 11, 2026
eeebb5c
Merge branch 'reduce-SuppressInstrumentationScope-overhead' into perf…
martincostello Apr 12, 2026
d97351a
Merge branch 'optimize-trace-sampling' into performance-improvements
martincostello Apr 12, 2026
3981f6b
Merge branch 'optimize-BaggagePropagator' into performance-improvements
martincostello Apr 12, 2026
9ebb662
Merge branch 'optimize-TraceContextPropagator' into performance-impro…
martincostello Apr 12, 2026
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
68 changes: 52 additions & 16 deletions src/OpenTelemetry.Api/Context/Propagation/BaggagePropagator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ public class BaggagePropagator : TextMapPropagator
private const int MaxBaggageLength = 8192;
private const int MaxBaggageItems = 180;

private static readonly char[] EqualSignSeparator = ['='];
#if !NET
private static readonly char[] CommaSignSeparator = [','];
#endif

/// <inheritdoc/>
public override ISet<string> Fields => new HashSet<string> { BaggageHeaderName };
Expand Down Expand Up @@ -50,9 +51,9 @@ public override PropagationContext Extract<T>(PropagationContext context, T carr
try
{
var baggageCollection = getter(carrier, BaggageHeaderName);
if (baggageCollection?.Any() ?? false)
if (baggageCollection is not null)
{
if (TryExtractBaggage([.. baggageCollection], out var baggageItems))
if (TryExtractBaggage(baggageCollection, out var baggageItems))
{
Baggage baggage =
#if NET
Expand Down Expand Up @@ -113,7 +114,7 @@ public override void Inject<T>(PropagationContext context, T carrier, Action<T,
}

internal static bool TryExtractBaggage(
string[] baggageCollection,
IEnumerable<string> baggageCollection,
#if NET
[NotNullWhen(true)]
#endif
Expand All @@ -135,43 +136,78 @@ internal static bool TryExtractBaggage(
continue;
}

foreach (var pair in item.Split(CommaSignSeparator))
#if NET
var span = item.AsSpan();
while (!span.IsEmpty)
{
baggageLength += pair.Length + 1; // pair and comma
ReadOnlySpan<char> pairSpan;

var index = span.IndexOf(',');
if (index < 0)
{
pairSpan = span;
span = default;
}
else
{
pairSpan = span[..index];
span = span[(index + 1)..];
}

baggageLength += pairSpan.Length + 1;

if (baggageLength >= MaxBaggageLength || baggageDictionary?.Count >= MaxBaggageItems)
{
done = true;
break;
}

#if NET
if (pair.IndexOf('=', StringComparison.Ordinal) < 0)
#else
if (pair.IndexOf('=') < 0)
#endif
index = pairSpan.IndexOf('=');
if (index < 0)
{
continue;
}

var parts = pair.Split(EqualSignSeparator, 2);
if (parts.Length != 2)
var key = WebUtility.UrlDecode(pairSpan[..index].ToString());
var value = WebUtility.UrlDecode(pairSpan[(index + 1)..].ToString());

if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(value))
{
continue;
}

var key = WebUtility.UrlDecode(parts[0]);
var value = WebUtility.UrlDecode(parts[1]);
baggageDictionary ??= [];
baggageDictionary[key] = value;
}
#else
foreach (var pair in item.Split(CommaSignSeparator))
{
baggageLength += pair.Length + 1;

if (baggageLength >= MaxBaggageLength || baggageDictionary?.Count >= MaxBaggageItems)
{
done = true;
break;
}

var index = pair.IndexOf('=');
if (index < 0)
{
continue;
}

var key = WebUtility.UrlDecode(pair.Substring(0, index));
var value = WebUtility.UrlDecode(pair.Substring(index + 1));

if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(value))
{
continue;
}

baggageDictionary ??= [];

baggageDictionary[key] = value;
}
#endif
}

baggage = baggageDictionary;
Expand Down
Loading
Loading