Repository navigation
feat: Add offline mode to pause uploads - #2339
Conversation
Add sentry_offline_mode_enable/disable/is_enabled. While offline mode is enabled, nothing is uploaded: envelopes are cached when http_retry is enabled and discarded otherwise. Disabling it sends the cached envelopes immediately. Like user consent, the setting is persisted in the database directory and loaded by sentry_init before envelopes from previous runs are sent, so an app that starts while still offline does not try to upload them. The Crashpad handler and the native crash daemon follow it as well. Logs and metrics are still discarded while offline, as they are today while consent is revoked. Refs #929 Co-Authored-By: Claude Opus 5.5 <[email protected]>
57b5b2d to
9b58b1e
Compare
|
Replace sentry_offline_mode_enable/disable with sentry_set_offline(int) and sentry_offline_mode_is_enabled with sentry_is_offline. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 9168a45. Configure here.
|
Could |
Offline mode and user consent are checked when an envelope is submitted, but envelopes already queued in the HTTP transport were still sent afterwards. Without connectivity, each of them waited for a network timeout, so sentry_close() could still hit the shutdown timeout after sentry_set_offline(1). Check the upload gate in http_send_task right before sending, and handle a blocked envelope like a network failure, so the existing failure path caches it for retry when http_retry is enabled. Refs #929 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Good point, added it in the last commit. |
The crash daemon submitted the logs, sessions and transactions dumped by the crashing app before copying user consent and offline mode from shared memory into its run. With offline mode enabled, those envelopes were still uploaded (or timed out without connectivity), and with user consent given, they were held back as if consent was missing. Copy both values before anything is submitted. Refs #929 Co-Authored-By: Claude Opus 5.5 <[email protected]>
jpnurmi
left a comment
There was a problem hiding this comment.
Nice! A few last remaining CI checks are still running but the changes look good to me. 👍

Adds an offline mode that stops the SDK from uploading anything, so apps that know they have no connectivity don't stall on network timeouts, for example at shutdown. While it's enabled, envelopes are written to the cache if
http_retryis on and discarded otherwise. Disabling it sends the cached envelopes immediately.The setting follows the user-consent model. It's stored in
<database>/offline-modeand loaded bysentry_initbefore envelopes from previous runs are sent, so an app that starts while still offline doesn't try to upload them. Like the consent API, the functions only take effect aftersentry_init. Offline mode is a second reason forsentry__run_should_skip_uploadto block uploads, next to missing consent, so every upload path follows it: events, sessions, the retry poller, the Crashpad handler (viaSetUploadsEnabled/SetUploadsPausedandRequestRetry) and the native crash daemon (via a new shared-memory field). Enabling it withouthttp_retrylogs a warning, because envelopes captured offline would be lost.Logs and metrics are discarded while offline, as they already are while consent is revoked: the batcher drops envelopes whenever uploads are blocked. This is documented on
sentry_set_offline. Caching them too would be a follow-up.Open questions:
SENTRY_CACHE_KEEP_OFFLINE. An alternative issentry_pause_uploads/sentry_resume_uploads, which matches Crashpad's terminology. Should this start asSENTRY_EXPERIMENTAL_API?sentry_set_offline(1)/sentry_set_offline(0)/sentry_is_offline()and decided onSENTRY_APIsentry_init, so the cache can grow beyond them during one long offline run. This is unchanged from how consent and failed sends already behave.sentry_crash_context_twithout increasingSENTRY_CRASH_VERSION, following feat(native): consent-aware offline caching #1649.user_consent_changed_funcnow also fires on offline-mode changes. Should it be renamed?sentry__should_skip_upload()in its consent callback. Once it moves to a 1.x release that includes this change, offline mode would set the region to 0 and crashes would lose their Sentry data, even though Nintendo's crash reporting uploads them later anyway. The backend should check consent only, which may need a consent-only helper here.sentry_transport_newand has no retry support, so with offline mode andhttp_retry, envelopes are cached but never sent, not even aftersentry_set_offline(0). Either document that sending cached envelopes needs the built-in HTTP transport, or add retry support to the PS transport.Fixes #929
🤖 Generated with Claude Code