Skip to content

Commit

Permalink
SDK: set sampled flag on sampling trace (open-telemetry#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
mauriciovasquezbernal authored and toumorokoshi committed Feb 17, 2020
1 parent e4ccc2f commit 55cd59b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,8 @@ def start_span( # pylint: disable=too-many-locals
)

if sampling_decision.sampled:
options = context.trace_options | trace_api.TraceOptions.SAMPLED
context.trace_options = trace_api.TraceOptions(options)
if attributes is None:
span_attributes = sampling_decision.attributes
else:
Expand Down
4 changes: 4 additions & 0 deletions opentelemetry-sdk/tests/trace/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def test_default_sampler(self):
self.assertIsInstance(root_span, trace.Span)
child_span = tracer.start_span(name="child span", parent=root_span)
self.assertIsInstance(child_span, trace.Span)
self.assertTrue(root_span.context.trace_options.sampled)

def test_sampler_no_sampling(self):
tracer_source = trace.TracerSource(sampling.ALWAYS_OFF)
Expand Down Expand Up @@ -251,6 +252,9 @@ def test_start_span_explicit(self):
other_parent = trace_api.SpanContext(
trace_id=0x000000000000000000000000DEADBEEF,
span_id=0x00000000DEADBEF0,
trace_options=trace_api.TraceOptions(
trace_api.TraceOptions.SAMPLED
),
)

self.assertIsNone(tracer.get_current_span())
Expand Down

0 comments on commit 55cd59b

Please sign in to comment.