Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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: 5 additions & 4 deletions src/OpenTelemetry.Api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ Notes](../../RELEASENOTES.md).

## Unreleased

* The library is now marked as trim and AOT compatible.
([#7441](https://github.com/open-telemetry/opentelemetry-dotnet/pull/7441))

* Fixed `TraceContextPropagator` to normalize empty `tracestate` header values
to `null` when extracting trace context.
([#7407](https://github.com/open-telemetry/opentelemetry-dotnet/pull/7407))
([#7407](https://github.com/open-telemetry/opentelemetry-dotnet/pull/7407),
[#7433](https://github.com/open-telemetry/opentelemetry-dotnet/pull/7433))

* The library is now marked as trim and AOT compatible.
([#7441](https://github.com/open-telemetry/opentelemetry-dotnet/pull/7441))

* **Experimental (pre-release builds only):** Updated `EnvironmentVariableCarrier.Get`
to read only the normalized environment variable name, following the updated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,11 @@ private static bool TryExtractMultipleTracestate(IEnumerable<string> tracestateC

foreach (var tracestateEntry in tracestateCollection)
{
if (tracestateEntry is not { Length: > 0 })
{
continue;
}

var tracestate = tracestateEntry.AsSpan();
var begin = 0;
while (begin < tracestate.Length)
Expand Down Expand Up @@ -465,11 +470,11 @@ private static bool TryExtractMultipleTracestate(IEnumerable<string> tracestateC
return true;
}

private static bool TryExtractSingleTracestate(string tracestate, out string tracestateResult)
private static bool TryExtractSingleTracestate(string? tracestate, out string tracestateResult)
{
tracestateResult = string.Empty;

if (tracestate.Length == 0)
if (tracestate is not { Length: > 0 })
{
return true;
}
Comment thread
martincostello marked this conversation as resolved.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,48 @@ public void TryExtractTracestate_NullCollectionReturnsEmpty()
Assert.Empty(actual);
}

[Fact]
public void Extract_HandlesNullTracestateValue()
{
var headers = new Dictionary<string, string>
{
{ TraceParent, $"00-{TraceId}-{SpanId}-01" },
};

var propagator = new TraceContextPropagator();
var context = propagator.Extract(default, headers, (_, name) => headers.TryGetValue(name, out var value) ? [value] : [null!]);

Assert.Equal(ActivityTraceId.CreateFromString(TraceId.AsSpan()), context.ActivityContext.TraceId);
Assert.Equal(ActivitySpanId.CreateFromString(SpanId.AsSpan()), context.ActivityContext.SpanId);

Assert.True(context.ActivityContext.IsRemote);
Assert.True(context.ActivityContext.IsValid());
Assert.NotEqual(0, (int)(context.ActivityContext.TraceFlags & ActivityTraceFlags.Recorded));

Assert.Null(context.ActivityContext.TraceState);
}

[Fact]
public void Extract_HandlesNullTracestateValues()
{
var headers = new Dictionary<string, string>
{
{ TraceParent, $"00-{TraceId}-{SpanId}-01" },
};

var propagator = new TraceContextPropagator();
var context = propagator.Extract(default, headers, (_, name) => headers.TryGetValue(name, out var value) ? [value] : [string.Empty, null!]);

Assert.Equal(ActivityTraceId.CreateFromString(TraceId.AsSpan()), context.ActivityContext.TraceId);
Assert.Equal(ActivitySpanId.CreateFromString(SpanId.AsSpan()), context.ActivityContext.SpanId);

Assert.True(context.ActivityContext.IsRemote);
Assert.True(context.ActivityContext.IsValid());
Assert.NotEqual(0, (int)(context.ActivityContext.TraceFlags & ActivityTraceFlags.Recorded));

Assert.Null(context.ActivityContext.TraceState);
}

[Fact]
public void Inject_NoTracestate()
{
Expand Down