Skip to content

Commit 53da6a7

Browse files
committed
test(tracing): enhance W3C traceparent tests with sampling flag assertions
1 parent dc9b392 commit 53da6a7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/tracing/test_http_headers.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,27 @@ def test_to_traceparent(sampled):
2929
assert parts[2] == "1" if sampled is True else "0" # sampled
3030

3131

32+
@pytest.mark.parametrize("sampled", [True, False, None])
33+
def test_to_w3c_traceparent(sampled):
34+
transaction = Transaction(
35+
name="/interactions/other-dogs/new-dog",
36+
op="greeting.sniff",
37+
trace_id="4a77088e323f137c4d96381f35b92cf6",
38+
sampled=sampled,
39+
)
40+
41+
traceparent = transaction.to_w3c_traceparent()
42+
43+
parts = traceparent.split("-")
44+
assert parts[0] == "00" # version
45+
assert parts[1] == "4a77088e323f137c4d96381f35b92cf6" # trace_id
46+
assert parts[2] == transaction.span_id # parent_span_id
47+
if sampled is not True:
48+
assert parts[3] == "00" # trace-flags
49+
else:
50+
assert parts[3] == "01" # trace-flags
51+
52+
3253
@pytest.mark.parametrize("sampling_decision", [True, False])
3354
def test_sentrytrace_extraction(sampling_decision):
3455
sentrytrace_header = "12312012123120121231201212312012-0415201309082013-{}".format(

0 commit comments

Comments
 (0)