Skip to content

fix(telemetry): patch Sentry SDK to prevent 3-second exit delay#85

Merged
BYK merged 1 commit intomainfrom
fix/telemetry-flush-timeout
Jan 27, 2026
Merged

fix(telemetry): patch Sentry SDK to prevent 3-second exit delay#85
BYK merged 1 commit intomainfrom
fix/telemetry-flush-timeout

Conversation

@BYK
Copy link
Copy Markdown
Member

@BYK BYK commented Jan 27, 2026

Summary

Fixes the 3-second hang when exiting the CLI caused by the Sentry SDK's flush(3000) call.

Root Cause

The Sentry SDK's internal timers in @sentry/core don't call .unref(), which keeps the Node.js event loop alive for the full timeout duration even when there's nothing to send:

  • client.js _isClientDoneProcessing() - polls with 1ms setTimeout in a loop
  • promisebuffer.js drain() - uses setTimeout for the timeout value

Changes

  • Patch @sentry/core@10.36.0: Add .unref() to these timers with browser-safe checks
  • Early exit optimization: Check _numProcessing === 0 before the first setTimeout, not after
  • E2E test: Verify CLI exits within reasonable time with telemetry enabled

Testing

E2E test compares exit time with telemetry disabled vs enabled, ensuring the enabled case doesn't add significant delay (< 500ms overhead, definitely < 1.5s total vs previous 3s+).

Upstream

Will file issue at getsentry/sentry-javascript after this PR is validated.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 27, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

Issue

  • Add workspace-scoped alias cache by BYK in #52
  • Add short ID aliases for multi-project support by BYK in #31

Other

  • (api) Align with gh api and curl conventions by BYK in #60
  • (auth) Add press 'c' to copy URL during login flow by betegon in #58
  • (commands) Rename get commands to view and add -w browser flag by BYK in #53
  • Added footer formatting function by MathurAditya724 in #71
  • Add explain and plan commands (Seer AI) by MathurAditya724 in #39
  • Add Sentry SDK for error tracking and usage telemetry by BYK in #63

Bug Fixes 🐛

Issue

  • Support short ID aliases in explain and plan commands by BYK in #74
  • Use correct fallback for unrecognized alias-suffix inputs by BYK in #72
  • Handle cross-org project slug collisions in alias generation by BYK in #62
  • Use org-scoped endpoint for latest event + enhanced display by betegon in #40

Other

  • (api) Use query params for --field with GET requests by BYK in #59
  • (telemetry) Patch Sentry SDK to prevent 3-second exit delay by BYK in #85

Documentation 📚

  • (issue) Update list command tips to reference view instead of get by BYK in #73
  • (readme) Add installation section by betegon in #65
  • Update command references from 'get' to 'view' and document -w flag by BYK in #54

Internal Changes 🔧

  • (issue) Extract shared parameters for issue commands by BYK in #79
  • (release) Fix changelog-preview permissions by BYK in #41
  • Rename config folder from .sentry-cli-next to .sentry by BYK in #50

Other

  • test(e2e): use mock HTTP server instead of live API by BYK in #78

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Jan 27, 2026

Codecov Results 📊

✅ Patch coverage is 100.00%. Project has 1663 uncovered lines.
✅ Project coverage is 64.79%. Comparing base (base) to head (head).

Files with missing lines (22)
File Patch % Lines
human.ts 18.35% ⚠️ 672 Missing
resolve-target.ts 18.67% ⚠️ 257 Missing
oauth.ts 21.71% ⚠️ 202 Missing
resolver.ts 3.23% ⚠️ 120 Missing
errors.ts 5.94% ⚠️ 95 Missing
api-client.ts 73.48% ⚠️ 74 Missing
api.ts 89.78% ⚠️ 47 Missing
seer.ts 75.54% ⚠️ 45 Missing
errors.ts 73.17% ⚠️ 33 Missing
seer.ts 76.15% ⚠️ 31 Missing
preload.ts 39.02% ⚠️ 25 Missing
detector.ts 87.79% ⚠️ 16 Missing
cache.ts 76.27% ⚠️ 14 Missing
telemetry.ts 89.87% ⚠️ 8 Missing
config.ts 97.11% ⚠️ 7 Missing
index.ts 95.06% ⚠️ 4 Missing
colors.ts 91.84% ⚠️ 4 Missing
env-file.ts 97.17% ⚠️ 3 Missing
utils.ts 98.64% ⚠️ 2 Missing
alias.ts 98.56% ⚠️ 2 Missing
java.ts 97.22% ⚠️ 1 Missing
parser.ts 98.63% ⚠️ 1 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    64.79%    64.79%        —%
==========================================
  Files           39        39         —
  Lines         4723      4723         —
  Branches         0         0         —
==========================================
+ Hits          3060      3060         —
- Misses        1663      1663         —
- Partials         0         0         —

Generated by Codecov Action

@BYK BYK force-pushed the fix/telemetry-flush-timeout branch 2 times, most recently from f1bbf38 to 96d8e7f Compare January 27, 2026 13:27
@BYK BYK marked this pull request as ready for review January 27, 2026 14:21
Copy link
Copy Markdown
Contributor

@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 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

The Sentry SDK flush() method blocks process exit for the full timeout
duration due to non-unref'd setTimeout calls. This causes a 3-second
hang when exiting the CLI even when there's nothing to send.

This patch adds .unref() to timers in:
- client.js _isClientDoneProcessing() - polling loop timer
- promisebuffer.js drain() - timeout timer

Also adds early exit check in _isClientDoneProcessing() when nothing
is processing.

Includes E2E test to verify the fix.

Upstream issue: getsentry/sentry-javascript#18996
@BYK BYK force-pushed the fix/telemetry-flush-timeout branch from 96d8e7f to cfae32a Compare January 27, 2026 14:59
@BYK BYK merged commit bf4661a into main Jan 27, 2026
16 checks passed
@BYK BYK deleted the fix/telemetry-flush-timeout branch January 27, 2026 15:11
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.

1 participant