Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v3] Fix SpanContextInjectorExtractorTests to account for tracestate #5479

Merged
merged 2 commits into from
Apr 22, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>
{
["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]
Expand All @@ -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]
Expand Down Expand Up @@ -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();

Expand All @@ -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]
Expand Down
Loading