Title: Introduce Async Hooks into the SDK · Issue #7691 · getsentry/sentry-javascript · GitHub
Open Graph Title: Introduce Async Hooks into the SDK · Issue #7691 · getsentry/sentry-javascript
X Title: Introduce Async Hooks into the SDK · Issue #7691 · getsentry/sentry-javascript
Description: ref: #3660 Let's work toward adding async hooks into the SDK. What we probably want to use is AsyncLocalStorage, which was made stable in v16.4.0, but added in v13.10.0, v12.17.0 Important to note that for Node 8, 10, 12 we should still ...
Open Graph Description: ref: #3660 Let's work toward adding async hooks into the SDK. What we probably want to use is AsyncLocalStorage, which was made stable in v16.4.0, but added in v13.10.0, v12.17.0 Important to note ...
X Description: ref: #3660 Let's work toward adding async hooks into the SDK. What we probably want to use is AsyncLocalStorage, which was made stable in v16.4.0, but added in v13.10.0, v12.17.0 Important to n...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/7691
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Introduce Async Hooks into the SDK","articleBody":"ref: https://github.com/getsentry/sentry-javascript/issues/3660\r\n\r\nLet's work toward adding async hooks into the SDK. What we probably want to use is [`AsyncLocalStorage`](https://nodejs.org/api/async_context.html#class-asynclocalstorage), which was made stable in `v16.4.0`, but added in `v13.10.0, v12.17.0`\r\n\r\nImportant to note that for Node 8, 10, 12 we should still use domains, and then for Node 14 and above we can use `AsyncLocalStorage`.\r\n\r\n- [x] https://github.com/getsentry/sentry-javascript/pull/7753\r\n- [x] https://github.com/getsentry/sentry-javascript/pull/7767\r\n- [x] https://github.com/getsentry/sentry-javascript/pull/7779\r\n- [x] #7799\r\n- [x] #7800\r\n- [x] #7804\r\n- [x] Test performance differences between ASL and domains\r\n- [x] Expose and document methods for async context management (for manual instrumentation)\r\n- [x] https://github.com/getsentry/sentry-docs/pull/6641\r\n\r\nRequirements:\r\n\r\n1. There must be only one hub management strategy active at a time (no exceptions)\r\n2. No breaking changes\r\n\r\nAdditional Details:\r\n\r\nWe can get this done with the following steps.\r\n\r\n```ts\r\n// @sentry/node\r\nimport { setAsyncContextStrategy } from '@sentry/core';\r\n\r\ninterface AsyncContextStrategy {\r\n getCurrentHub(): Hub | undefined;\r\n runWithAsyncContext\u003cT>(callback: (hub: Hub) => T): T;\r\n}\r\n\r\ninit() {\r\n setHubStrategy(strategy)\r\n}\r\n```\r\n\r\n1. Update `getCurrentHub` to reference some global strategy for grabbing the current hub. When you initialize the SDK in Node 8-12, it uses a domain strategy. For Node 14+ it'll use async local storage strategy.\r\n2. Instead of using domains directly in our code, we should define a `runWithHub` method that creates a new domain/asynclocalstorage/whatever for that code. Then we can go in and replace domain usage with `runWithHub` instead.\r\n\r\nThe global strategy can just just be registered onto the global object. This means there can only be one global strategy at a time.\r\n\r\nWe have to add this concept of a strategy to `@sentry/core`, so it can also be used by non-node SDKs (think vercel edge, cloudflare workers etc.).","author":{"url":"https://github.com/AbhiPrasad","@type":"Person","name":"AbhiPrasad"},"datePublished":"2023-03-31T10:13:52Z","url":"https://github.com/getsentry/sentry-javascript/issues/7691"}
| 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:52df3500-375f-ce1b-7a41-526b253c7bf9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AC00:C710:502523:7007FF:6B044473 |
| html-safe-nonce | bdb3cf98165e5c06b2573fd3cdeebea61745be962b47b667b51eca13e4a6e5d6 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQzAwOkM3MTA6NTAyNTIzOjcwMDdGRjo2QjA0NDQ3MyIsInZpc2l0b3JfaWQiOiI5MDk4MDYzNTM3NDA1OTY5NTIzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | d20deaaabea844de943ffc7a960edfd6520d9c4e9359978eb743721e391e8d36 |
| hovercard-subject-tag | issue:1649087087 |
| 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/7691/issue_layout |
| twitter:image | https://opengraph.githubassets.com/be3a56f5ef317605ab4e6dbdc0593f63b3c0a2862b7bc536db8b7a47d1abe8d5/getsentry/sentry-javascript/issues/7691 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/be3a56f5ef317605ab4e6dbdc0593f63b3c0a2862b7bc536db8b7a47d1abe8d5/getsentry/sentry-javascript/issues/7691 |
| og:image:alt | ref: #3660 Let's work toward adding async hooks into the SDK. What we probably want to use is AsyncLocalStorage, which was made stable in v16.4.0, but added in v13.10.0, v12.17.0 Important to note ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | AbhiPrasad |
| hostname | github.com |
| expected-hostname | github.com |
| None | d4495c3631faba668036f176d1f5946901c5172efd73a6edb984029e7d4f8e46 |
| 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 | 9ac4337fb7c6a5846cdfdb1a04f154d3c33ebc77 |
| 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