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

Commit 61c053a

Browse files
authored
Make NullContextManager support nested spans (#156)
1 parent 635599e commit 61c053a

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

opencensus/trace/tracers/base.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ def __init__(self, span_id=None):
7272
self.span_id = span_id
7373

7474
def __enter__(self):
75-
pass # pragma: NO COVER
75+
return self # pragma: NO COVER
7676

7777
def __exit__(self, exc_type, exc_value, traceback):
7878
pass # pragma: NO COVER
79+
80+
def span(self, name='span'):
81+
return NullContextManager()

tests/unit/trace/test_tracer.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,12 @@ def test_span_not_sampled(self):
141141
tracer = tracer_module.Tracer(sampler=sampler)
142142

143143
span = tracer.span()
144+
145+
# Test nested span not sampled
146+
child_span = span.span()
147+
144148
assert isinstance(span, base.NullContextManager)
149+
assert isinstance(child_span, base.NullContextManager)
145150

146151
def test_span_sampled(self):
147152
sampler = mock.Mock()

0 commit comments

Comments
 (0)