From 9c26730e12231319fb71aa0572c45d6a01676b1a Mon Sep 17 00:00:00 2001 From: Munir Abdinur Date: Fri, 22 Nov 2024 14:58:26 -0500 Subject: [PATCH] parametric: move make_single_request_and_get_inject_headers to APMLibrary (#3512) --- tests/parametric/test_128_bit_traceids.py | 76 ++++++------- tests/parametric/test_headers_b3.py | 15 ++- tests/parametric/test_headers_b3multi.py | 17 ++- tests/parametric/test_headers_baggage.py | 30 +++-- tests/parametric/test_headers_datadog.py | 15 +-- tests/parametric/test_headers_none.py | 17 +-- tests/parametric/test_headers_precedence.py | 104 +++++++----------- tests/parametric/test_headers_tracecontext.py | 23 ++-- .../parametric/test_headers_tracestate_dd.py | 85 +++++--------- .../test_otel_api_interoperability.py | 4 +- utils/parametric/_library_client.py | 7 +- utils/parametric/headers.py | 4 - 12 files changed, 159 insertions(+), 238 deletions(-) delete mode 100644 utils/parametric/headers.py diff --git a/tests/parametric/test_128_bit_traceids.py b/tests/parametric/test_128_bit_traceids.py index 6c6924accf..c9c12978a4 100644 --- a/tests/parametric/test_128_bit_traceids.py +++ b/tests/parametric/test_128_bit_traceids.py @@ -1,6 +1,5 @@ import pytest -from utils.parametric.headers import make_single_request_and_get_inject_headers from utils.parametric.spec.trace import find_first_span_in_trace_payload, find_trace, find_only_span from utils import missing_feature, context, scenarios, features @@ -20,8 +19,7 @@ def test_datadog_128_bit_propagation(self, test_agent, test_library): headers. """ with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, + headers = test_library.dd_make_child_span_and_get_headers( [ ["x-datadog-trace-id", "1234567890123456789"], ["x-datadog-parent-id", "987654321"], @@ -47,8 +45,7 @@ def test_datadog_128_bit_propagation_tid_long(self, test_agent, test_library): """ Ensure that incoming tids that are too long are discarded. """ with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, + headers = test_library.dd_make_child_span_and_get_headers( [ ["x-datadog-trace-id", "1234567890123456789"], ["x-datadog-parent-id", "987654321"], @@ -74,8 +71,7 @@ def test_datadog_128_bit_propagation_tid_short(self, test_agent, test_library): """ Ensure that incoming tids that are too short are discarded. """ with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, + headers = test_library.dd_make_child_span_and_get_headers( [ ["x-datadog-trace-id", "1234567890123456789"], ["x-datadog-parent-id", "987654321"], @@ -101,8 +97,7 @@ def test_datadog_128_bit_propagation_tid_chars(self, test_agent, test_library): """ Ensure that incoming tids with bad characters are discarded. """ with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, + headers = test_library.dd_make_child_span_and_get_headers( [ ["x-datadog-trace-id", "1234567890123456789"], ["x-datadog-parent-id", "987654321"], @@ -130,8 +125,7 @@ def test_datadog_128_bit_propagation_tid_malformed_optional_tag(self, test_agent """ Ensure that if incoming tids are malformed and the error is tagged, the tag is set to the expected value. """ with test_library: - make_single_request_and_get_inject_headers( - test_library, + test_library.dd_make_child_span_and_get_headers( [ ["x-datadog-trace-id", "1234567890123456789"], ["x-datadog-parent-id", "987654321"], @@ -151,8 +145,8 @@ def test_datadog_128_bit_propagation_and_generation(self, test_agent, test_libra """Ensure that a new span from incoming headers does not modify the trace id when generation is true. """ with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, [["x-datadog-trace-id", "1234567890123456789"], ["x-datadog-parent-id", "987654321"],], + headers = test_library.dd_make_child_span_and_get_headers( + [["x-datadog-trace-id", "1234567890123456789"], ["x-datadog-parent-id", "987654321"],], ) span = find_only_span(test_agent.wait_for_num_traces(1)) trace_id = span.get("trace_id") @@ -172,7 +166,7 @@ def test_datadog_128_bit_generation_disabled(self, test_agent, test_library): datadog headers, and populated in trace data. """ with test_library: - headers = make_single_request_and_get_inject_headers(test_library, []) + headers = test_library.dd_make_child_span_and_get_headers([]) span = find_only_span(test_agent.wait_for_num_traces(1)) trace_id = span.get("trace_id") dd_p_tid = span["meta"].get("_dd.p.tid") @@ -192,7 +186,7 @@ def test_datadog_128_bit_generation_enabled(self, test_agent, test_library): datadog headers, and populated in trace data. """ with test_library: - headers = make_single_request_and_get_inject_headers(test_library, []) + headers = test_library.dd_make_child_span_and_get_headers([]) span = find_only_span(test_agent.wait_for_num_traces(1)) trace_id = span.get("trace_id") dd_p_tid = span["meta"].get("_dd.p.tid") @@ -214,7 +208,7 @@ def test_datadog_128_bit_generation_enabled_by_default(self, test_agent, test_li datadog headers, and populated in trace data. """ with test_library: - headers = make_single_request_and_get_inject_headers(test_library, []) + headers = test_library.dd_make_child_span_and_get_headers([]) span = find_only_span(test_agent.wait_for_num_traces(1)) trace_id = span.get("trace_id") dd_p_tid = span["meta"].get("_dd.p.tid") @@ -235,8 +229,8 @@ def test_b3single_128_bit_propagation(self, test_agent, test_library): single-header. """ with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, [["b3", "640cfd8d00000000abcdefab12345678-000000003ade68b1-1"],], + headers = test_library.dd_make_child_span_and_get_headers( + [["b3", "640cfd8d00000000abcdefab12345678-000000003ade68b1-1"],], ) span = find_only_span(test_agent.wait_for_num_traces(1)) trace_id = span.get("trace_id") @@ -257,9 +251,7 @@ def test_b3single_128_bit_propagation_and_generation(self, test_agent, test_libr """Ensure that a new span from incoming headers does not modify the trace id when generation is true. """ with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, [["b3", "abcdefab12345678-000000003ade68b1-1"],], - ) + headers = test_library.dd_make_child_span_and_get_headers([["b3", "abcdefab12345678-000000003ade68b1-1"],],) span = find_only_span(test_agent.wait_for_num_traces(1)) trace_id = span.get("trace_id") dd_p_tid = span["meta"].get("_dd.p.tid") @@ -282,7 +274,7 @@ def test_b3single_128_bit_generation_disabled(self, test_agent, test_library): single-header, and populated in trace data. """ with test_library: - headers = make_single_request_and_get_inject_headers(test_library, []) + headers = test_library.dd_make_child_span_and_get_headers([]) span = find_only_span(test_agent.wait_for_num_traces(1)) fields = headers["b3"].split("-", 1) @@ -299,7 +291,7 @@ def test_b3single_128_bit_generation_enabled(self, test_agent, test_library): single-header, and populated in trace data. """ with test_library: - headers = make_single_request_and_get_inject_headers(test_library, []) + headers = test_library.dd_make_child_span_and_get_headers([]) span = find_only_span(test_agent.wait_for_num_traces(1)) fields = headers["b3"].split("-", 1) @@ -315,8 +307,7 @@ def test_b3multi_128_bit_propagation(self, test_agent, test_library): multi-headers. """ with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, + headers = test_library.dd_make_child_span_and_get_headers( [["x-b3-traceid", "640cfd8d00000000abcdefab12345678"], ["x-b3-spanid", "000000003ade68b1"],], ) span = find_only_span(test_agent.wait_for_num_traces(1)) @@ -336,8 +327,8 @@ def test_b3multi_128_bit_propagation_and_generation(self, test_agent, test_libra """Ensure that a new span from incoming headers does not modify the trace id when generation is true. """ with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, [["x-b3-traceid", "abcdefab12345678"], ["x-b3-spanid", "000000003ade68b1"],], + headers = test_library.dd_make_child_span_and_get_headers( + [["x-b3-traceid", "abcdefab12345678"], ["x-b3-spanid", "000000003ade68b1"],], ) span = find_only_span(test_agent.wait_for_num_traces(1)) trace_id = span.get("trace_id") @@ -359,7 +350,7 @@ def test_b3multi_128_bit_generation_disabled(self, test_agent, test_library): multi-headers, and populated in trace data. """ with test_library: - headers = make_single_request_and_get_inject_headers(test_library, []) + headers = test_library.dd_make_child_span_and_get_headers([]) span = find_only_span(test_agent.wait_for_num_traces(1)) check_64_bit_trace_id(headers["x-b3-traceid"], span.get("trace_id"), span["meta"].get("_dd.p.tid")) @@ -374,7 +365,7 @@ def test_b3multi_128_bit_generation_enabled(self, test_agent, test_library): multi-headers, and populated in trace data. """ with test_library: - headers = make_single_request_and_get_inject_headers(test_library, []) + headers = test_library.dd_make_child_span_and_get_headers([]) span = find_only_span(test_agent.wait_for_num_traces(1)) check_128_bit_trace_id(headers["x-b3-traceid"], span.get("trace_id"), span["meta"].get("_dd.p.tid")) @@ -389,8 +380,8 @@ def test_w3c_128_bit_propagation(self, test_agent, test_library): headers. """ with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, [["traceparent", "00-640cfd8d00000000abcdefab12345678-000000003ade68b1-01",],], + headers = test_library.dd_make_child_span_and_get_headers( + [["traceparent", "00-640cfd8d00000000abcdefab12345678-000000003ade68b1-01",],], ) span = find_only_span(test_agent.wait_for_num_traces(1)) trace_id = span.get("trace_id") @@ -411,8 +402,7 @@ def test_w3c_128_bit_propagation_tid_consistent(self, test_agent, test_library): the trace header then no error is reported. """ with test_library: - make_single_request_and_get_inject_headers( - test_library, + test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-640cfd8d00000000abcdefab12345678-000000003ade68b1-01"], ["tracestate", "dd=t.tid:640cfd8d00000000"], @@ -464,8 +454,7 @@ def test_w3c_128_bit_propagation_tid_inconsistent(self, test_agent, test_library the trace header, the trace header tid is preserved. """ with test_library: - make_single_request_and_get_inject_headers( - test_library, + test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-640cfd8d00000000abcdefab12345678-000000003ade68b1-01"], ["tracestate", "dd=t.tid:640cfd8d0000ffff"], @@ -492,8 +481,7 @@ def test_w3c_128_bit_propagation_tid_inconsistent_optional_tag(self, test_agent, the trace header the error is tagged. """ with test_library: - make_single_request_and_get_inject_headers( - test_library, + test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-640cfd8d00000000abcdefab12345678-000000003ade68b1-01"], ["tracestate", "dd=t.tid:640cfd8d0000ffff"], @@ -514,8 +502,7 @@ def test_w3c_128_bit_propagation_tid_malformed(self, test_agent, test_library): """Ensure that if the trace state contains a tid that is badly formed, the trace header tid is preserved. """ with test_library: - make_single_request_and_get_inject_headers( - test_library, + test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-640cfd8d00000000abcdefab12345678-000000003ade68b1-01"], ["tracestate", "dd=t.tid:XXXX"], @@ -542,8 +529,7 @@ def test_w3c_128_bit_propagation_tid_malformed_optional_tag(self, test_agent, te it is tagged with the expected value. """ with test_library: - make_single_request_and_get_inject_headers( - test_library, + test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-640cfd8d00000000abcdefab12345678-000000003ade68b1-01"], ["tracestate", "dd=t.tid:XXXX"], @@ -563,8 +549,8 @@ def test_w3c_128_bit_propagation_and_generation(self, test_agent, test_library): """Ensure that a new span from incoming headers does not modify the trace id when generation is true. """ with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, [["traceparent", "00-0000000000000000abcdefab12345678-000000003ade68b1-01",],], + headers = test_library.dd_make_child_span_and_get_headers( + [["traceparent", "00-0000000000000000abcdefab12345678-000000003ade68b1-01",],], ) span = find_only_span(test_agent.wait_for_num_traces(1)) trace_id = span.get("trace_id") @@ -587,7 +573,7 @@ def test_w3c_128_bit_generation_disabled(self, test_agent, test_library): headers, and populated in trace data. """ with test_library: - headers = make_single_request_and_get_inject_headers(test_library, []) + headers = test_library.dd_make_child_span_and_get_headers([]) span = find_only_span(test_agent.wait_for_num_traces(1)) fields = headers["traceparent"].split("-", 2) @@ -603,7 +589,7 @@ def test_w3c_128_bit_generation_enabled(self, test_agent, test_library): headers, and populated in trace data. """ with test_library: - headers = make_single_request_and_get_inject_headers(test_library, []) + headers = test_library.dd_make_child_span_and_get_headers([]) span = find_only_span(test_agent.wait_for_num_traces(1)) fields = headers["traceparent"].split("-", 2) diff --git a/tests/parametric/test_headers_b3.py b/tests/parametric/test_headers_b3.py index 8fb1f83676..4306193327 100644 --- a/tests/parametric/test_headers_b3.py +++ b/tests/parametric/test_headers_b3.py @@ -4,7 +4,6 @@ from utils.parametric.spec.trace import SAMPLING_PRIORITY_KEY, ORIGIN from utils.parametric.spec.trace import span_has_no_parent -from utils.parametric.headers import make_single_request_and_get_inject_headers from utils.parametric.spec.trace import find_only_span from utils import missing_feature, context, scenarios, features, bug from utils.tools import logger @@ -53,8 +52,8 @@ def test_headers_b3_extract_valid(self, test_agent, test_library): and activated properly. """ with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, [["b3", "000000000000000000000000075bcd15-000000003ade68b1-1"]] + test_library.dd_make_child_span_and_get_headers( + [["b3", "000000000000000000000000075bcd15-000000003ade68b1-1"]] ) span = find_only_span(test_agent.wait_for_num_traces(1)) @@ -70,7 +69,7 @@ def test_headers_b3_extract_invalid(self, test_agent, test_library): """Ensure that invalid b3 distributed tracing headers are not extracted. """ with test_library: - headers = make_single_request_and_get_inject_headers(test_library, [["b3", "0-0-1"]]) + test_library.dd_make_child_span_and_get_headers([["b3", "0-0-1"]]) span = find_only_span(test_agent.wait_for_num_traces(1)) assert span.get("trace_id") != 0 @@ -84,7 +83,7 @@ def test_headers_b3_inject_valid(self, test_agent, test_library): """Ensure that b3 distributed tracing headers are injected properly. """ with test_library: - headers = make_single_request_and_get_inject_headers(test_library, []) + headers = test_library.dd_make_child_span_and_get_headers([]) span = find_only_span(test_agent.wait_for_num_traces(1)) b3Arr = headers["b3"].split("-") @@ -107,8 +106,8 @@ def test_headers_b3_propagate_valid(self, test_agent, test_library): and injected properly. """ with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, [["b3", "000000000000000000000000075bcd15-000000003ade68b1-1"]] + headers = test_library.dd_make_child_span_and_get_headers( + [["b3", "000000000000000000000000075bcd15-000000003ade68b1-1"]] ) span = find_only_span(test_agent.wait_for_num_traces(1)) @@ -131,7 +130,7 @@ def test_headers_b3_propagate_invalid(self, test_agent, test_library): and the new span context is injected properly. """ with test_library: - headers = make_single_request_and_get_inject_headers(test_library, [["b3", "0-0-1"]]) + headers = test_library.dd_make_child_span_and_get_headers([["b3", "0-0-1"]]) span = find_only_span(test_agent.wait_for_num_traces(1)) assert span.get("trace_id") != 0 diff --git a/tests/parametric/test_headers_b3multi.py b/tests/parametric/test_headers_b3multi.py index 3fe39a8c3c..850c7d4165 100644 --- a/tests/parametric/test_headers_b3multi.py +++ b/tests/parametric/test_headers_b3multi.py @@ -4,7 +4,6 @@ from utils.parametric.spec.trace import SAMPLING_PRIORITY_KEY, ORIGIN from utils.parametric.spec.trace import span_has_no_parent -from utils.parametric.headers import make_single_request_and_get_inject_headers from utils.parametric.spec.trace import find_only_span from utils import missing_feature, irrelevant, context, scenarios, features, bug @@ -46,8 +45,7 @@ def test_headers_b3multi_extract_valid(self, test_agent, test_library): and activated properly. """ with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, + headers = test_library.dd_make_child_span_and_get_headers( [ ["x-b3-traceid", "000000000000000000000000075bcd15"], ["x-b3-spanid", "000000003ade68b1"], @@ -66,8 +64,8 @@ def test_headers_b3multi_extract_invalid(self, test_agent, test_library): """Ensure that invalid b3multi distributed tracing headers are not extracted. """ with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, [["x-b3-traceid", "0"], ["x-b3-spanid", "0"], ["x-b3-sampled", "1"],] + headers = test_library.dd_make_child_span_and_get_headers( + [["x-b3-traceid", "0"], ["x-b3-spanid", "0"], ["x-b3-sampled", "1"],] ) span = find_only_span(test_agent.wait_for_num_traces(1)) @@ -80,7 +78,7 @@ def test_headers_b3multi_inject_valid(self, test_agent, test_library): """Ensure that b3multi distributed tracing headers are injected properly. """ with test_library: - headers = make_single_request_and_get_inject_headers(test_library, []) + headers = test_library.dd_make_child_span_and_get_headers([]) span = find_only_span(test_agent.wait_for_num_traces(1)) b3_trace_id = headers["x-b3-traceid"] @@ -99,8 +97,7 @@ def test_headers_b3multi_propagate_valid(self, test_agent, test_library): and injected properly. """ with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, + headers = test_library.dd_make_child_span_and_get_headers( [ ["x-b3-traceid", "000000000000000000000000075bcd15"], ["x-b3-spanid", "000000003ade68b1"], @@ -126,8 +123,8 @@ def test_headers_b3multi_propagate_invalid(self, test_agent, test_library): and the new span context is injected properly. """ with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, [["x-b3-traceid", "0"], ["x-b3-spanid", "0"], ["x-b3-sampled", "1"],] + headers = test_library.dd_make_child_span_and_get_headers( + [["x-b3-traceid", "0"], ["x-b3-spanid", "0"], ["x-b3-sampled", "1"],] ) span = find_only_span(test_agent.wait_for_num_traces(1)) diff --git a/tests/parametric/test_headers_baggage.py b/tests/parametric/test_headers_baggage.py index e2bb3f3a76..238a41cf1d 100644 --- a/tests/parametric/test_headers_baggage.py +++ b/tests/parametric/test_headers_baggage.py @@ -3,13 +3,11 @@ from requests import head # type: ignore from utils.parametric.spec.trace import SAMPLING_PRIORITY_KEY, ORIGIN from utils.parametric.spec.trace import span_has_no_parent -from utils.parametric.headers import make_single_request_and_get_inject_headers from utils.parametric.spec.trace import find_only_span from utils import features, scenarios, bug, context from typing import Any import pytest from utils.parametric.spec.trace import SAMPLING_PRIORITY_KEY, ORIGIN -from utils.parametric.headers import make_single_request_and_get_inject_headers from utils.parametric.spec.trace import find_only_span parametrize = pytest.mark.parametrize @@ -35,8 +33,7 @@ class Test_Headers_Baggage: def test_headers_baggage_default_D001(self, test_agent, test_library): """Ensure baggage is enabled as a default setting and that it does not interfere with Datadog headers.""" with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, + headers = test_library.dd_make_child_span_and_get_headers( [["x-datadog-trace-id", "123456789"], ["x-datadog-parent-id", "987654321"], ["baggage", "foo=bar"],], ) @@ -50,8 +47,8 @@ def test_headers_baggage_default_D001(self, test_agent, test_library): def test_headers_baggage_only_D002(self, test_library): """Ensure that only baggage headers are injected when baggage is the only enabled propagation style.""" with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, [["x-datadog-trace-id", "123456789"], ["baggage", "foo=bar"]] + headers = test_library.dd_make_child_span_and_get_headers( + [["x-datadog-trace-id", "123456789"], ["baggage", "foo=bar"]] ) assert "x-datadog-trace-id" not in headers.keys() @@ -64,8 +61,7 @@ def test_headers_baggage_only_D002(self, test_library): def test_baggage_disable_settings_D003(self, test_agent, test_library): """Ensure that baggage headers are not injected when baggage is disabled and does not interfere with other headers.""" with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, + headers = test_library.dd_make_child_span_and_get_headers( [["x-datadog-trace-id", "123456789"], ["x-datadog-parent-id", "987654321"], ["baggage", "foo=bar"],], ) @@ -98,7 +94,7 @@ def test_baggage_inject_header_D004(self, test_library): def test_baggage_extract_header_D005(self, test_library): """testing baggage header extraction and decoding""" - with test_library.extract_headers_and_make_child_span( + with test_library.dd_extract_headers_and_make_child_span( "test_baggage_extract_header_D005", [ [ @@ -142,7 +138,7 @@ def test_baggage_set_disabled_D007(self, test_library): def test_baggage_get_D008(self, test_library): """testing baggage API get_baggage""" - with test_library.extract_headers_and_make_child_span( + with test_library.dd_extract_headers_and_make_child_span( "test_baggage_get_D008", [["baggage", "userId=Am%C3%A9lie,serverNode=DF%2028"]] ) as span: span.set_baggage("foo", "bar") @@ -154,7 +150,7 @@ def test_baggage_get_D008(self, test_library): def test_baggage_get_all_D009(self, test_library): """testing baggage API get_all_baggage""" - with test_library.extract_headers_and_make_child_span( + with test_library.dd_extract_headers_and_make_child_span( "test_baggage_get_all_D009", [["baggage", "foo=bar"]] ) as span: span.set_baggage("baz", "qux") @@ -186,8 +182,8 @@ def test_baggage_remove_all_D011(self, test_library): def test_baggage_malformed_headers_D012(self, test_library, test_agent): """Ensure that malformed baggage headers are handled properly. Unable to use get_baggage functions because it does not return anything""" with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, [["baggage", "no-equal-sign,foo=gets-dropped-because-previous-pair-is-malformed"]], + headers = test_library.dd_make_child_span_and_get_headers( + [["baggage", "no-equal-sign,foo=gets-dropped-because-previous-pair-is-malformed"]], ) assert "baggage" not in headers.keys() @@ -195,20 +191,20 @@ def test_baggage_malformed_headers_D012(self, test_library, test_agent): def test_baggage_malformed_headers_D013(self, test_library): """Ensure that malformed baggage headers are handled properly. Unable to use get_baggage functions because it does not return anything""" with test_library: - headers = make_single_request_and_get_inject_headers(test_library, [["baggage", "=no-key"]],) + headers = test_library.dd_make_child_span_and_get_headers([["baggage", "=no-key"]],) assert "baggage" not in headers.keys() def test_baggage_malformed_headers_D014(self, test_library): with test_library: - headers = make_single_request_and_get_inject_headers(test_library, [["baggage", "no-value="]],) + headers = test_library.dd_make_child_span_and_get_headers([["baggage", "no-value="]],) assert "baggage" not in headers.keys() def test_baggage_malformed_headers_D015(self, test_library): with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, [["baggage", "foo=gets-dropped-because-subsequent-pair-is-malformed,="]], + headers = test_library.dd_make_child_span_and_get_headers( + [["baggage", "foo=gets-dropped-because-subsequent-pair-is-malformed,="]], ) assert "baggage" not in headers.keys() diff --git a/tests/parametric/test_headers_datadog.py b/tests/parametric/test_headers_datadog.py index a425a01f3c..f0064608ea 100644 --- a/tests/parametric/test_headers_datadog.py +++ b/tests/parametric/test_headers_datadog.py @@ -1,6 +1,5 @@ from utils.parametric.spec.trace import SAMPLING_PRIORITY_KEY, ORIGIN from utils.parametric.spec.trace import span_has_no_parent -from utils.parametric.headers import make_single_request_and_get_inject_headers from utils.parametric.spec.trace import find_only_span from utils import features, scenarios, bug, context @@ -13,8 +12,7 @@ def test_distributed_headers_extract_datadog_D001(self, test_agent, test_library and activated properly. """ with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, + headers = test_library.dd_make_child_span_and_get_headers( [ ["x-datadog-trace-id", "123456789"], ["x-datadog-parent-id", "987654321"], @@ -37,8 +35,7 @@ def test_distributed_headers_extract_datadog_invalid_D002(self, test_agent, test """Ensure that invalid Datadog distributed tracing headers are not extracted. """ with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, + headers = test_library.dd_make_child_span_and_get_headers( [ ["x-datadog-trace-id", "0"], ["x-datadog-parent-id", "0"], @@ -59,7 +56,7 @@ def test_distributed_headers_inject_datadog_D003(self, test_agent, test_library) """Ensure that Datadog distributed tracing headers are injected properly. """ with test_library: - headers = make_single_request_and_get_inject_headers(test_library, []) + headers = test_library.dd_make_child_span_and_get_headers([]) span = find_only_span(test_agent.wait_for_num_traces(1)) assert int(headers["x-datadog-trace-id"]) == span.get("trace_id") @@ -71,8 +68,7 @@ def test_distributed_headers_propagate_datadog_D004(self, test_agent, test_libra and injected properly. """ with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, + headers = test_library.dd_make_child_span_and_get_headers( [ ["x-datadog-trace-id", "123456789"], ["x-datadog-parent-id", "987654321"], @@ -94,8 +90,7 @@ def test_distributed_headers_extractandinject_datadog_invalid_D005(self, test_ag and the new span context is injected properly. """ with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, + headers = test_library.dd_make_child_span_and_get_headers( [ ["x-datadog-trace-id", "0"], ["x-datadog-parent-id", "0"], diff --git a/tests/parametric/test_headers_none.py b/tests/parametric/test_headers_none.py index 8c34be497d..e61d6a1931 100644 --- a/tests/parametric/test_headers_none.py +++ b/tests/parametric/test_headers_none.py @@ -3,7 +3,6 @@ import pytest from utils.parametric.spec.trace import SAMPLING_PRIORITY_KEY, ORIGIN -from utils.parametric.headers import make_single_request_and_get_inject_headers from utils.parametric.spec.trace import find_only_span from utils import missing_feature, context, scenarios, features, bug @@ -41,8 +40,7 @@ def test_headers_none_extract(self, test_agent, test_library): """Ensure that no distributed tracing headers are extracted. """ with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, + test_library.dd_make_child_span_and_get_headers( [ ["x-datadog-trace-id", "123456789"], ["x-datadog-parent-id", "987654321"], @@ -66,8 +64,7 @@ def test_headers_none_extract_with_other_propagators(self, test_agent, test_libr and activated properly. """ with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, + test_library.dd_make_child_span_and_get_headers( [ ["x-datadog-trace-id", "123456789"], ["x-datadog-parent-id", "987654321"], @@ -90,7 +87,7 @@ def test_headers_none_inject(self, test_agent, test_library): no Datadog distributed tracing headers are injected. """ with test_library: - headers = make_single_request_and_get_inject_headers(test_library, []) + headers = test_library.dd_make_child_span_and_get_headers([]) assert "traceparent" not in headers assert "tracestate" not in headers @@ -106,7 +103,7 @@ def test_headers_none_inject_with_other_propagators(self, test_agent, test_libra In this case, ensure that the Datadog distributed tracing headers are injected properly. """ with test_library: - headers = make_single_request_and_get_inject_headers(test_library, []) + headers = test_library.dd_make_child_span_and_get_headers([]) span = find_only_span(test_agent.wait_for_num_traces(1)) assert int(headers["x-datadog-trace-id"]) == span.get("trace_id") @@ -119,8 +116,7 @@ def test_headers_none_propagate(self, test_agent, test_library): no Datadog distributed tracing headers are extracted or injected. """ with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, + headers = test_library.dd_make_child_span_and_get_headers( [ ["x-datadog-trace-id", "123456789"], ["x-datadog-parent-id", "987654321"], @@ -151,8 +147,7 @@ def test_headers_none_single_key_propagate(self, test_agent, test_library): no Datadog distributed tracing headers are extracted or injected. """ with test_library: - headers = make_single_request_and_get_inject_headers( - test_library, + headers = test_library.dd_make_child_span_and_get_headers( [ ["x-datadog-trace-id", "123456789"], ["x-datadog-parent-id", "987654321"], diff --git a/tests/parametric/test_headers_precedence.py b/tests/parametric/test_headers_precedence.py index 4e1b95307c..471c1ddda3 100644 --- a/tests/parametric/test_headers_precedence.py +++ b/tests/parametric/test_headers_precedence.py @@ -4,7 +4,6 @@ from utils.parametric.spec.tracecontext import get_tracecontext, TRACECONTEXT_FLAGS_SET from utils.parametric.spec.trace import retrieve_span_links, find_span_in_traces -from utils.parametric.headers import make_single_request_and_get_inject_headers from utils import bug, missing_feature, context, irrelevant, scenarios, features parametrize = pytest.mark.parametrize @@ -111,22 +110,20 @@ def test_headers_precedence_propagationstyle_legacy(self, test_agent, test_libra def test_headers_precedence_propagationstyle_datadog(self, test_agent, test_library): with test_library: # 1) No headers - headers1 = make_single_request_and_get_inject_headers(test_library, []) + headers1 = test_library.dd_make_child_span_and_get_headers([]) # 2) Only tracecontext headers - headers2 = make_single_request_and_get_inject_headers( - test_library, [["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"],] + headers2 = test_library.dd_make_child_span_and_get_headers( + [["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"],] ) # 3) Only tracecontext headers, includes existing tracestate - headers3 = make_single_request_and_get_inject_headers( - test_library, + headers3 = test_library.dd_make_child_span_and_get_headers( [["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"], ["tracestate", "foo=1"],], ) # 4) Both tracecontext and Datadog headers - headers4 = make_single_request_and_get_inject_headers( - test_library, + headers4 = test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"], ["tracestate", "foo=1"], @@ -137,8 +134,7 @@ def test_headers_precedence_propagationstyle_datadog(self, test_agent, test_libr ) # 5) Only Datadog headers - headers5 = make_single_request_and_get_inject_headers( - test_library, + headers5 = test_library.dd_make_child_span_and_get_headers( [ ["x-datadog-trace-id", "123456789"], ["x-datadog-parent-id", "987654321"], @@ -147,8 +143,7 @@ def test_headers_precedence_propagationstyle_datadog(self, test_agent, test_libr ) # 6) Invalid tracecontext, valid Datadog headers - headers6 = make_single_request_and_get_inject_headers( - test_library, + headers6 = test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-12345678901234567890123456789012-0000000000000000-01"], ["tracestate", "foo=1"], @@ -233,22 +228,20 @@ def test_headers_precedence_propagationstyle_default_tracecontext_datadog(self, def test_headers_precedence_propagationstyle_tracecontext_datadog(self, test_agent, test_library): with test_library: # 1) No headers - headers1 = make_single_request_and_get_inject_headers(test_library, []) + headers1 = test_library.dd_make_child_span_and_get_headers([]) # 2) Only tracecontext headers - headers2 = make_single_request_and_get_inject_headers( - test_library, [["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"],] + headers2 = test_library.dd_make_child_span_and_get_headers( + [["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"],] ) # 3) Only tracecontext headers, includes existing tracestate - headers3 = make_single_request_and_get_inject_headers( - test_library, + headers3 = test_library.dd_make_child_span_and_get_headers( [["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"], ["tracestate", "foo=1"],], ) # 4) Both tracecontext and Datadog headers - headers4 = make_single_request_and_get_inject_headers( - test_library, + headers4 = test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"], ["tracestate", "foo=1"], @@ -259,8 +252,7 @@ def test_headers_precedence_propagationstyle_tracecontext_datadog(self, test_age ) # 5) Only Datadog headers - headers5 = make_single_request_and_get_inject_headers( - test_library, + headers5 = test_library.dd_make_child_span_and_get_headers( [ ["x-datadog-trace-id", "123456789"], ["x-datadog-parent-id", "987654321"], @@ -269,8 +261,7 @@ def test_headers_precedence_propagationstyle_tracecontext_datadog(self, test_age ) # 6) Invalid tracecontext, valid Datadog headers - headers6 = make_single_request_and_get_inject_headers( - test_library, + headers6 = test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-12345678901234567890123456789012-0000000000000000-01"], ["tracestate", "foo=1"], @@ -374,22 +365,20 @@ def test_headers_precedence_propagationstyle_tracecontext_datadog(self, test_age def test_headers_precedence_propagationstyle_tracecontext(self, test_agent, test_library): with test_library: # 1) No headers - headers1 = make_single_request_and_get_inject_headers(test_library, []) + headers1 = test_library.dd_make_child_span_and_get_headers([]) # 2) Only tracecontext headers - headers2 = make_single_request_and_get_inject_headers( - test_library, [["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"],] + headers2 = test_library.dd_make_child_span_and_get_headers( + [["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"],] ) # 3) Only tracecontext headers, includes existing tracestate - headers3 = make_single_request_and_get_inject_headers( - test_library, + headers3 = test_library.dd_make_child_span_and_get_headers( [["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"], ["tracestate", "foo=1"],], ) # 4) Both tracecontext and Datadog headers - headers4 = make_single_request_and_get_inject_headers( - test_library, + headers4 = test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"], ["tracestate", "foo=1"], @@ -400,8 +389,7 @@ def test_headers_precedence_propagationstyle_tracecontext(self, test_agent, test ) # 5) Only Datadog headers - headers5 = make_single_request_and_get_inject_headers( - test_library, + headers5 = test_library.dd_make_child_span_and_get_headers( [ ["x-datadog-trace-id", "123456789"], ["x-datadog-parent-id", "987654321"], @@ -410,8 +398,7 @@ def test_headers_precedence_propagationstyle_tracecontext(self, test_agent, test ) # 6) Invalid tracecontext, valid Datadog headers - headers6 = make_single_request_and_get_inject_headers( - test_library, + headers6 = test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-12345678901234567890123456789012-0000000000000000-01"], ["tracestate", "foo=1"], @@ -505,22 +492,20 @@ def test_headers_precedence_propagationstyle_default_datadog_tracecontext(self, def test_headers_precedence_propagationstyle_datadog_tracecontext(self, test_agent, test_library): with test_library: # 1) No headers - headers1 = make_single_request_and_get_inject_headers(test_library, []) + headers1 = test_library.dd_make_child_span_and_get_headers([]) # 2) Only tracecontext headers - headers2 = make_single_request_and_get_inject_headers( - test_library, [["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"],] + headers2 = test_library.dd_make_child_span_and_get_headers( + [["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"],] ) # 3) Only tracecontext headers, includes existing tracestate - headers3 = make_single_request_and_get_inject_headers( - test_library, + headers3 = test_library.dd_make_child_span_and_get_headers( [["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"], ["tracestate", "foo=1"],], ) # 4) Both tracecontext and Datadog headers - headers4 = make_single_request_and_get_inject_headers( - test_library, + headers4 = test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"], ["tracestate", "foo=1"], @@ -531,8 +516,7 @@ def test_headers_precedence_propagationstyle_datadog_tracecontext(self, test_age ) # 5) Only Datadog headers - headers5 = make_single_request_and_get_inject_headers( - test_library, + headers5 = test_library.dd_make_child_span_and_get_headers( [ ["x-datadog-trace-id", "123456789"], ["x-datadog-parent-id", "987654321"], @@ -541,8 +525,7 @@ def test_headers_precedence_propagationstyle_datadog_tracecontext(self, test_age ) # 6) Invalid tracecontext, valid Datadog headers - headers6 = make_single_request_and_get_inject_headers( - test_library, + headers6 = test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-12345678901234567890123456789012-0000000000000000-01"], ["tracestate", "foo=1"], @@ -661,7 +644,7 @@ def test_headers_precedence_propagationstyle_resolves_conflicting_contexts(self, # 1) Datadog and tracecontext headers, Datadog is primary context, # trace-id does not match, # tracestate is present, so should be added to tracecontext span_link - with test_library.extract_headers_and_make_child_span( + with test_library.dd_extract_headers_and_make_child_span( name="span1", http_headers=[ ["traceparent", "00-11111111111111110000000000000001-000000003ade68b1-01"], @@ -675,7 +658,7 @@ def test_headers_precedence_propagationstyle_resolves_conflicting_contexts(self, pass # 2) Datadog and tracecontext headers, trace-id does match, Datadog is primary context # we want to make sure there's no span link since they match - with test_library.extract_headers_and_make_child_span( + with test_library.dd_extract_headers_and_make_child_span( name="span2", http_headers=[ ["traceparent", "00-11111111111111110000000000000001-000000003ade68b1-01"], @@ -690,7 +673,7 @@ def test_headers_precedence_propagationstyle_resolves_conflicting_contexts(self, # 3) Datadog, tracecontext, b3multi headers, Datadog is primary context # tracecontext and b3multi trace_id do match it # we should have two span links, b3multi should not have tracestate - with test_library.extract_headers_and_make_child_span( + with test_library.dd_extract_headers_and_make_child_span( name="span3", http_headers=[ ["traceparent", "00-11111111111111110000000000000001-000000003ade68b1-01"], @@ -707,7 +690,7 @@ def test_headers_precedence_propagationstyle_resolves_conflicting_contexts(self, pass # 4) Datadog, b3multi headers edge case where we want to make sure NOT to create a span_link # if the secondary context has trace_id 0 since that's not valid. - with test_library.extract_headers_and_make_child_span( + with test_library.dd_extract_headers_and_make_child_span( name="span4", http_headers=[ ["x-datadog-trace-id", "5"], @@ -722,7 +705,7 @@ def test_headers_precedence_propagationstyle_resolves_conflicting_contexts(self, pass # 5) Datadog, b3multi headers edge case where we want to make sure NOT to create a span_link # if the secondary context has span_id 0 since that's not valid. - with test_library.extract_headers_and_make_child_span( + with test_library.dd_extract_headers_and_make_child_span( name="span5", http_headers=[ ["x-datadog-trace-id", "6"], @@ -807,7 +790,7 @@ def test_headers_precedence_propagationstyle_resolves_conflicting_contexts_trace """ with test_library: # Trace ids with the three styles do not match - with test_library.extract_headers_and_make_child_span( + with test_library.dd_extract_headers_and_make_child_span( name="trace_ids_do_not_match", http_headers=[ ["traceparent", "00-11111111111111110000000000000002-000000003ade68b1-01"], @@ -858,7 +841,7 @@ def test_headers_precedence_propagationstyle_resolves_conflicting_contexts_spanl """ with test_library: # Trace ids with the three styles do not match - with test_library.extract_headers_and_make_child_span( + with test_library.dd_extract_headers_and_make_child_span( name="trace_ids_do_not_match", http_headers=[ ["traceparent", "00-11111111111111110000000000000002-000000003ade68b1-01"], @@ -902,7 +885,7 @@ def test_headers_precedence_propagationstyle_resolves_conflicting_contexts_spanl """ with test_library: # Trace ids with the three styles do not match - with test_library.extract_headers_and_make_child_span( + with test_library.dd_extract_headers_and_make_child_span( name="trace_ids_do_not_match", http_headers=[ ["traceparent", "00-11111111111111110000000000000002-000000003ade68b1-01"], @@ -985,8 +968,7 @@ def _test_headers_precedence_propagationstyle_includes_tracecontext_correctly_pr with test_library: # 1) Datadog and tracecontext headers, trace-id and span-id match, tracestate is present # Note: This is expected to be the most frequent case - headers1 = make_single_request_and_get_inject_headers( - test_library, + headers1 = test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-11111111111111110000000000000001-000000003ade68b1-01"], ["tracestate", "dd=s:2;t.tid:1111111111111111,foo=1"], @@ -998,8 +980,7 @@ def _test_headers_precedence_propagationstyle_includes_tracecontext_correctly_pr ) # 2) Scenario 1 but the x-datadog-* headers don't match the tracestate string # Note: This is an exceptional case that should not happen, but we should be consistent - headers2 = make_single_request_and_get_inject_headers( - test_library, + headers2 = test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-11111111111111110000000000000002-000000003ade68b1-01"], ["tracestate", "dd=s:1;t.tid:1111111111111111,foo=1"], @@ -1012,8 +993,7 @@ def _test_headers_precedence_propagationstyle_includes_tracecontext_correctly_pr # 3) Scenario 1 but there is no dd tracestate list-member # Note: This is an exceptional case that should not happen, but we should be consistent - headers3 = make_single_request_and_get_inject_headers( - test_library, + headers3 = test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-11111111111111110000000000000003-000000003ade68b1-01"], ["tracestate", "foo=1"], @@ -1026,8 +1006,7 @@ def _test_headers_precedence_propagationstyle_includes_tracecontext_correctly_pr # 4) Datadog and tracecontext headers, trace-id is the same but span-id is different, tracestate is present # Note: This happens when a W3C Proxy / Cloud Provider continues the W3C trace - headers4 = make_single_request_and_get_inject_headers( - test_library, + headers4 = test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-11111111111111110000000000000004-000000003ade68b1-01"], ["tracestate", "dd=s:2;t.tid:1111111111111111,foo=1"], @@ -1041,8 +1020,7 @@ def _test_headers_precedence_propagationstyle_includes_tracecontext_correctly_pr # 5) Datadog and tracecontext headers, trace-id is different, tracestate is present # Note: This happens when a W3C Proxy / Cloud Provider starts a new W3C trace, # which would happen if the incoming request only had x-datadog-* headers - headers5 = make_single_request_and_get_inject_headers( - test_library, + headers5 = test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-11111111111111110000000000000005-000000003ade68b1-01"], ["tracestate", "foo=1"], diff --git a/tests/parametric/test_headers_tracecontext.py b/tests/parametric/test_headers_tracecontext.py index d7b5dddd27..dc9d6df42a 100644 --- a/tests/parametric/test_headers_tracecontext.py +++ b/tests/parametric/test_headers_tracecontext.py @@ -13,7 +13,6 @@ from utils.parametric.spec.tracecontext import get_tracecontext from utils.parametric.spec.trace import find_span_in_traces, find_only_span -from utils.parametric.headers import make_single_request_and_get_inject_headers from utils import missing_feature, context, scenarios, features parametrize = pytest.mark.parametrize @@ -728,7 +727,7 @@ def test_tracestate_w3c_p_extract(self, test_agent, test_library): Ensure the last parent id tag is set according to the W3C Phase 2 spec """ with test_library: - with test_library.extract_headers_and_make_child_span( + with test_library.dd_extract_headers_and_make_child_span( "p_set", [ ["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"], @@ -737,7 +736,7 @@ def test_tracestate_w3c_p_extract(self, test_agent, test_library): ) as s1: pass - with test_library.extract_headers_and_make_child_span( + with test_library.dd_extract_headers_and_make_child_span( "p_invalid", [ ["traceparent", "00-12345678901234567890123456789013-1234567890123457-01"], @@ -798,7 +797,7 @@ def test_tracestate_w3c_p_extract_datadog_w3c(self, test_agent, test_library): """ with test_library: # 1) Trace ids and parent ids in datadog and tracecontext headers match - with test_library.extract_headers_and_make_child_span( + with test_library.dd_extract_headers_and_make_child_span( "identical_trace_info", [ ["traceparent", "00-11111111111111110000000000000001-000000003ade68b1-01"], @@ -811,7 +810,7 @@ def test_tracestate_w3c_p_extract_datadog_w3c(self, test_agent, test_library): pass # 2) Trace ids in datadog and tracecontext headers do not match - with test_library.extract_headers_and_make_child_span( + with test_library.dd_extract_headers_and_make_child_span( "trace_ids_do_not_match", [ ["traceparent", "00-11111111111111110000000000000002-000000003ade68b1-01"], @@ -824,7 +823,7 @@ def test_tracestate_w3c_p_extract_datadog_w3c(self, test_agent, test_library): pass # 3) Parent ids in Datadog and tracecontext headers do not match - with test_library.extract_headers_and_make_child_span( + with test_library.dd_extract_headers_and_make_child_span( "same_trace_non_matching_parent_ids", [ ["traceparent", "00-11111111111111110000000000000003-000000003ade68b1-01"], @@ -837,7 +836,7 @@ def test_tracestate_w3c_p_extract_datadog_w3c(self, test_agent, test_library): pass # 4) Parent ids do not match and p value is not present in tracestate - with test_library.extract_headers_and_make_child_span( + with test_library.dd_extract_headers_and_make_child_span( "non_matching_span_missing_p_value", [ ["traceparent", "00-00000000000000000000000000000004-000000003ade68b1-01"], @@ -848,7 +847,7 @@ def test_tracestate_w3c_p_extract_datadog_w3c(self, test_agent, test_library): ) as s4: pass - with test_library.extract_headers_and_make_child_span( + with test_library.dd_extract_headers_and_make_child_span( "non_matching_span_non_matching_p_value", [ ["traceparent", "00-00000000000000000000000000000005-000000003ade68b1-01"], @@ -914,7 +913,7 @@ def test_tracestate_w3c_p_phase_3_extract_first(self, test_agent, test_library): """ # 1) Datadog and tracecontext headers, parent ids do not match - with test_library.extract_headers_and_make_child_span( + with test_library.dd_extract_headers_and_make_child_span( "same_trace_different_parent_ids", [ ["traceparent", "00-11111111111111110000000000000001-000000000000000f-01"], @@ -941,7 +940,7 @@ def test_tracestate_w3c_context_leak(self, test_agent, test_library): Ensure high order bits do not leak between traces """ with test_library: - with test_library.extract_headers_and_make_child_span( + with test_library.dd_extract_headers_and_make_child_span( "high_order_64_bits_set", [ ["traceparent", "00-33333333333333330000000000000003-000000003ade68b1-01"], @@ -953,7 +952,7 @@ def test_tracestate_w3c_context_leak(self, test_agent, test_library): ) as s1: pass - with test_library.extract_headers_and_make_child_span( + with test_library.dd_extract_headers_and_make_child_span( "high_order_64_bits_unset", [ ["traceparent", "00-00000000000000000000000000000004-000000003ade68b1-01"], @@ -1119,4 +1118,4 @@ def test_tracestate_ows_handling(self, test_agent, test_library): def make_single_request_and_get_tracecontext(test_library, headers_list): - return get_tracecontext(make_single_request_and_get_inject_headers(test_library, headers_list)) + return get_tracecontext(test_library.dd_make_child_span_and_get_headers(headers_list)) diff --git a/tests/parametric/test_headers_tracestate_dd.py b/tests/parametric/test_headers_tracestate_dd.py index 1ce71541a2..96c3d43125 100644 --- a/tests/parametric/test_headers_tracestate_dd.py +++ b/tests/parametric/test_headers_tracestate_dd.py @@ -3,7 +3,6 @@ import pytest from utils.parametric.spec.tracecontext import get_tracecontext -from utils.parametric.headers import make_single_request_and_get_inject_headers from utils import bug, missing_feature, context, scenarios, features parametrize = pytest.mark.parametrize @@ -29,8 +28,7 @@ def test_headers_tracestate_dd_propagate_samplingpriority(self, test_agent, test """ with test_library: # 1) x-datadog-sampling-priority > 0 - headers1 = make_single_request_and_get_inject_headers( - test_library, + headers1 = test_library.dd_make_child_span_and_get_headers( [ ["x-datadog-trace-id", "7890123456789012"], ["x-datadog-parent-id", "1234567890123456"], @@ -39,8 +37,7 @@ def test_headers_tracestate_dd_propagate_samplingpriority(self, test_agent, test ) # 2) x-datadog-sampling-priority <= 0 - headers2 = make_single_request_and_get_inject_headers( - test_library, + headers2 = test_library.dd_make_child_span_and_get_headers( [ ["x-datadog-trace-id", "7890123456789012"], ["x-datadog-parent-id", "1234567890123456"], @@ -49,13 +46,12 @@ def test_headers_tracestate_dd_propagate_samplingpriority(self, test_agent, test ) # 3) Sampled = 1, tracestate[dd][s] is not present - headers3 = make_single_request_and_get_inject_headers( - test_library, [["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"],] + headers3 = test_library.dd_make_child_span_and_get_headers( + [["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"],] ) # 4) Sampled = 1, tracestate[dd][s] <= 0 - headers4 = make_single_request_and_get_inject_headers( - test_library, + headers4 = test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"], ["tracestate", "foo=1,dd=s:-1"], @@ -63,8 +59,7 @@ def test_headers_tracestate_dd_propagate_samplingpriority(self, test_agent, test ) # 5) Sampled = 1, tracestate[dd][s] > 0 - headers5 = make_single_request_and_get_inject_headers( - test_library, + headers5 = test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"], ["tracestate", "foo=1,dd=s:2"], @@ -72,13 +67,12 @@ def test_headers_tracestate_dd_propagate_samplingpriority(self, test_agent, test ) # 6) Sampled = 0, tracestate[dd][s] is not present - headers6 = make_single_request_and_get_inject_headers( - test_library, [["traceparent", "00-12345678901234567890123456789012-1234567890123456-00"],] + headers6 = test_library.dd_make_child_span_and_get_headers( + [["traceparent", "00-12345678901234567890123456789012-1234567890123456-00"],] ) # 7) Sampled = 0, tracestate[dd][s] <= 0 - headers7 = make_single_request_and_get_inject_headers( - test_library, + headers7 = test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-12345678901234567890123456789012-1234567890123456-00"], ["tracestate", "foo=1,dd=s:-1"], @@ -86,8 +80,7 @@ def test_headers_tracestate_dd_propagate_samplingpriority(self, test_agent, test ) # 8) Sampled = 0, tracestate[dd][s] > 0 - headers8 = make_single_request_and_get_inject_headers( - test_library, + headers8 = test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-12345678901234567890123456789012-1234567890123456-00"], ["tracestate", "foo=1,dd=s:1"], @@ -200,8 +193,7 @@ def test_headers_tracestate_dd_propagate_origin(self, test_agent, test_library): """ with test_library: # 1) x-datadog-origin is a well-known value - headers1 = make_single_request_and_get_inject_headers( - test_library, + headers1 = test_library.dd_make_child_span_and_get_headers( [ ["x-datadog-trace-id", "7890123456789012"], ["x-datadog-parent-id", "1234567890123456"], @@ -210,8 +202,7 @@ def test_headers_tracestate_dd_propagate_origin(self, test_agent, test_library): ) # 2) x-datadog-origin is NOT a well-known value - headers2 = make_single_request_and_get_inject_headers( - test_library, + headers2 = test_library.dd_make_child_span_and_get_headers( [ ["x-datadog-trace-id", "7890123456789012"], ["x-datadog-parent-id", "1234567890123456"], @@ -220,8 +211,7 @@ def test_headers_tracestate_dd_propagate_origin(self, test_agent, test_library): ) # 3) x-datadog-origin has invalid characters - headers3 = make_single_request_and_get_inject_headers( - test_library, + headers3 = test_library.dd_make_child_span_and_get_headers( [ ["x-datadog-trace-id", "7890123456789012"], ["x-datadog-parent-id", "1234567890123456"], @@ -230,8 +220,7 @@ def test_headers_tracestate_dd_propagate_origin(self, test_agent, test_library): ) # 4) tracestate[dd][o] is not present - headers4 = make_single_request_and_get_inject_headers( - test_library, + headers4 = test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"], ["tracestate", "foo=1,dd=s:-1"], @@ -239,8 +228,7 @@ def test_headers_tracestate_dd_propagate_origin(self, test_agent, test_library): ) # 5) tracestate[dd][o] is present and is a well-known value - headers5 = make_single_request_and_get_inject_headers( - test_library, + headers5 = test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"], ["tracestate", "foo=1,dd=s:-1;o:synthetics-browser"], @@ -248,8 +236,7 @@ def test_headers_tracestate_dd_propagate_origin(self, test_agent, test_library): ) # 6) tracestate[dd][o] is present and is NOT a well-known value - headers6 = make_single_request_and_get_inject_headers( - test_library, + headers6 = test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"], ["tracestate", "foo=1,dd=s:-1;o:tracing2.0"], @@ -339,8 +326,7 @@ def test_headers_tracestate_dd_propagate_propagatedtags(self, test_agent, test_l """ with test_library: # 1) x-datadog-tags is populated with well-known tags - headers1 = make_single_request_and_get_inject_headers( - test_library, + headers1 = test_library.dd_make_child_span_and_get_headers( [ ["x-datadog-trace-id", "7890123456789012"], ["x-datadog-parent-id", "1234567890123456"], @@ -350,8 +336,7 @@ def test_headers_tracestate_dd_propagate_propagatedtags(self, test_agent, test_l # 2) x-datadog-tags is populated with well-known tags that require # substituting "=" characters with ":" characters - headers2 = make_single_request_and_get_inject_headers( - test_library, + headers2 = test_library.dd_make_child_span_and_get_headers( [ ["x-datadog-trace-id", "7890123456789012"], ["x-datadog-parent-id", "1234567890123456"], @@ -360,8 +345,7 @@ def test_headers_tracestate_dd_propagate_propagatedtags(self, test_agent, test_l ) # 3) x-datadog-tags is populated with both well-known tags and unrecognized tags - headers3 = make_single_request_and_get_inject_headers( - test_library, + headers3 = test_library.dd_make_child_span_and_get_headers( [ ["x-datadog-trace-id", "7890123456789012"], ["x-datadog-parent-id", "1234567890123456"], @@ -370,8 +354,7 @@ def test_headers_tracestate_dd_propagate_propagatedtags(self, test_agent, test_l ) # 4) tracestate[dd] does not contain propagated tags - headers4 = make_single_request_and_get_inject_headers( - test_library, + headers4 = test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"], ["tracestate", "foo=1,dd=s:-1"], @@ -455,8 +438,7 @@ def test_headers_tracestate_dd_propagate_propagatedtags_change_sampling_same_dm( """ with test_library: # 1) tracestate[dd] is populated with well-known propagated tags - headers1 = make_single_request_and_get_inject_headers( - test_library, + headers1 = test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"], ["tracestate", "foo=1,dd=s:0;t.dm:-0;t.usr.id:baz64~~"], @@ -464,8 +446,7 @@ def test_headers_tracestate_dd_propagate_propagatedtags_change_sampling_same_dm( ) # 2) tracestate[dd][o] is populated with both well-known tags and unrecognized propagated tags - headers2 = make_single_request_and_get_inject_headers( - test_library, + headers2 = test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-12345678901234567890123456789012-1234567890123456-00"], ["tracestate", "foo=1,dd=s:1;t.dm:-0;t.usr.id:baz64~~;t.url:http://localhost"], @@ -522,8 +503,7 @@ def test_headers_tracestate_dd_propagate_propagatedtags_change_sampling_reset_dm """ with test_library: # 1) tracestate[dd] is populated with well-known propagated tags - headers1 = make_single_request_and_get_inject_headers( - test_library, + headers1 = test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"], ["tracestate", "foo=1,dd=s:-1;t.dm:-4;t.usr.id:baz64~~"], @@ -531,8 +511,7 @@ def test_headers_tracestate_dd_propagate_propagatedtags_change_sampling_reset_dm ) # 2) tracestate[dd][o] is populated with both well-known tags and unrecognized propagated tags - headers2 = make_single_request_and_get_inject_headers( - test_library, + headers2 = test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-12345678901234567890123456789012-1234567890123456-00"], ["tracestate", "foo=1,dd=s:2;t.dm:-4;t.usr.id:baz64~~;t.url:http://localhost"], @@ -590,8 +569,7 @@ def test_headers_tracestate_dd_keeps_32_or_fewer_list_members(self, test_agent, other_vendors = ",".join("key%d=value%d" % (i, i) for i in range(1, 32)) # 1) Input: 32 list-members with 'dd' at the end of the tracestate string - headers1 = make_single_request_and_get_inject_headers( - test_library, + headers1 = test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"], ["tracestate", other_vendors + ",dd=s:-1"], @@ -599,8 +577,7 @@ def test_headers_tracestate_dd_keeps_32_or_fewer_list_members(self, test_agent, ) # 2) Input: 32 list-members with 'dd' at the beginning of the tracestate string - headers2 = make_single_request_and_get_inject_headers( - test_library, + headers2 = test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"], ["tracestate", "dd=s:-1," + other_vendors], @@ -608,8 +585,7 @@ def test_headers_tracestate_dd_keeps_32_or_fewer_list_members(self, test_agent, ) # 3) Input: 31 list-members without 'dd' in the tracestate string - headers3 = make_single_request_and_get_inject_headers( - test_library, + headers3 = test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"], ["tracestate", other_vendors], @@ -617,8 +593,8 @@ def test_headers_tracestate_dd_keeps_32_or_fewer_list_members(self, test_agent, ) # 4) Input: No tracestate string - headers4 = make_single_request_and_get_inject_headers( - test_library, [["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"],], + headers4 = test_library.dd_make_child_span_and_get_headers( + [["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"],], ) # 1) Input: 32 list-members with 'dd' at the end of the tracestate string @@ -668,8 +644,7 @@ def test_headers_tracestate_dd_evicts_32_or_greater_list_members(self, test_agen other_vendors = ",".join("key%d=value%d" % (i, i) for i in range(1, 32)) # 1) Input: 32 list-members without 'dd' in the tracestate string - headers1 = make_single_request_and_get_inject_headers( - test_library, + headers1 = test_library.dd_make_child_span_and_get_headers( [ ["traceparent", "00-12345678901234567890123456789012-1234567890123456-01"], ["tracestate", other_vendors + ",key32=value32"], diff --git a/tests/parametric/test_otel_api_interoperability.py b/tests/parametric/test_otel_api_interoperability.py index 52000b7008..006d7c1c2b 100644 --- a/tests/parametric/test_otel_api_interoperability.py +++ b/tests/parametric/test_otel_api_interoperability.py @@ -381,7 +381,7 @@ def test_distributed_headers_are_propagated_tracecontext(self, test_agent, test_ ] with test_library: - with test_library.extract_headers_and_make_child_span("dd_span", headers): + with test_library.dd_extract_headers_and_make_child_span("dd_span", headers): otel_span = test_library.otel_current_span() otel_context = otel_span.span_context() @@ -410,7 +410,7 @@ def test_distributed_headers_are_propagated_datadog(self, test_agent, test_libra ] with test_library: - with test_library.extract_headers_and_make_child_span("dd_span", headers): + with test_library.dd_extract_headers_and_make_child_span("dd_span", headers): otel_span = test_library.otel_current_span() otel_context = otel_span.span_context() otel_trace_state = otel_context.get("trace_state") diff --git a/utils/parametric/_library_client.py b/utils/parametric/_library_client.py index 3d2fdebd7e..9da553df46 100644 --- a/utils/parametric/_library_client.py +++ b/utils/parametric/_library_client.py @@ -439,10 +439,15 @@ def dd_start_span( yield span span.finish() - def extract_headers_and_make_child_span(self, name, http_headers): + def dd_extract_headers_and_make_child_span(self, name, http_headers): parent_id = self.dd_extract_headers(http_headers=http_headers) return self.dd_start_span(name=name, parent_id=parent_id,) + def dd_make_child_span_and_get_headers(self, headers): + with self.dd_extract_headers_and_make_child_span("name", headers) as span: + headers = self.dd_inject_headers(span.span_id) + return {k.lower(): v for k, v in headers} + @contextlib.contextmanager def otel_start_span( self, diff --git a/utils/parametric/headers.py b/utils/parametric/headers.py deleted file mode 100644 index dd20fc5d2b..0000000000 --- a/utils/parametric/headers.py +++ /dev/null @@ -1,4 +0,0 @@ -def make_single_request_and_get_inject_headers(test_library, headers): - with test_library.extract_headers_and_make_child_span("name", headers) as span: - headers = test_library.dd_inject_headers(span.span_id) - return {k.lower(): v for k, v in headers}