Skip to content

Commit

Permalink
Fix test_tracestate_duplicated_keys
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek committed Oct 9, 2023
1 parent 3c2bb7c commit e785a3a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
3 changes: 3 additions & 0 deletions src/OpenTelemetry.Api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
`trace-flags` field of the `traceparent` header.
([#4893](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4893))

* Fix `TraceContextPropagator` by propagating duplicated `tracestate` entries.
([#4937](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4937))

## 1.6.0

Released 2023-Sep-05
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ internal static bool TryExtractTracestate(string[] tracestateCollection, out str

if (tracestateCollection != null)
{
var keySet = new HashSet<string>();
int validEntries = 0;
var result = new StringBuilder();
for (int i = 0; i < tracestateCollection.Length; ++i)
{
Expand Down Expand Up @@ -264,7 +264,7 @@ internal static bool TryExtractTracestate(string[] tracestateCollection, out str
continue;
}

if (keySet.Count >= 32)
if (validEntries >= 32)
{
// https://github.com/w3c/trace-context/blob/master/spec/20-http_request_header_format.md#list
// test_tracestate_member_count_limit
Expand Down Expand Up @@ -294,19 +294,13 @@ internal static bool TryExtractTracestate(string[] tracestateCollection, out str
return false;
}

// ValidateKey() call above has ensured the key does not contain upper case letters.
if (!keySet.Add(key.ToString()))
{
// test_tracestate_duplicated_keys
return false;
}

if (result.Length > 0)
{
result.Append(',');
}

result.Append(listMember.ToString());
validEntries++;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ public void W3CTraceContextTestSuiteAsync(string value)

if (AspNetCoreHostingVersion.Major <= 6)
{
Assert.StartsWith("FAILED (failures=5)", lastLine);
Assert.StartsWith("FAILED (failures=4)", lastLine);
}
else
{
Assert.StartsWith("FAILED (failures=2)", lastLine);
Assert.StartsWith("FAILED (failures=1)", lastLine);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ public void Inject_WithTracestate()
public void DuplicateKeys()
{
// test_tracestate_duplicated_keys
Assert.Empty(CallTraceContextPropagator("foo=1,foo=1"));
Assert.Empty(CallTraceContextPropagator("foo=1,foo=2"));
Assert.Empty(CallTraceContextPropagator(new[] { "foo=1", "foo=1" }));
Assert.Empty(CallTraceContextPropagator(new[] { "foo=1", "foo=2" }));
Assert.Equal("foo=1,foo=1", CallTraceContextPropagator("foo=1,foo=1"));
Assert.Equal("foo=1,foo=2", CallTraceContextPropagator("foo=1,foo=2"));
Assert.Equal("foo=1,foo=1", CallTraceContextPropagator(new[] { "foo=1", "foo=1" }));
Assert.Equal("foo=1,foo=2", CallTraceContextPropagator(new[] { "foo=1", "foo=2" }));
}

[Fact]
Expand Down

0 comments on commit e785a3a

Please sign in to comment.