Skip to content

Commit 2a54a93

Browse files
SDK: set sampled flag on sampling trace (#407)
1 parent fe99dbc commit 2a54a93

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

Diff for: opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,8 @@ def start_span( # pylint: disable=too-many-locals
509509
)
510510

511511
if sampling_decision.sampled:
512+
options = context.trace_options | trace_api.TraceOptions.SAMPLED
513+
context.trace_options = trace_api.TraceOptions(options)
512514
if attributes is None:
513515
span_attributes = sampling_decision.attributes
514516
else:

Diff for: opentelemetry-sdk/tests/trace/test_trace.py

+4
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def test_default_sampler(self):
117117
self.assertIsInstance(root_span, trace.Span)
118118
child_span = tracer.start_span(name="child span", parent=root_span)
119119
self.assertIsInstance(child_span, trace.Span)
120+
self.assertTrue(root_span.context.trace_options.sampled)
120121

121122
def test_sampler_no_sampling(self):
122123
tracer_source = trace.TracerSource(sampling.ALWAYS_OFF)
@@ -251,6 +252,9 @@ def test_start_span_explicit(self):
251252
other_parent = trace_api.SpanContext(
252253
trace_id=0x000000000000000000000000DEADBEEF,
253254
span_id=0x00000000DEADBEF0,
255+
trace_options=trace_api.TraceOptions(
256+
trace_api.TraceOptions.SAMPLED
257+
),
254258
)
255259

256260
self.assertIsNone(tracer.get_current_span())

0 commit comments

Comments
 (0)