Title: node: Healthy process sessions are never sent because the beforeExit check is inverted · Issue #23699 · getsentry/sentry-javascript · GitHub
Open Graph Title: node: Healthy process sessions are never sent because the beforeExit check is inverted · Issue #23699 · getsentry/sentry-javascript
X Title: node: Healthy process sessions are never sent because the beforeExit check is inverted · Issue #23699 · getsentry/sentry-javascript
Description: Is there an existing issue for this? I have reviewed the documentation https://docs.sentry.io/ I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I am using the latest SDK release https://github.com/...
Open Graph Description: Is there an existing issue for this? I have reviewed the documentation https://docs.sentry.io/ I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I am using th...
X Description: Is there an existing issue for this? I have reviewed the documentation https://docs.sentry.io/ I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I am using th...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/23699
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"node: Healthy process sessions are never sent because the beforeExit check is inverted","articleBody":"### Is there an existing issue for this?\n\n- [x] I have reviewed the documentation https://docs.sentry.io/\n- [x] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues\n- [x] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases\n\n### How do you use Sentry?\n\nSentry Saas (sentry.io)\n\n### Which SDK are you using?\n\n@sentry/node\n\n### SDK Version\n\n10.70.0\n\n### Framework Version\n\n_No response_\n\n### Link to Sentry event\n\n_No response_\n\n### Reproduction Example/SDK Setup\n\n`processSessionIntegration` is an unconditional default integration (`packages/node/src/sdk/index.ts:73`, and `packages/bun/src/sdk.ts:66` for `@sentry/bun`), so no opt-in is needed to hit this. Any plain Node process reproduces it:\n\n```js\nSentry.init({ dsn: __YOUR_DSN__, release: '1.0.0' });\n// ...do some work, capture no errors...\n// process exits normally -> expect one session envelope with status \"exited\"\n```\n\nA unit test in this repo reproduces it without a network. Save as `packages/node/test/integrations/processSession.test.ts` and run `cd packages/node && yarn vitest run test/integrations/processSession.test.ts`:\n\n```ts\nimport { getIsolationScope, setCurrentClient } from '@sentry/core';\nimport { beforeEach, describe, expect, it, vi } from 'vitest';\nimport { processSessionIntegration } from '../../src/integrations/processSession';\nimport { NodeClient } from '../../src/sdk/client';\nimport { getDefaultNodeClientOptions } from '../helpers/getDefaultNodeClientOptions';\n\ndescribe('processSessionIntegration', () => {\n let client: NodeClient;\n let sendSession: ReturnType\u003ctypeof vi.spyOn>;\n let beforeExitHandler: () => void;\n\n beforeEach(() => {\n getIsolationScope().setSession(undefined);\n client = new NodeClient(getDefaultNodeClientOptions({ release: '1.0.0' }));\n setCurrentClient(client);\n client.init();\n sendSession = vi.spyOn(client, 'sendSession').mockImplementation(() => undefined);\n\n const onSpy = vi.spyOn(process, 'on').mockImplementation(((event: string, cb: () => void) => {\n if (event === 'beforeExit') beforeExitHandler = cb;\n return process;\n }) as never);\n processSessionIntegration().setupOnce!();\n onSpy.mockRestore();\n });\n\n it('sends one session with status \"exited\" on a healthy exit', () => {\n beforeExitHandler();\n expect(sendSession).toHaveBeenCalledTimes(1);\n expect(sendSession).toHaveBeenCalledWith(expect.objectContaining({ status: 'exited' }));\n });\n\n it('does not send a second update for an already-crashed session', () => {\n getIsolationScope().getSession()!.status = 'crashed';\n sendSession.mockClear();\n beforeExitHandler();\n expect(sendSession).toHaveBeenCalledTimes(0);\n });\n});\n```\n\n### Steps to Reproduce\n\n1. Run any Node process with `Sentry.init({ dsn, release })` that does some work and exits cleanly, capturing no errors.\n2. Look for a `session` envelope in the SDK output — or add the unit test above and run it.\n3. Or just read `packages/node/src/integrations/processSession.ts`; the whole file is 31 lines:\n\n```ts\n// Only call endSession, if the Session exists on Scope and SessionStatus is not a\n// Terminal Status i.e. Exited or Crashed because\n// \"When a session is moved away from ok it must not be updated anymore.\"\n// Ref: https://develop.sentry.dev/sdk/sessions/\nif (session?.status !== 'ok') {\n endSession();\n}\n```\n\nThe guard the comment describes is \"session exists **and** status is not exited/crashed\". What is written is its inverse for the healthy case.\n\n### Expected Result\n\nPer the comment's own description and https://develop.sentry.dev/sdk/sessions/:\n\n- healthy exit → exactly one session envelope, status `exited`\n- already-crashed session → no further update for that `sid`, since it is terminal\n\nBoth tests above pass.\n\n### Actual Result\n\n- healthy exit → **zero** session envelopes; nothing is ever sent for the process\n- already-crashed session → **one** further envelope, a post-terminal update for the same `sid`\n\nBoth tests above fail, against `develop` @ 3016b1fc9:\n\n```\n × processSessionIntegration > sends one session with status \"exited\" on a healthy exit\n → expected \"sendSession\" to be called 1 times, but got 0 times\n × processSessionIntegration > does not send a second update for an already-crashed session\n → expected \"sendSession\" to be called +0 times, but got 1 times\n\n Tests 2 failed (2)\n```\n\nInspecting the spy calls directly shows the healthy run records no `sendSession` call at all, and the crashed run records one with `status: \"crashed\"`.\n\n### Additional Context\n\n### Why the healthy case sends nothing at all\n\n`startSession()` (`packages/core/src/exports.ts`) only creates the session and puts it on the isolation scope — it does not send it. The only route to a `type: 'session'` envelope is:\n\n```\nendSession() -> closeSession() -> _sendSessionUpdate() -> client.captureSession() -> sendSession()\n```\n\nThe browser SDK compensates with an explicit deferred `captureSession()` (`packages/browser/src/integrations/browsersession.ts`), but Node has no initial send — and a repo-wide grep finds exactly one non-export `endSession()` call site across `packages/node/src` and `packages/bun/src`: this handler, at `processSession.ts:26`. So when the guard skips it, nothing is sent for the entire process run.\n\nThis is not covered by the request-session aggregates. Those come from `packages/core/src/integrations/http/record-request-session.ts` via `client.sendSession({ aggregates })` and only apply to an HTTP server, so scripts, CLIs, workers and serverless invocations are left with nothing.\n\n### Provenance — the guard was inverted at some point\n\nPR #3423 (\"feat(node): Application mode sessions\") introduced this handler with the same comment that is still present today, and the condition was:\n\n```js\nconst terminalStates = [SessionStatus.Exited, SessionStatus.Crashed];\n// Only call endSession, if the Session exists on Scope and SessionStatus is not a\n// Terminal Status i.e. Exited or Crashed because\nif (session && !terminalStates.includes(session.status)) hub.endSession();\n```\n\nThe current `session?.status !== 'ok'` is the logical inverse of that for the healthy case, and it additionally fires when `session` is `undefined` — which the comment's \"if the Session exists on Scope\" explicitly excludes.\n\nThat PR also added a manual test asserting a healthy session *is* sent on `beforeExit` (`packages/node/test/manual/release-health/single-session/healthy-session.js`). No `release-health` directory or `healthy-session*` file exists in the repo any more, so nothing guards this behaviour today.\n\nNothing asserts the current behaviour either: there is no `processSession` test anywhere in the repo, and with the guard restored the full `@sentry/node` unit suite still passes (32 files, 366 tests).\n\n### Suggested fix\n\nOne line, restoring what the comment describes:\n\n```ts\nif (session && session.status !== 'exited' && session.status !== 'crashed') {\n```\n\nVerified: with that change the unit test above passes in both directions and the node suite stays green. Happy to open a PR with the test.\n\n### Related, but distinct\n\n- #19777 \"Session immutability constraints are violated\" (open, Browser) — same spec family as the post-terminal-update half of this report, but it concerns mutating session *attributes* after first send in the browser, and does not cover the healthy-session-never-sent half at all.\n- #18516 \"Bun projects unable to have release health\" (closed as completed via #18852) — the reported symptom was exactly this healthy case: no release-health data from a process. It was closed by adding `processSessionIntegration` to Bun's defaults; the guard itself was never touched, and the reporter never confirmed a fix.\n\n### Affected versions\n\nPresent in 10.70.0. In that release the file lived at `packages/node-core/src/integrations/processSession.ts` and is byte-identical to the current `packages/node/src/integrations/processSession.ts` (`packages/node-core` has since been removed).\n\n### Priority\n\n_No response_","author":{"url":"https://github.com/suhailopensource","@type":"Person","name":"suhailopensource"},"datePublished":"2026-08-27T14:53:50Z","url":"https://github.com/getsentry/sentry-javascript/issues/23699"}
| 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:6c4d45fd-9ae9-4bd5-3324-2f9d48b6e83b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DA06:1E7453:5454D5:769449:6B047420 |
| html-safe-nonce | fda215fc7450c63ee1330b58bb55112c310517a75c749e708f8f763c0c546662 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQTA2OjFFNzQ1Mzo1NDU0RDU6NzY5NDQ5OjZCMDQ3NDIwIiwidmlzaXRvcl9pZCI6IjQ4NzEwMjE2Nzc0NzMxOTkxMzYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 4c4b503b1d46a9bc35d3ccf502f91f09be2334f4a35b5309afc77fa8df6d2d16 |
| hovercard-subject-tag | issue:5268946983 |
| 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/23699/issue_layout |
| twitter:image | https://opengraph.githubassets.com/1d50407bec710ad6b29813e0340f8a8a6bfce66ba141a3519459bd075275c0e7/getsentry/sentry-javascript/issues/23699 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/1d50407bec710ad6b29813e0340f8a8a6bfce66ba141a3519459bd075275c0e7/getsentry/sentry-javascript/issues/23699 |
| og:image:alt | Is there an existing issue for this? I have reviewed the documentation https://docs.sentry.io/ I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues I am using th... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | suhailopensource |
| hostname | github.com |
| expected-hostname | github.com |
| None | ae8802492f12d3ba4f6b0d814054e617a2a5616b6327bf8555c10cd5b0dc2a6f |
| 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 | cfb5f24c6e01d85f70804652a5107e5cac03a161 |
| 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