From 07234e47f3d58436fb08144fa822cca181ec1d5c Mon Sep 17 00:00:00 2001 From: Zach Montoya Date: Tue, 26 Nov 2024 10:51:46 -0800 Subject: [PATCH 1/3] Add weblog test to assert that library tracers continue the trace when they receive x-datadog-trace-id= and x-datadog-parent-id=0 --- tests/test_distributed.py | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/tests/test_distributed.py b/tests/test_distributed.py index ca8af6b56f..65040ea8e7 100644 --- a/tests/test_distributed.py +++ b/tests/test_distributed.py @@ -3,6 +3,7 @@ # Copyright 2022 Datadog, Inc. import json +from utils.parametric.spec.trace import SAMPLING_PRIORITY_KEY, ORIGIN from utils import weblog, interfaces, scenarios, features @@ -25,3 +26,51 @@ def test_main(self): assert "x-datadog-sampling-priority" not in data["request_headers"] assert "x-datadog-tags" not in data["request_headers"] assert "x-datadog-trace-id" not in data["request_headers"] + + +@scenarios.default +@features.datadog_headers_propagation +class Test_Synthetics_APM_Datadog: + def setup_synthetics(self): + self.r = weblog.get( + "/", + headers={ + "x-datadog-trace-id": "123456789", + "x-datadog-parent-id": "0", + "x-datadog-sampling-priority": "1", + "x-datadog-origin": "synthetics", + }, + ) + + def test_synthetics(self): + interfaces.library.assert_trace_exists(self.r) + spans = interfaces.agent.get_spans_list(self.r) + assert len(spans) == 1, "Agent received the incorrect amount of spans" + + span = spans[0] + assert span.get("traceID") == "123456789" + assert "parentID" not in span or span.get("parentID") == 0 or span.get("parentID") is None + assert span.get("meta")[ORIGIN] == "synthetics" + assert span.get("metrics")[SAMPLING_PRIORITY_KEY] == 1 + + def setup_synthetics_browser(self): + self.r = weblog.get( + "/", + headers={ + "x-datadog-trace-id": "123456789", + "x-datadog-parent-id": "0", + "x-datadog-sampling-priority": "1", + "x-datadog-origin": "synthetics-browser", + }, + ) + + def test_synthetics_browser(self): + interfaces.library.assert_trace_exists(self.r) + spans = interfaces.agent.get_spans_list(self.r) + assert len(spans) == 1, "Agent received the incorrect amount of spans" + + span = spans[0] + assert span.get("traceID") == "123456789" + assert "parentID" not in span or span.get("parentID") == 0 or span.get("parentID") is None + assert span.get("meta")[ORIGIN] == "synthetics-browser" + assert span.get("metrics")[SAMPLING_PRIORITY_KEY] == 1 From 464e2d3ee4b3c12b254e3c149a3b3ad5ac69feef Mon Sep 17 00:00:00 2001 From: Zach Montoya Date: Mon, 2 Dec 2024 13:37:37 -0800 Subject: [PATCH 2/3] Use different trace ID's for synthetics tests to avoid failing the test tests/test_data_integrity.py::Test_TraceUniqueness::test_trace_ids --- tests/test_distributed.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_distributed.py b/tests/test_distributed.py index 65040ea8e7..349e0fff9a 100644 --- a/tests/test_distributed.py +++ b/tests/test_distributed.py @@ -35,7 +35,7 @@ def setup_synthetics(self): self.r = weblog.get( "/", headers={ - "x-datadog-trace-id": "123456789", + "x-datadog-trace-id": "1234567890", "x-datadog-parent-id": "0", "x-datadog-sampling-priority": "1", "x-datadog-origin": "synthetics", @@ -48,7 +48,7 @@ def test_synthetics(self): assert len(spans) == 1, "Agent received the incorrect amount of spans" span = spans[0] - assert span.get("traceID") == "123456789" + assert span.get("traceID") == "1234567890" assert "parentID" not in span or span.get("parentID") == 0 or span.get("parentID") is None assert span.get("meta")[ORIGIN] == "synthetics" assert span.get("metrics")[SAMPLING_PRIORITY_KEY] == 1 @@ -57,7 +57,7 @@ def setup_synthetics_browser(self): self.r = weblog.get( "/", headers={ - "x-datadog-trace-id": "123456789", + "x-datadog-trace-id": "1234567891", "x-datadog-parent-id": "0", "x-datadog-sampling-priority": "1", "x-datadog-origin": "synthetics-browser", @@ -70,7 +70,7 @@ def test_synthetics_browser(self): assert len(spans) == 1, "Agent received the incorrect amount of spans" span = spans[0] - assert span.get("traceID") == "123456789" + assert span.get("traceID") == "1234567891" assert "parentID" not in span or span.get("parentID") == 0 or span.get("parentID") is None assert span.get("meta")[ORIGIN] == "synthetics-browser" assert span.get("metrics")[SAMPLING_PRIORITY_KEY] == 1 From ba90973bff2bdb6f7c395c67f7c9c05e472ca073 Mon Sep 17 00:00:00 2001 From: Zach Montoya Date: Mon, 2 Dec 2024 17:33:32 -0800 Subject: [PATCH 3/3] Update manifests to skip the new Test_Synthetics_APM_Datadog tests for failing languages/weblogs --- manifests/golang.yml | 1 + manifests/nodejs.yml | 3 +++ 2 files changed, 4 insertions(+) diff --git a/manifests/golang.yml b/manifests/golang.yml index 87558c5694..c7b63afbd9 100644 --- a/manifests/golang.yml +++ b/manifests/golang.yml @@ -585,6 +585,7 @@ tests/: Test_LibraryHeaders: v1.60.0.dev0 test_distributed.py: Test_DistributedHttp: missing_feature + Test_Synthetics_APM_Datadog: bug (APMAPI-901) # the incoming headers are considered invalid test_identify.py: Test_Basic: v1.37.0 Test_Propagate: v1.48.0-rc.1 diff --git a/manifests/nodejs.yml b/manifests/nodejs.yml index 6bdbe5b40e..20cf477e4e 100644 --- a/manifests/nodejs.yml +++ b/manifests/nodejs.yml @@ -755,6 +755,9 @@ tests/: Test_Config_UnifiedServiceTagging_Default: *ref_5_25_0 test_distributed.py: Test_DistributedHttp: missing_feature + Test_Synthetics_APM_Datadog: + '*': *ref_5_25_0 + nextjs: bug (APMAPI-939) # the nextjs weblog application changes the sampling priority from 1.0 to 2.0 test_identify.py: Test_Basic: v2.4.0 Test_Propagate: *ref_3_2_0