Title: Redis spans become single transactions when using `after` in Next.js · Issue #19529 · getsentry/sentry-javascript · GitHub
Open Graph Title: Redis spans become single transactions when using `after` in Next.js · Issue #19529 · getsentry/sentry-javascript
X Title: Redis spans become single transactions when using `after` in Next.js · Issue #19529 · getsentry/sentry-javascript
Description: Summary While investigating detached spans in our Next.js + Slack app, Codex diagnosed a trace propagation break in the chat SDK async webhook processing pattern. The result is Redis DB spans showing up as root transactions (is_transacti...
Open Graph Description: Summary While investigating detached spans in our Next.js + Slack app, Codex diagnosed a trace propagation break in the chat SDK async webhook processing pattern. The result is Redis DB spans showi...
X Description: Summary While investigating detached spans in our Next.js + Slack app, Codex diagnosed a trace propagation break in the chat SDK async webhook processing pattern. The result is Redis DB spans showi...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/19529
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Redis spans become single transactions when using `after` in Next.js","articleBody":"## Summary\nWhile investigating detached spans in our Next.js + Slack app, **Codex diagnosed** a trace propagation break in the `chat` SDK async webhook processing pattern. The result is Redis DB spans showing up as root transactions (`is_transaction:true`) instead of children of the HTTP webhook/request span.\n\nThis appears to be a context propagation issue around `waitUntil` usage with eagerly-started async tasks.\n\n## What we observed\n- Sentry trace sample: `de7433a2d4c4f70153604eb328d6fd5e`\n- In that trace, DB spans are root spans with `is_transaction:true`.\n- Querying the trace:\n - DB spans with missing parent span id: **6**\n - DB spans with non-empty parent span id: **0**\n- In the last 24h, top `db` “transactions” include Redis commands like:\n - `GET chat-sdk:cache:...`\n - `SISMEMBER chat-sdk:subscriptions ...`\n - `SET chat-sdk:lock:...`\n\nThat indicates the DB spans are detached from the intended request/workflow parent span.\n\n## Why this seems to happen\n### 1) Request span exists in webhook handler\nOur route wraps webhook handling in a request span and passes a background function:\n\n```ts\nwithSpan(\"http.server.request\", \"http.server\", ..., async () => {\n const response = await handler(request, {\n waitUntil: (task) => after(() => task),\n });\n return response;\n});\n```\n\n### 2) `chat` SDK eagerly starts async work before scheduling\nIn `chat` `processMessage` (and similar methods), task is started immediately:\n\n```ts\nconst task = (async () => {\n const message = ...\n await this.handleIncomingMessage(...)\n})().catch(...)\n\noptions?.waitUntil?.(task)\n```\n\nBy the time `waitUntil`/`after` runs, work is already in flight and may no longer be bound to the originating active span context.\n\n### 3) Redis spans are emitted inside that async pipeline\n`handleIncomingMessage` performs state adapter operations (`get/set/lock/isSubscribed/...`), so those DB spans can become root spans if parent context is absent.\n\n## Expected behavior\nDB spans from webhook message processing should remain parented under the request span (or at least under the same trace root), not become detached root transactions.\n\n## Suggested direction\nA lazy background scheduling API in `chat` could avoid eager task startup and preserve context:\n\n- Add something like `runInBackground?: (run: () => Promise\u003cunknown>) => void`\n- If provided, SDK should pass a thunk and let caller execute it in the desired context.\n- Keep existing `waitUntil(task)` for backward compatibility.\n\nThis allows frameworks/runtimes to run deferred work inside a captured active span context (e.g. `withActiveSpan`).\n\n## Environment\n- `@sentry/nextjs`: `10.40.0`\n- `next`: `16.1.6`\n- `chat`: `4.14.0`\n- `@chat-adapter/slack`: `4.14.0`\n- `@chat-adapter/state-redis`: `4.14.0`\n\n## Additional note\nThis diagnosis and root-cause mapping were performed by **Codex** during a deep source + trace analysis.\n","author":{"url":"https://github.com/dcramer","@type":"Person","name":"dcramer"},"datePublished":"2026-02-26T06:23:20Z","url":"https://github.com/getsentry/sentry-javascript/issues/19529"}
| 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:5f7f1439-37e0-6551-44e6-28a1a7e72c54 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B444:2F152B:51FD4B:71E986:6B0455D1 |
| html-safe-nonce | 1333bb3bea0a3a810dce5cbc6c33bb5eb298c26e565ad25fdde056117b1f9139 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNDQ0OjJGMTUyQjo1MUZENEI6NzFFOTg2OjZCMDQ1NUQxIiwidmlzaXRvcl9pZCI6IjM3MjAxNDEwNTExMzEwOTAzODUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 48e81f25e0539f1fe455f08dc5b06cab6850dc30759185ba95296d5a183ee676 |
| hovercard-subject-tag | issue:3993547385 |
| 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/19529/issue_layout |
| twitter:image | https://opengraph.githubassets.com/322cfa99584bc4da802b8ba1f46a67fc82f3a429a20090c3965c0addf871b7c4/getsentry/sentry-javascript/issues/19529 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/322cfa99584bc4da802b8ba1f46a67fc82f3a429a20090c3965c0addf871b7c4/getsentry/sentry-javascript/issues/19529 |
| og:image:alt | Summary While investigating detached spans in our Next.js + Slack app, Codex diagnosed a trace propagation break in the chat SDK async webhook processing pattern. The result is Redis DB spans showi... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dcramer |
| hostname | github.com |
| expected-hostname | github.com |
| None | 910ca0e260cfec6aff11407d8dc6a0d3a4cd381a2ec9ada56627b063426892a0 |
| 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 | e086f9b7e88322eb2b41885a6ad425b215737fa5 |
| 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