From f6b2d2a8378c80556529b7cebaeac83048f6145b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Fri, 27 Oct 2023 13:15:39 +0200 Subject: [PATCH] W3Trace propagator tests - switch to level 1 --- src/OpenTelemetry.Api/CHANGELOG.md | 3 --- .../Context/Propagation/TraceContextPropagator.cs | 12 +++++++++--- .../Dockerfile | 2 +- .../W3CTraceContextTests.cs | 4 ++-- .../docker-compose.yml | 1 - .../Trace/Propagation/TraceContextPropagatorTest.cs | 8 ++++---- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/OpenTelemetry.Api/CHANGELOG.md b/src/OpenTelemetry.Api/CHANGELOG.md index 96cca2fc44b..67cf8f478ff 100644 --- a/src/OpenTelemetry.Api/CHANGELOG.md +++ b/src/OpenTelemetry.Api/CHANGELOG.md @@ -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 diff --git a/src/OpenTelemetry.Api/Context/Propagation/TraceContextPropagator.cs b/src/OpenTelemetry.Api/Context/Propagation/TraceContextPropagator.cs index 0cdc03e5f7d..16c2456ad4a 100644 --- a/src/OpenTelemetry.Api/Context/Propagation/TraceContextPropagator.cs +++ b/src/OpenTelemetry.Api/Context/Propagation/TraceContextPropagator.cs @@ -235,7 +235,7 @@ internal static bool TryExtractTracestate(string[] tracestateCollection, out str if (tracestateCollection != null) { - int validEntries = 0; + var keySet = new HashSet(); var result = new StringBuilder(); for (int i = 0; i < tracestateCollection.Length; ++i) { @@ -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 @@ -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++; } } diff --git a/test/OpenTelemetry.Instrumentation.W3cTraceContext.Tests/Dockerfile b/test/OpenTelemetry.Instrumentation.W3cTraceContext.Tests/Dockerfile index b0c7a87696e..0508036d3e8 100644 --- a/test/OpenTelemetry.Instrumentation.W3cTraceContext.Tests/Dockerfile +++ b/test/OpenTelemetry.Instrumentation.W3cTraceContext.Tests/Dockerfile @@ -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 diff --git a/test/OpenTelemetry.Instrumentation.W3cTraceContext.Tests/W3CTraceContextTests.cs b/test/OpenTelemetry.Instrumentation.W3cTraceContext.Tests/W3CTraceContextTests.cs index 1effb256171..aacc918f67a 100644 --- a/test/OpenTelemetry.Instrumentation.W3cTraceContext.Tests/W3CTraceContextTests.cs +++ b/test/OpenTelemetry.Instrumentation.W3cTraceContext.Tests/W3CTraceContextTests.cs @@ -103,11 +103,11 @@ public void W3CTraceContextTestSuiteAsync(string value) if (AspNetCoreHostingVersion.Major <= 6) { - Assert.StartsWith("FAILED (failures=4)", lastLine); + Assert.StartsWith("FAILED (failures=3)", lastLine); } else { - Assert.StartsWith("FAILED (failures=1)", lastLine); + Assert.StartsWith("OK", lastLine); } } diff --git a/test/OpenTelemetry.Instrumentation.W3cTraceContext.Tests/docker-compose.yml b/test/OpenTelemetry.Instrumentation.W3cTraceContext.Tests/docker-compose.yml index ae3253078ce..7c421786f5c 100644 --- a/test/OpenTelemetry.Instrumentation.W3cTraceContext.Tests/docker-compose.yml +++ b/test/OpenTelemetry.Instrumentation.W3cTraceContext.Tests/docker-compose.yml @@ -11,4 +11,3 @@ services: command: --TestCaseFilter:CategoryName=W3CTraceContextTests environment: - OTEL_W3CTRACECONTEXT=enabled - - SPEC_LEVEL=2 diff --git a/test/OpenTelemetry.Tests/Trace/Propagation/TraceContextPropagatorTest.cs b/test/OpenTelemetry.Tests/Trace/Propagation/TraceContextPropagatorTest.cs index 089aa248517..f7dae35547f 100644 --- a/test/OpenTelemetry.Tests/Trace/Propagation/TraceContextPropagatorTest.cs +++ b/test/OpenTelemetry.Tests/Trace/Propagation/TraceContextPropagatorTest.cs @@ -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]