Repository navigation
feat(node): Stop sending the process session once request sessions are tracked #24915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+218
−5
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
257e7c8
feat(node): Stop sending the process session once request sessions ar…
mydea 3df3e63
test(node): Cover switching from the process session to request aggre…
mydea 2b1d3ee
ref(node): Start the process session in `setup` instead of `setupOnce`
mydea 5318766
test(node): Wait for the startup error to be processed before serving…
mydea 0515ec5
test(bun): Skip the server process session suite under `@sentry/bun`
mydea 3893005
add comment
mydea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
dev-packages/node-integration-tests/suites/sessions/process-session/instrument.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| release: '1.0', | ||
| transport: loggingTransport, | ||
| }); |
3 changes: 3 additions & 0 deletions
3
dev-packages/node-integration-tests/suites/sessions/process-session/scenario.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
|
|
||
| Sentry.captureException(new Error('Scenario error')); |
18 changes: 18 additions & 0 deletions
18
dev-packages/node-integration-tests/suites/sessions/process-session/test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { afterAll, test } from 'vitest'; | ||
| import { join } from 'path'; | ||
| import { cleanupChildProcesses, createRunner } from '../../../utils/runner'; | ||
|
|
||
| afterAll(() => { | ||
| cleanupChildProcesses(); | ||
| }); | ||
|
|
||
| test('sends a process session for a process that does not serve requests', async () => { | ||
| await createRunner(__dirname, 'scenario.mjs') | ||
| .withInstrument(join(__dirname, 'instrument.mjs')) | ||
| .ignore('event') | ||
| .unignore('session') | ||
| .expect({ session: { init: true, status: 'ok', errors: 1 } }) | ||
| .expect({ session: { init: false, status: 'exited', errors: 1 } }) | ||
| .start() | ||
| .completed(); | ||
| }); |
20 changes: 20 additions & 0 deletions
20
...ration-tests/suites/sessions/server-without-process-session/server-with-startup-error.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests'; | ||
| import express from 'express'; | ||
|
|
||
| Sentry.captureException(new Error('Startup error')); | ||
| // Event processing is async; make sure the error has updated the process session before the first request. | ||
| await Sentry.flush(); | ||
|
|
||
| const app = express(); | ||
|
|
||
| app.get('/test/success', (_req, res) => { | ||
| res.send('Success!'); | ||
| }); | ||
|
|
||
| app.get('/test/error_handled', (_req, res) => { | ||
| Sentry.captureException(new Error('Request error')); | ||
| res.send('Handled!'); | ||
| }); | ||
|
|
||
| startExpressServerAndSendPortToRunner(app); |
56 changes: 56 additions & 0 deletions
56
dev-packages/node-integration-tests/suites/sessions/server-without-process-session/test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { afterAll, expect, test } from 'vitest'; | ||
| import { join } from 'path'; | ||
| import { cleanupChildProcesses, createRunner } from '../../../utils/runner'; | ||
| import type { SessionAggregates } from '@sentry/core'; | ||
|
|
||
| afterAll(() => { | ||
| cleanupChildProcesses(); | ||
| }); | ||
|
|
||
| function sumAggregates(agg: SessionAggregates): { exited: number; errored: number; crashed: number } { | ||
| return agg.aggregates.reduce( | ||
| (acc, b) => ({ | ||
| exited: acc.exited + (b.exited ?? 0), | ||
| errored: acc.errored + (b.errored ?? 0), | ||
| crashed: acc.crashed + (b.crashed ?? 0), | ||
| }), | ||
| { exited: 0, errored: 0, crashed: 0 }, | ||
| ); | ||
| } | ||
|
|
||
| test('does not send a process session once requests are tracked as request sessions', async () => { | ||
| const runner = createRunner(__dirname, '..', 'server.mjs') | ||
| .withInstrument(join(__dirname, '..', 'instrument.mjs')) | ||
| .ignore('transaction', 'event') | ||
| .unignore('session', 'sessions') | ||
| .expect({ | ||
| sessions: agg => { | ||
| expect(sumAggregates(agg)).toEqual({ exited: 1, errored: 1, crashed: 1 }); | ||
| }, | ||
| }) | ||
| .start(); | ||
|
|
||
| runner.makeRequest('get', '/test/success'); | ||
| runner.makeRequest('get', '/test/error_handled'); | ||
| runner.makeRequest('get', '/test/error_unhandled', { expectError: true }); | ||
| await runner.completed(); | ||
| }); | ||
|
|
||
| test('counts an error before the first request in the process session, and later errors in the aggregate', async () => { | ||
| const runner = createRunner(__dirname, 'server-with-startup-error.mjs') | ||
| .withInstrument(join(__dirname, '..', 'instrument.mjs')) | ||
| .ignore('transaction', 'event') | ||
| .unignore('session', 'sessions') | ||
| .expect({ session: { init: true, status: 'ok', errors: 1 } }) | ||
| .expect({ session: { init: false, status: 'exited', errors: 1 } }) | ||
| .expect({ | ||
| sessions: agg => { | ||
| expect(sumAggregates(agg)).toEqual({ exited: 1, errored: 1, crashed: 0 }); | ||
| }, | ||
| }) | ||
| .start(); | ||
|
|
||
| await runner.makeRequest('get', '/test/success'); | ||
| await runner.makeRequest('get', '/test/error_handled'); | ||
| await runner.completed(); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.