Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable the sampled trace flag when a span is not sampled #1046

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -788,6 +788,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