Skip to content
This repository was archived by the owner on Aug 13, 2025. It is now read-only.

Commit a34c130

Browse files
authored
Default w3c sampled flag to 01 (#152)
Receiving OTEL instrumentation ignores spans coming with the 00 sampled flag. This is a stop-gap measure to ensure w3c parser hooks work with an OTEL receiver. Ideally, we would like to set the sampled flag based on an actual sampler, but that requires further investigation.
1 parent 2ab8dea commit a34c130

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

beeline/propagation/test_w3c.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import beeline.propagation.w3c as w3c
55

66
_TEST_TRACEPARENT_HEADER = "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-00"
7+
_TEST_TRACEPARENT_HEADER_DEFAULT_TRACEFLAGS = "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01"
78
_TEST_TRACESTATE_HEADER = "foo=bar,bar=baz"
89

910
_TEST_HEADERS = {
@@ -73,3 +74,12 @@ def test_generates_correct_headers(self):
7374
_TEST_TRACEPARENT_HEADER)
7475
self.assertEqual(headers['tracestate'],
7576
_TEST_TRACESTATE_HEADER)
77+
78+
def test_defaults_trace_flags_to_sampled(self):
79+
pc = PropagationContext(
80+
_TEST_TRACE_ID, _TEST_PARENT_ID
81+
)
82+
headers = w3c.http_trace_propagation_hook(pc)
83+
self.assertIn('traceparent', headers)
84+
self.assertEqual(headers['traceparent'],
85+
_TEST_TRACEPARENT_HEADER_DEFAULT_TRACEFLAGS)

beeline/propagation/w3c.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def marshal_traceparent(propagation_context):
7070

7171
trace_flags = propagation_context.trace_fields.get('traceflags')
7272
if not trace_flags:
73-
trace_flags = "00"
73+
trace_flags = "01"
7474

7575
traceparent_header = "00-{}-{}-{}".format(
7676
propagation_context.trace_id,

0 commit comments

Comments
 (0)