Skip to content

Commit

Permalink
Disable the sampled trace flag when a span is not sampled
Browse files Browse the repository at this point in the history
  • Loading branch information
David Grochowski committed Aug 27, 2020
1 parent e21ee21 commit 029fde5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 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 @@ -831,6 +831,8 @@ def start_span( # pylint: disable=too-many-locals
)
span.start(start_time=start_time)
else:
options = context.trace_flags & ~trace_api.TraceFlags.SAMPLED
context.trace_flags = trace_api.TraceFlags(options)
span = trace_api.DefaultSpan(context=context)
return span

Expand Down
6 changes: 4 additions & 2 deletions opentelemetry-sdk/tests/trace/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,20 @@ 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_flags.sampled)
self.assertTrue(root_span.get_context().trace_flags.sampled)

def test_sampler_no_sampling(self):
tracer_provider = trace.TracerProvider(sampling.ALWAYS_OFF)
tracer = tracer_provider.get_tracer(__name__)

# Check that the default tracer creates no-op spans if the sampler
# decides not to sampler
# decides not to sample
root_span = tracer.start_span(name="root span", parent=None)
self.assertIsInstance(root_span, trace_api.DefaultSpan)
self.assertFalse(root_span.get_context().trace_flags.sampled)
child_span = tracer.start_span(name="child span", parent=root_span)
self.assertIsInstance(child_span, trace_api.DefaultSpan)
self.assertFalse(child_span.get_context().trace_flags.sampled)


class TestSpanCreation(unittest.TestCase):
Expand Down

0 comments on commit 029fde5

Please sign in to comment.