Skip to content

Commit

Permalink
fix(serialization): Adjust breadcrumb check for new structure (#883)
Browse files Browse the repository at this point in the history
Fixes a bug which resulted in events being capped at 10 breadcrumbs. More details in the PR description.
  • Loading branch information
lobsterkatie authored Oct 20, 2020
1 parent 4fab6df commit 2348f52
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
4 changes: 3 additions & 1 deletion sentry_sdk/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
total=False,
)

DEFAULT_MAX_BREADCRUMBS = 100


# This type exists to trick mypy and PyCharm into thinking `init` and `Client`
# take these arguments (even though they take opaque **kwargs)
Expand All @@ -39,7 +41,7 @@ def __init__(
self,
dsn=None, # type: Optional[str]
with_locals=True, # type: bool
max_breadcrumbs=100, # type: int
max_breadcrumbs=DEFAULT_MAX_BREADCRUMBS, # type: int
release=None, # type: Optional[str]
environment=None, # type: Optional[str]
server_name=None, # type: Optional[str]
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ def _is_databag():
if p0 == "request" and path[1] == "data":
return True

if p0 == "breadcrumbs":
path[1]
if p0 == "breadcrumbs" and path[1] == "values":
path[2]
return True

if p0 == "extra":
Expand Down
25 changes: 25 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from sentry_sdk import (
Hub,
Client,
add_breadcrumb,
configure_scope,
capture_message,
capture_exception,
Expand All @@ -21,6 +22,8 @@
from sentry_sdk.transport import Transport
from sentry_sdk._compat import reraise, text_type, PY2
from sentry_sdk.utils import HAS_CHAINED_EXCEPTIONS
from sentry_sdk.serializer import MAX_DATABAG_BREADTH
from sentry_sdk.consts import DEFAULT_MAX_BREADCRUMBS

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

(event,) = events

assert (
len(event["exception"]["values"][0]["stacktrace"]["frames"][0]["vars"]["a"])
== MAX_DATABAG_BREADTH
)
assert len(json.dumps(event)) < 10000


Expand Down Expand Up @@ -860,3 +867,21 @@ def capture_event(self, event):

assert not envelopes
assert not events


@pytest.mark.parametrize(
"sdk_options, expected_breadcrumbs",
[({}, DEFAULT_MAX_BREADCRUMBS), ({"max_breadcrumbs": 50}, 50)],
)
def test_max_breadcrumbs_option(
sentry_init, capture_events, sdk_options, expected_breadcrumbs
):
sentry_init(sdk_options)
events = capture_events()

for _ in range(1231):
add_breadcrumb({"type": "sourdough"})

capture_message("dogs are great")

assert len(events[0]["breadcrumbs"]["values"]) == expected_breadcrumbs

0 comments on commit 2348f52

Please sign in to comment.