Skip to content

Commit 2348f52

Browse files
authored
fix(serialization): Adjust breadcrumb check for new structure (#883)
Fixes a bug which resulted in events being capped at 10 breadcrumbs. More details in the PR description.
1 parent 4fab6df commit 2348f52

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

sentry_sdk/consts.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
total=False,
3232
)
3333

34+
DEFAULT_MAX_BREADCRUMBS = 100
35+
3436

3537
# This type exists to trick mypy and PyCharm into thinking `init` and `Client`
3638
# take these arguments (even though they take opaque **kwargs)
@@ -39,7 +41,7 @@ def __init__(
3941
self,
4042
dsn=None, # type: Optional[str]
4143
with_locals=True, # type: bool
42-
max_breadcrumbs=100, # type: int
44+
max_breadcrumbs=DEFAULT_MAX_BREADCRUMBS, # type: int
4345
release=None, # type: Optional[str]
4446
environment=None, # type: Optional[str]
4547
server_name=None, # type: Optional[str]

sentry_sdk/serializer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ def _is_databag():
188188
if p0 == "request" and path[1] == "data":
189189
return True
190190

191-
if p0 == "breadcrumbs":
192-
path[1]
191+
if p0 == "breadcrumbs" and path[1] == "values":
192+
path[2]
193193
return True
194194

195195
if p0 == "extra":

tests/test_client.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from sentry_sdk import (
1111
Hub,
1212
Client,
13+
add_breadcrumb,
1314
configure_scope,
1415
capture_message,
1516
capture_exception,
@@ -21,6 +22,8 @@
2122
from sentry_sdk.transport import Transport
2223
from sentry_sdk._compat import reraise, text_type, PY2
2324
from sentry_sdk.utils import HAS_CHAINED_EXCEPTIONS
25+
from sentry_sdk.serializer import MAX_DATABAG_BREADTH
26+
from sentry_sdk.consts import DEFAULT_MAX_BREADCRUMBS
2427

2528
if PY2:
2629
# Importing ABCs from collections is deprecated, and will stop working in 3.8
@@ -611,6 +614,10 @@ def inner():
611614

612615
(event,) = events
613616

617+
assert (
618+
len(event["exception"]["values"][0]["stacktrace"]["frames"][0]["vars"]["a"])
619+
== MAX_DATABAG_BREADTH
620+
)
614621
assert len(json.dumps(event)) < 10000
615622

616623

@@ -860,3 +867,21 @@ def capture_event(self, event):
860867

861868
assert not envelopes
862869
assert not events
870+
871+
872+
@pytest.mark.parametrize(
873+
"sdk_options, expected_breadcrumbs",
874+
[({}, DEFAULT_MAX_BREADCRUMBS), ({"max_breadcrumbs": 50}, 50)],
875+
)
876+
def test_max_breadcrumbs_option(
877+
sentry_init, capture_events, sdk_options, expected_breadcrumbs
878+
):
879+
sentry_init(sdk_options)
880+
events = capture_events()
881+
882+
for _ in range(1231):
883+
add_breadcrumb({"type": "sourdough"})
884+
885+
capture_message("dogs are great")
886+
887+
assert len(events[0]["breadcrumbs"]["values"]) == expected_breadcrumbs

0 commit comments

Comments
 (0)