Skip to content

Commit

Permalink
fix: Allow nested spans to override sampled argument (#708)
Browse files Browse the repository at this point in the history
  • Loading branch information
beezz authored May 27, 2020
1 parent d4a25dc commit 8326668
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 2 additions & 5 deletions sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,9 @@ def __exit__(self, ty, value, tb):

def new_span(self, **kwargs):
# type: (**Any) -> Span
kwargs.setdefault("sampled", self.sampled)
rv = type(self)(
trace_id=self.trace_id,
span_id=None,
parent_span_id=self.span_id,
sampled=self.sampled,
**kwargs
trace_id=self.trace_id, span_id=None, parent_span_id=self.span_id, **kwargs
)

rv._span_recorder = self._span_recorder
Expand Down
7 changes: 7 additions & 0 deletions tests/test_tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,10 @@ def test_span_trimming(sentry_init, capture_events):
span1, span2 = event["spans"]
assert span1["op"] == "foo0"
assert span2["op"] == "foo1"


def test_nested_span_sampling_override():
with Hub.current.start_span(transaction="outer", sampled=True) as span:
assert span.sampled is True
with Hub.current.start_span(transaction="inner", sampled=False) as span:
assert span.sampled is False

0 comments on commit 8326668

Please sign in to comment.