Skip to content

test(breadcrumbs): Add regression tests for breadcrumb truncation _meta (#3996) - #7621

Closed
DawnofGenX wants to merge 1 commit into
getsentry:masterfrom
DawnofGenX:fix/issue-3996-breadcrumbs-meta
Closed

DawnofGenX wants to merge 1 commit into
getsentry:masterfrom
DawnofGenX:fix/issue-3996-breadcrumbs-meta

Conversation

@DawnofGenX

Copy link
Copy Markdown

Summary

Adds regression tests for the breadcrumb-truncation _meta annotation described in #3996.

The runtime behavior itself already exists (merged in 5147ab9 / #4007): when breadcrumbs exceed max_breadcrumbs, the SDK tracks the number dropped on the scope and attaches event["_meta"]["breadcrumbs"] = {"": {"len": <original total>}} to captured events. However, the original PR shipped with no dedicated tests (its only test change was an adjustment to tests/test_scrubber.py caused by the new annotation), so nothing in the suite guards this protocol behavior today.

This PR adds three tests to tests/test_client.py next to the existing test_max_breadcrumbs_option:

  1. test_breadcrumbs_truncated_meta — 10 breadcrumbs with max_breadcrumbs=3 → event carries 3 crumbs and _meta records the original total (10).
  2. test_breadcrumbs_not_truncated_no_meta — exactly at the limit → no breadcrumbs entry under _meta.
  3. test_breadcrumbs_truncated_meta_from_child_scope — breadcrumbs added in a child scope accumulate correctly across scope merging (Scope._merge_into).

Test plan / evidence

Fails without the fix (I temporarily reverted the _meta attachment block in sentry_sdk/client.py):

tests/test_client.py::test_breadcrumbs_truncated_meta FAILED
tests/test_client.py::test_breadcrumbs_not_truncated_no_meta PASSED
tests/test_client.py::test_breadcrumbs_truncated_meta_from_child_scope FAILED

E   KeyError: '_meta'  (test_client.py:1091, test_breadcrumbs_truncated_meta)
E   KeyError: '_meta'  (test_client.py:1121, test_breadcrumbs_truncated_meta_from_child_scope)
=========== 2 failed, 1 passed, 88 skipped, 2329 deselected in 2.53s ===========

Passes with the fix restored (full tests/test_client.py):

========== 2246 passed, 174 skipped, 126 warnings in 77.52s (0:01:17) ==========
  py3.14-common: OK

Commands:

  • uv run tox -e py3.14-common -- -k "breadcrumbs_truncated_meta or breadcrumbs_not_truncated_no_meta"
  • uv run tox -e py3.14-common -- tests/test_client.py
  • uv run ruff check --fix tests/test_client.py / uv run ruff format tests/test_client.py (clean)

Fixes #3996

@DawnofGenX
DawnofGenX requested a review from a team as a code owner September 22, 2026 19:41
@alexander-alderman-webb

Copy link
Copy Markdown
Collaborator

Going to close this because we don't have capacity to review the 5 PRs you've opened.
If you'd like to contribute dedicate your time towards making one good PR. Thanks.

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.

Add _meta tag containing the number of breadcrumbs truncated

2 participants