Skip to content

Conversation

alexander-alderman-webb
Copy link
Contributor

@alexander-alderman-webb alexander-alderman-webb commented Oct 17, 2025

Description

The breadcrumbs dictionary is normally initialized in Scope._apply_breadcrumbs_to_event():

def _apply_breadcrumbs_to_event(self, event, hint, options):
# type: (Event, Hint, Optional[Dict[str, Any]]) -> None
event.setdefault("breadcrumbs", {})
# This check is just for mypy -
if not isinstance(event["breadcrumbs"], AnnotatedValue):
event["breadcrumbs"].setdefault("values", [])

However, the method is only invoked if the event is not a span or a check in:

if not is_transaction and not is_check_in:
self._apply_breadcrumbs_to_event(event, hint, options)
self._apply_flags_to_event(event, hint, options)

The user that reported the issue is filtering on a check in. Their suspicion that the AnnotatedValue created a default breadcrumbs value of the wrong type for check ins is correct.

Add the following snippet to tests/test_client.py to test. I didn't push this test because I don't see why we're adding truncated breadcrumbs metadata to spans and check ins in the first place.

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

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

    with start_transaction(name="transaction"):
        pass

    assert "values" in events[0]["breadcrumbs"]

Issues

Closes #4951

Reminders

@alexander-alderman-webb alexander-alderman-webb requested a review from a team as a code owner October 17, 2025 09:43
Copy link
Contributor

@sentrivana sentrivana left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good quick fix. There's a couple of things at play in the original issue:

  • check-ins are actually not supposed to go through before_send at all, that's a bug, see also https://develop.sentry.dev/sdk/expected-features/#before-send-hook
  • breadcrumbs afaik don't make sense for anything but error events (though we shouldn't populate the field with an invalid empty value in any case so this PR is a good improvement 👍🏻 )
  • there's also the lesser known before_breadcrumb that could be used to sanitize breadcrumbs

@alexander-alderman-webb alexander-alderman-webb merged commit cc432a6 into master Oct 17, 2025
112 checks passed
@alexander-alderman-webb alexander-alderman-webb deleted the webb/breadcrumbs-type branch October 17, 2025 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unexpected event["breadcrumbs"] type

2 participants