From 69334b7e9d50800cbbcb96f30ff9cf7f02a4a1e9 Mon Sep 17 00:00:00 2001 From: Andrew Lock Date: Mon, 22 Apr 2024 13:16:43 +0100 Subject: [PATCH] [v3] Fix `SpanContextInjectorExtractorTests` to account for `tracestate` (#5479) * Refactor unit tests to expose errors more easily * Fix SpanContextInjectorExtractorTests expectations to account for tracestate --- .../SpanContextInjectorExtractorTests.cs | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/tracer/test/Datadog.Trace.Tests/SpanContextInjectorExtractorTests.cs b/tracer/test/Datadog.Trace.Tests/SpanContextInjectorExtractorTests.cs index effbb28949cc..a4b58219ba07 100644 --- a/tracer/test/Datadog.Trace.Tests/SpanContextInjectorExtractorTests.cs +++ b/tracer/test/Datadog.Trace.Tests/SpanContextInjectorExtractorTests.cs @@ -31,13 +31,13 @@ public void BasicInjectionInDict() injector.Inject(headers, (h, k, v) => h[k] = v, context); - headers.Count.Should().Be(expected: 3); - headers.Keys.Should().Contain("x-datadog-trace-id"); - headers.Keys.Should().Contain("x-datadog-parent-id"); - headers.Keys.Should().Contain("traceparent"); - headers["x-datadog-trace-id"].Should().Be(traceId.ToString()); - headers["x-datadog-parent-id"].Should().Be(spanId.ToString()); - headers["traceparent"].Should().Be($"00-{traceId:x32}-{spanId:x16}-01"); + headers.Should().BeEquivalentTo(new Dictionary + { + ["x-datadog-trace-id"] = traceId.ToString(), + ["x-datadog-parent-id"] = spanId.ToString(), + ["traceparent"] = $"00-{traceId:x32}-{spanId:x16}-01", + ["tracestate"] = $"dd=p:{spanId:x16}", + }); } [Fact] @@ -52,7 +52,7 @@ public void BasicInjectionInStringBuilder() headers.Length--; headers.Append("}"); - headers.ToString().Should().Be("{{x-datadog-trace-id,123456789101112},{x-datadog-parent-id,109876543210},{traceparent,00-000000000000000000007048860f3a38-000000199526feea-01}}"); + headers.ToString().Should().Be("{{x-datadog-trace-id,123456789101112},{x-datadog-parent-id,109876543210},{traceparent,00-000000000000000000007048860f3a38-000000199526feea-01},{tracestate,dd=p:000000199526feea}}"); } [Fact] @@ -80,13 +80,17 @@ public void InjectionWithDsm() injector.InjectIncludingDsm(headers, (h, k, v) => h[k] = v, context, "Pneumatic Tube", "cashier1"); - headers.Count.Should().Be(expected: 4); - // regular trace propagation headers - headers.Keys.Should().Contain("x-datadog-trace-id"); - headers.Keys.Should().Contain("x-datadog-parent-id"); - headers.Keys.Should().Contain("traceparent"); - // DSM specific header - headers.Keys.Should().Contain("dd-pathway-ctx-base64"); + headers.Keys.Should().BeEquivalentTo( + [ + // regular trace propagation headers + "x-datadog-trace-id", + "x-datadog-parent-id", + "traceparent", + "tracestate", + // DSM specific header + "dd-pathway-ctx-base64", + ]); + // should not throw (i.e. should be valid base64) Convert.FromBase64String(headers["dd-pathway-ctx-base64"]).Should().NotBeEmpty(); @@ -105,11 +109,14 @@ public void NoDsmInjectionIsDisabled() injector.InjectIncludingDsm(headers, (h, k, v) => h[k] = v, context, "Pneumatic Tube", "cashier1"); - headers.Count.Should().Be(expected: 3); - // regular trace propagation headers only - headers.Keys.Should().Contain("x-datadog-trace-id"); - headers.Keys.Should().Contain("x-datadog-parent-id"); - headers.Keys.Should().Contain("traceparent"); + headers.Keys.Should().BeEquivalentTo( + [ + // regular trace propagation headers + "x-datadog-trace-id", + "x-datadog-parent-id", + "traceparent", + "tracestate", + ]); } [Fact]