Skip to content

fix: sample high-volume "Token required" Sentry errors at 1%#116

Merged
thomasrockhu-codecov merged 6 commits intomainfrom
th/sample-token-errors
Mar 26, 2026
Merged

fix: sample high-volume "Token required" Sentry errors at 1%#116
thomasrockhu-codecov merged 6 commits intomainfrom
th/sample-token-errors

Conversation

@thomasrockhu-codecov
Copy link
Collaborator

@thomasrockhu-codecov thomasrockhu-codecov commented Mar 24, 2026

Summary

  • Adds a before_send hook to Sentry SDK init that samples "Token required" error events at 1% (1 in 100), dropping the rest
  • Issue CLI-S has ~21M occurrences flooding Sentry; this reduces volume while still capturing representative samples
  • The sampling pattern list (_SAMPLED_MESSAGES) is extensible for future high-volume errors

Test plan

  • Verify existing tests pass (pytest tests/helpers/test_args.py)
  • Confirm other Sentry events (non-"Token required") are unaffected and always sent
  • After deploy, monitor CLI-S event volume in Sentry to confirm ~99% reduction

@thomasrockhu-codecov thomasrockhu-codecov force-pushed the th/sample-token-errors branch 2 times, most recently from 51740fd to 9ba6faa Compare March 24, 2026 13:35
@thomasrockhu-codecov thomasrockhu-codecov force-pushed the th/sample-token-errors branch 3 times, most recently from 84501b9 to 7382961 Compare March 25, 2026 13:32
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

The CLI-S issue has ~21M occurrences of "Token required - not valid
tokenless upload" errors flooding Sentry. Add a before_send hook that
randomly drops 99 out of 100 events matching this message pattern,
reducing volume while still capturing representative samples.
The _before_send hook only checked logentry.message and event.message,
but Sentry exception events store error text in
exception.values[i].value. Extract a _collect_messages generator that
yields from all three locations so "Token required" exceptions are
actually matched and sampled at 1%.

Made-with: Cursor
Collapse _collect_messages generator into a single inline expression
and replace nested loops with any(). Same behavior, half the lines.
@thomasrockhu-codecov
Copy link
Collaborator Author

@thomasrockhu-codecov thomasrockhu-codecov merged commit 130cb06 into main Mar 26, 2026
29 checks passed
@thomasrockhu-codecov thomasrockhu-codecov deleted the th/sample-token-errors branch March 26, 2026 07:01
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.

2 participants