Skip to content

Commit

Permalink
W3Trace propagator tests - switch to level 1
Browse files Browse the repository at this point in the history
  • Loading branch information
Kielek committed Oct 27, 2023
1 parent b4faa7c commit c52d2a4
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
3 changes: 0 additions & 3 deletions src/OpenTelemetry.Api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
`8.0.0-rc.2.23479.6`.
([#4959](https://github.com/open-telemetry/opentelemetry-dotnet/pull/4959))

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

## 1.7.0-alpha.1

Released 2023-Oct-16
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)
{
int validEntries = 0;
var keySet = new HashSet<string>();
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 (validEntries >= 32)
if (keySet.Count >= 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,13 +294,19 @@ 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 @@ -9,7 +9,7 @@ FROM ubuntu AS w3c
#Install git
WORKDIR /w3c
RUN apt-get update && apt-get install -y git
RUN git clone https://github.com/w3c/trace-context.git
RUN git clone --branch level-1 https://github.com/w3c/trace-context.git

FROM mcr.microsoft.com/dotnet/sdk:${BUILD_SDK_VERSION} AS build
ARG PUBLISH_CONFIGURATION=Release
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=4)", lastLine);
Assert.StartsWith("FAILED (errors=3)", lastLine);
}
else
{
Assert.StartsWith("FAILED (failures=1)", lastLine);
Assert.StartsWith("OK", lastLine);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ services:
command: --TestCaseFilter:CategoryName=W3CTraceContextTests
environment:
- OTEL_W3CTRACECONTEXT=enabled
- SPEC_LEVEL=2
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.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" }));
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" }));
}

[Fact]
Expand Down

0 comments on commit c52d2a4

Please sign in to comment.