diff --git a/tests/test_distributed.py b/tests/test_distributed.py index b5249e917b5..2571ffde404 100644 --- a/tests/test_distributed.py +++ b/tests/test_distributed.py @@ -28,6 +28,48 @@ def test_main(self): assert "x-datadog-trace-id" not in data["request_headers"] +@scenarios.trace_propagation_style_w3c_datadog_b3 +@features.w3c_headers_injection_and_extraction +class Test_Span_Links_Flags_From_Conflicting_Contexts: + """Verify headers containing conflicting trace context information are added as span links""" + + def setup_span_links_from_conflicting_contexts(self): + extract_headers = { + "traceparent": "00-11111111111111110000000000000002-000000003ade68b1-01", + "tracestate": "dd=s:2;p:000000000000000a,foo=1", + "x-datadog-parent-id": "10", + "x-datadog-trace-id": "2", + "x-datadog-tags": "_dd.p.tid=2222222222222222", + "x-datadog-sampling-priority": "2", + "x-b3-traceid": "11111111111111110000000000000003", + "x-b3-spanid": "a2fb4a1d1a96d312", + "x-b3-sampled": "0", + } + + self.req = weblog.get("/make_distant_call", params={"url": "http://weblog:7777"}, headers=extract_headers) + + def test_span_links_from_conflicting_contexts(self): + trace = [ + span + for _, _, span in interfaces.library.get_spans(self.req, full_trace=True) + if retrieve_span_links(span) is not None + and span["trace_id"] == 2 # Only fetch the trace that is related to the header extractions + ] + + for span in trace: + span_links = retrieve_span_links(span) + assert len(span_links) == 2 + link1 = span_links[0] + assert link1["flags"] == 1 | TRACECONTEXT_FLAGS_SET + + link2 = span_links[1] + assert link2["flags"] == 0 | TRACECONTEXT_FLAGS_SET + return + + # Return false if we get no span links + assert False + + @scenarios.trace_propagation_style_w3c_datadog_b3 @features.w3c_headers_injection_and_extraction class Test_Span_Links_From_Conflicting_Contexts: @@ -193,48 +235,6 @@ def test_span_links_from_conflicting_contexts_datadog_precedence(self): assert False -@scenarios.trace_propagation_style_w3c_datadog_b3 -@features.w3c_headers_injection_and_extraction -class Test_Span_Links_Flags_From_Conflicting_Contexts: - """Verify headers containing conflicting trace context information are added as span links""" - - def setup_span_links_from_conflicting_contexts(self): - extract_headers = { - "traceparent": "00-11111111111111110000000000000002-000000003ade68b1-01", - "tracestate": "dd=s:2;p:000000000000000a,foo=1", - "x-datadog-parent-id": "10", - "x-datadog-trace-id": "2", - "x-datadog-tags": "_dd.p.tid=2222222222222222", - "x-datadog-sampling-priority": "2", - "x-b3-traceid": "11111111111111110000000000000003", - "x-b3-spanid": "a2fb4a1d1a96d312", - "x-b3-sampled": "0", - } - - self.req = weblog.get("/make_distant_call", params={"url": "http://weblog:7777"}, headers=extract_headers) - - def test_span_links_from_conflicting_contexts(self): - trace = [ - span - for _, _, span in interfaces.library.get_spans(self.req, full_trace=True) - if retrieve_span_links(span) is not None - and span["trace_id"] == 2 # Only fetch the trace that is related to the header extractions - ] - - for span in trace: - span_links = retrieve_span_links(span) - assert len(span_links) == 2 - link1 = span_links[0] - assert link1["flags"] == 1 | TRACECONTEXT_FLAGS_SET - - link2 = span_links[1] - assert link2["flags"] == 0 | TRACECONTEXT_FLAGS_SET - return - - # Return false if we get no span links - assert False - - @scenarios.trace_propagation_style_w3c_datadog_b3 @features.w3c_headers_injection_and_extraction class Test_Span_Links_Omit_Tracestate_From_Conflicting_Contexts: