8000 fix: Trim long stacktraces · getsentry/sentry-python@df00c7d · GitHub
[go: up one dir, main page]

Skip to content

Commit df00c7d

Browse files
fix: Trim long stacktraces
Only process and send the first 300 stack frames for an error event. This prevents the SDK from causing the program to hang when the SDK captures an error with a very large number of stack frames. Relay anyways [trims events to 250 stack frames](https://github.com/getsentry/relay/blob/aae36669414a1f7c6ef68d5226cb2e96a28f7667/relay-event-normalization/src/trimming.rs#L286), so it is pointless for us to process much beyond that number. Fixes #2764
1 parent ec2d929 commit df00c7d

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

sentry_sdk/consts.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ class CompressionAlgo(Enum):
8282
DEFAULT_MAX_BREADCRUMBS = 100
8383
MATCH_ALL = r".*"
8484

85+
MAX_STACK_FRAMES = 300 # type: int
86+
"""The maximum number of stack frames to capture on error events.
87+
88+
Relay enforces a limit of 250 frames on the stack trace. See
89+
https://github.com/getsentry/relay/blob/aae36669414a1f7c6ef68d5226cb2e96a28f7667/relay-event-normalization/src/trimming.rs#L286.
90+
We use a slightly higher value here; Relay will trim any frames
91+
beyond its limit.
92+
93+
This constant is for internal use only, and it may be changed or removed
94+
at any time.
95+
"""
96+
8597
FALSE_VALUES = [
8698
"false",
8799
"no",

sentry_sdk/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import base64
2+
import itertools
23
import json
34
import linecache
45
import logging
@@ -26,7 +27,7 @@
2627

2728
import sentry_sdk
2829
from sentry_sdk._compat import PY37
29-
from sentry_sdk.consts import DEFAULT_MAX_VALUE_LENGTH, EndpointType
30+
from sentry_sdk.consts import DEFAULT_MAX_VALUE_LENGTH, MAX_STACK_FRAMES, EndpointType
3031

3132
from typing import TYPE_CHECKING
3233

@@ -803,7 +804,7 @@ def single_exception_from_error_tuple(
803804
max_value_length=max_value_length,
804805
custom_repr=custom_repr,
805806
)
806-
for tb in iter_stacks(tb)
807+
for tb in itertools.islice(iter_stacks(tb), MAX_STACK_FRAMES)
807808
]
808809

809810
if frames:

0 commit comments

Comments
 (0)
0