Skip to content

Commit e4f3397

Browse files
committed
Make it more resilient againt misuse
1 parent 04f79ed commit e4f3397

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

sentry_sdk/consts.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
# up top to prevent circular import due to integration import
77
DEFAULT_MAX_VALUE_LENGTH = 1024
88

9+
DEFAULT_MAX_STACK_FRAMES = 100
10+
DEFAULT_ADD_FULL_STACK = False
11+
912

1013
# Also needs to be at the top to prevent circular import
1114
class EndpointType(Enum):
@@ -550,8 +553,8 @@ def __init__(
550553
cert_file=None, # type: Optional[str]
551554
key_file=None, # type: Optional[str]
552555
custom_repr=None, # type: Optional[Callable[..., Optional[str]]]
553-
add_full_stack=False, # type: bool
554-
max_stack_frames=50, # type: Optional[int]
556+
add_full_stack=DEFAULT_ADD_FULL_STACK, # type: bool
557+
max_stack_frames=DEFAULT_MAX_STACK_FRAMES, # type: Optional[int]
555558
):
556559
# type: (...) -> None
557560
pass

sentry_sdk/utils.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@
2626

2727
import sentry_sdk
2828
from sentry_sdk._compat import PY37
29-
from sentry_sdk.consts import DEFAULT_MAX_VALUE_LENGTH, EndpointType
29+
from sentry_sdk.consts import (
30+
DEFAULT_ADD_FULL_STACK,
31+
DEFAULT_MAX_STACK_FRAMES,
32+
DEFAULT_MAX_VALUE_LENGTH,
33+
EndpointType,
34+
)
3035

3136
from typing import TYPE_CHECKING
3237

@@ -837,7 +842,9 @@ def single_exception_from_error_tuple(
837842

838843
# Limit the number of frames
839844
max_stack_frames = (
840-
client_options.get("max_stack_frames") if client_options else None
845+
client_options.get("max_stack_frames", DEFAULT_MAX_STACK_FRAMES)
846+
if client_options
847+
else None
841848
)
842849
if max_stack_frames is not None:
843850
new_frames = new_frames[:max_stack_frames]
@@ -1179,7 +1186,7 @@ def event_from_exception(
11791186
exc_info = exc_info_from_error(exc_info)
11801187
hint = event_hint_with_exc_info(exc_info)
11811188

1182-
if client_options and client_options["add_full_stack"]:
1189+
if client_options and client_options.get("add_full_stack", DEFAULT_ADD_FULL_STACK):
11831190
full_stack = get_full_stack()
11841191
else:
11851192
full_stack = None

0 commit comments

Comments
 (0)