Skip to content

Commit 8787ee4

Browse files
authored
fix(tracing): Do not attach stacktrace to transaction (#4713)
The `attach_stacktrace` option was attaching stack traces to transactions. This is an expensive operation but the results aren't used anywhere.
1 parent e012ff1 commit 8787ee4

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

sentry_sdk/client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,9 @@ def _prepare_event(
516516
if event.get("timestamp") is None:
517517
event["timestamp"] = datetime.now(timezone.utc)
518518

519+
is_transaction = event.get("type") == "transaction"
520+
519521
if scope is not None:
520-
is_transaction = event.get("type") == "transaction"
521522
spans_before = len(cast(List[Dict[str, object]], event.get("spans", [])))
522523
event_ = scope.apply_to_event(event, hint, self.options)
523524

@@ -560,7 +561,8 @@ def _prepare_event(
560561
)
561562

562563
if (
563-
self.options["attach_stacktrace"]
564+
not is_transaction
565+
and self.options["attach_stacktrace"]
564566
and "exception" not in event
565567
and "stacktrace" not in event
566568
and "threads" not in event

tests/test_client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
capture_exception,
2222
capture_event,
2323
set_tag,
24+
start_transaction,
2425
)
2526
from sentry_sdk.spotlight import DEFAULT_SPOTLIGHT_URL
2627
from sentry_sdk.utils import capture_internal_exception
@@ -562,6 +563,15 @@ def test_attach_stacktrace_disabled(sentry_init, capture_events):
562563
assert "threads" not in event
563564

564565

566+
def test_attach_stacktrace_transaction(sentry_init, capture_events):
567+
sentry_init(traces_sample_rate=1.0, attach_stacktrace=True)
568+
events = capture_events()
569+
with start_transaction(name="transaction"):
570+
pass
571+
(event,) = events
572+
assert "threads" not in event
573+
574+
565575
def test_capture_event_works(sentry_init):
566576
sentry_init(transport=_TestTransport())
567577
pytest.raises(EnvelopeCapturedError, lambda: capture_event({}))

0 commit comments

Comments
 (0)