Skip to content

Commit ad1cde3

Browse files
committed
refactor: Use bitmask to check if W3C trace-flags have the "sampled" bit set
1 parent b944656 commit ad1cde3

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

sentry_sdk/tracing_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"[0-9]{2}?" # version
5454
"-?([0-9a-f]{32})?" # trace_id
5555
"-?([0-9a-f]{16})?" # span_id
56-
"-?([01]{2})?" # trace-flags
56+
"-?([0-9]{2})?" # trace-flags
5757
"[ \t]*$" # whitespace
5858
)
5959

@@ -369,7 +369,8 @@ def extract_w3c_traceparent_data(header):
369369
if parent_span_id:
370370
parent_span_id = "{:016x}".format(int(parent_span_id, 16))
371371
if trace_flags:
372-
parent_sampled = trace_flags == "01"
372+
trace_flags_byte = int(trace_flags, 16)
373+
parent_sampled = (trace_flags_byte & 0x01) == 1
373374

374375
return {
375376
"trace_id": trace_id,

0 commit comments

Comments
 (0)