8000 fix: Allow nested spans to override sampled argument (#708) · lmasikl/sentry-python@8326668 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8326668

Browse files
authored
fix: Allow nested spans to override sampled argument (getsentry#708)
1 parent d4a25dc commit 8326668

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

sentry_sdk/tracing.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,9 @@ def __exit__(self, ty, value, tb):
196196

197197
def new_span(self, **kwargs):
198198
# type: (**Any) -> Span
199+
kwargs.setdefault("sampled", self.sampled)
199200
rv = type(self)(
200-
trace_id=self.trace_id,
201-
span_id=None,
202-
parent_span_id=self.span_id,
203-
sampled=self.sampled,
204-
**kwargs
201+
trace_id=self.trace_id, span_id=None, parent_span_id=self.span_id, **kwargs
205202
)
206203

207204
rv._span_recorder = self._span_recorder

tests/test_tracing.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,10 @@ def test_span_trimming(sentry_init, capture_events):
148148
span1, span2 = event["spans"]
149149
assert span1["op"] == "foo0"
150150
assert span2["op"] == "foo1"
151+
152+
153+
def test_nested_span_sampling_override():
154+
with Hub.current.start_span(transaction="outer", sampled=True) as span:
155+
assert span.sampled is True
156+
with Hub.current.start_span(transaction="inner", sampled=False) as span:
157+
assert span.sampled is False

0 commit comments

Comments
 (0)
0