Skip to content

Commit

Permalink
parametric: move make_single_request_and_get_inject_headers to APMLib…
Browse files Browse the repository at this point in the history
…rary (#3512)
  • Loading branch information
mabdinur authored Nov 22, 2024
1 parent 833f54c commit 9c26730
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 238 deletions.
76 changes: 31 additions & 45 deletions tests/parametric/test_128_bit_traceids.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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"],
Expand All @@ -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"],
Expand All @@ -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"],
Expand All @@ -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"],
Expand Down Expand Up @@ -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"],
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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")
Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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))
Expand All @@ -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")
Expand All @@ -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"))
Expand All @@ -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"))
Expand All @@ -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")
Expand All @@ -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"],
Expand Down Expand Up @@ -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"],
Expand All @@ -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"],
Expand All @@ -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"],
Expand All @@ -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"],
Expand All @@ -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")
Expand All @@ -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)

Expand All @@ -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)

Expand Down
15 changes: 7 additions & 8 deletions tests/parametric/test_headers_b3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand All @@ -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("-")
Expand All @@ -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))
Expand All @@ -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
Expand Down
Loading

0 comments on commit 9c26730

Please sign in to comment.