Title: Offline support via `Transport` wrapper · Issue #6403 · getsentry/sentry-javascript · GitHub
Open Graph Title: Offline support via `Transport` wrapper · Issue #6403 · getsentry/sentry-javascript
X Title: Offline support via `Transport` wrapper · Issue #6403 · getsentry/sentry-javascript
Description: Problem Statement Currently for browser offline caching support there is the Offline integration which has a number of issues: It does not cater for events that fail to send due to network issues Browser navigator.onLine does not offer a...
Open Graph Description: Problem Statement Currently for browser offline caching support there is the Offline integration which has a number of issues: It does not cater for events that fail to send due to network issues B...
X Description: Problem Statement Currently for browser offline caching support there is the Offline integration which has a number of issues: It does not cater for events that fail to send due to network issues B...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/6403
X: @github
Domain: github.com
IPv4 address: 140.82.112.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Offline support via `Transport` wrapper","articleBody":"### Problem Statement\r\n\r\nCurrently for browser offline caching support there is the `Offline` integration which has a number of issues:\r\n\r\n- It does not cater for events that fail to send due to network issues\r\n- Browser `navigator.onLine` does not offer a reliable way to determine if the machine is connected to the internet. It only tells you that the machine is connected to a network. \r\n - For example, on Windows, the Docker virtual network adaptor means that `onLine` is always `true` 😭\r\n- Because it sends delayed events via `hub.captureEvent()` this results in another pass through the integrations which triggers the `Dedupe` integration https://github.com/getsentry/sentry-javascript/issues/3046#issuecomment-1287404024.\r\n - Multiple passes through integrations and event processors opens up a lot of issues and confusion \r\n\r\n\r\n### Solution Brainstorm\r\n\r\nIt makes more sense for offline support to act at the transport interface so it can catch send failures. Since the transports have recently been re-written in v7 with a functional approach this has become simpler.\r\n\r\n```ts\r\nconst makeOfflineFetchTransport = makeOfflineTransport(makeFetchTransport);\r\n```\r\n\r\nAdditionally allow the backing store to be configurable: \r\n```ts\r\nconst makeOfflineFetchTransport = makeOfflineTransport(makeFetchTransport, indexedDbStore(MAX_QUEUE_LENGTH));\r\n```\r\n\r\nThe issue with wrapping `Transport` directly is that `send` doesn't pass through rate limit responses so there is no way to wrap that directly and retry for those failures:\r\n\r\n```ts\r\nexport interface Transport {\r\n send(request: Envelope): PromiseLike\u003cvoid>;\r\n flush(timeout?: number): PromiseLike\u003cboolean>;\r\n}\r\n```\r\nTo get around this current limitation, the Electron SDK offline transport [wraps the default `TransportRequestExecutor`](https://github.com/getsentry/sentry-electron/blob/master/src/main/transports/electron-offline-net.ts) and adds offline persisting. This allows us to queue and retry events that have failed due to rate limit errors. \r\n\r\nIs this desired in the browser? Should we be retying rate-limited requests?\r\n\r\nWe could change `send` to this without it being a breaking change (#6626):\r\n```ts\r\nsend(request: Envelope): PromiseLike\u003cvoid | TransportMakeRequestResponse>;\r\n```\r\nThen all the existing transports can pass through the response.\r\n\r\nAnother solution would be to add a new function although this won't currently be able to wrap the existing transports because they don't expose/export their `TransportRequestExecutor` implementations:\r\n\r\n```ts\r\nexport function createOfflineTransport(\r\n options: InternalBaseTransportOptions,\r\n makeRequest: TransportRequestExecutor,\r\n store: PersistStore = makeIndexedDbStore(DEFAULT_TRANSPORT_BUFFER_SIZE),\r\n): Transport {\r\n //\r\n}\r\n```","author":{"url":"https://github.com/timfish","@type":"Person","name":"timfish"},"datePublished":"2022-12-04T08:42:06Z","url":"https://github.com/getsentry/sentry-javascript/issues/6403"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:97dae6ab-6517-fd4d-eaac-f334fc5b3504 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B090:29C09E:886F3C:BFF010:6B0428AE |
| html-safe-nonce | fcfa8033bd50724aabb37fc526aaebb76a0c183820ca8a9161b24325a31aa492 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMDkwOjI5QzA5RTo4ODZGM0M6QkZGMDEwOjZCMDQyOEFFIiwidmlzaXRvcl9pZCI6IjM0MTAzMjk4NjAxODEzMzgyODYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 74fc1e674b9272be7b0b37d1f047bd53410bddaae0021ce7323170b0cf418bac |
| hovercard-subject-tag | issue:1474606865 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-javascript/6403/issue_layout |
| twitter:image | https://opengraph.githubassets.com/04580f68d42335e5b5cbbed53a743ec35e6a62bd1f99204721fd2b697114a46a/getsentry/sentry-javascript/issues/6403 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/04580f68d42335e5b5cbbed53a743ec35e6a62bd1f99204721fd2b697114a46a/getsentry/sentry-javascript/issues/6403 |
| og:image:alt | Problem Statement Currently for browser offline caching support there is the Offline integration which has a number of issues: It does not cater for events that fail to send due to network issues B... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | timfish |
| hostname | github.com |
| expected-hostname | github.com |
| None | b7a1d2b9101496921b08579fbee988d014345aef2f5bd660d1f8c7332d81560e |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-javascript git https://github.com/getsentry/sentry-javascript.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 3328572 |
| octolytics-dimension-repository_nwo | getsentry/sentry-javascript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3328572 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-javascript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | c3dd496c3da6ea6b77e69c09279d2b81604654f1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width