-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(core): Isolate throwing user callbacks instead of capturing them as events #23770
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
msonnb
merged 3 commits into
ms/safe-callback-helper
from
ms/safe-callback-user-callbacks
Sep 3, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
15 changes: 15 additions & 0 deletions
15
.../node-integration-tests/suites/client-reports/drop-reasons/before-send-throws/scenario.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,15 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| transport: loggingTransport, | ||
| beforeSend() { | ||
| throw new Error('beforeSend failed'); | ||
| }, | ||
| }); | ||
|
|
||
| Sentry.captureException(new Error('this should get dropped because beforeSend throws')); | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
| Sentry.flush(); |
24 changes: 24 additions & 0 deletions
24
...ages/node-integration-tests/suites/client-reports/drop-reasons/before-send-throws/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,24 @@ | ||
| import { afterAll, test } from 'vitest'; | ||
| import { cleanupChildProcesses, createRunner } from '../../../../utils/runner'; | ||
|
|
||
| afterAll(() => { | ||
| cleanupChildProcesses(); | ||
| }); | ||
|
|
||
| test('records a client report and no extra error event when beforeSend throws', async () => { | ||
| await createRunner(__dirname, 'scenario.ts') | ||
| .unignore('client_report') | ||
| .expect({ | ||
| client_report: { | ||
| discarded_events: [ | ||
| { | ||
| category: 'error', | ||
| quantity: 1, | ||
| reason: 'before_send', | ||
| }, | ||
| ], | ||
| }, | ||
| }) | ||
| .start() | ||
| .completed(); | ||
| }); |
17 changes: 17 additions & 0 deletions
17
...gration-tests/suites/client-reports/drop-reasons/event-processor-throws/scenario-async.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,17 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
|
|
||
| Sentry.init({ | ||
| traceLifecycle: 'static', | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| transport: loggingTransport, | ||
| }); | ||
|
|
||
| Sentry.addEventProcessor(async () => { | ||
| throw new Error('async event processor failed'); | ||
| }); | ||
|
|
||
| Sentry.captureException(new Error('this should get dropped because the async event processor rejects')); | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
| Sentry.flush(); |
16 changes: 16 additions & 0 deletions
16
...e-integration-tests/suites/client-reports/drop-reasons/event-processor-throws/scenario.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,16 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| transport: loggingTransport, | ||
| }); | ||
|
|
||
| Sentry.addEventProcessor(() => { | ||
| throw new Error('event processor failed'); | ||
| }); | ||
|
|
||
| Sentry.captureException(new Error('this should get dropped because the event processor throws')); | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
| Sentry.flush(); | ||
42 changes: 42 additions & 0 deletions
42
.../node-integration-tests/suites/client-reports/drop-reasons/event-processor-throws/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,42 @@ | ||
| import { afterAll, test } from 'vitest'; | ||
| import { cleanupChildProcesses, createRunner } from '../../../../utils/runner'; | ||
|
|
||
| afterAll(() => { | ||
| cleanupChildProcesses(); | ||
| }); | ||
|
|
||
| test('records a client report and no extra error event when an event processor throws', async () => { | ||
| await createRunner(__dirname, 'scenario.ts') | ||
| .unignore('client_report') | ||
| .expect({ | ||
| client_report: { | ||
| discarded_events: [ | ||
| { | ||
| category: 'error', | ||
| quantity: 1, | ||
| reason: 'event_processor', | ||
| }, | ||
| ], | ||
| }, | ||
| }) | ||
| .start() | ||
| .completed(); | ||
| }); | ||
|
|
||
| test('records a client report and no extra error event when an async event processor rejects', async () => { | ||
| await createRunner(__dirname, 'scenario-async.ts') | ||
| .unignore('client_report') | ||
| .expect({ | ||
| client_report: { | ||
| discarded_events: [ | ||
| { | ||
| category: 'error', | ||
| quantity: 1, | ||
| reason: 'event_processor', | ||
| }, | ||
| ], | ||
| }, | ||
| }) | ||
| .start() | ||
| .completed(); | ||
| }); |
19 changes: 19 additions & 0 deletions
19
...ation-tests/suites/client-reports/drop-reasons/traces-sampler-throws/scenario-fallback.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,19 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
|
|
||
| Sentry.init({ | ||
| traceLifecycle: 'static', | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| transport: loggingTransport, | ||
| tracesSampleRate: 1, | ||
| tracesSampler: () => { | ||
| throw new Error('tracesSampler failed'); | ||
| }, | ||
| }); | ||
|
|
||
| Sentry.startSpan({ name: 'sampled via tracesSampleRate fallback' }, () => { | ||
| // no-op | ||
| }); | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
| Sentry.flush(); |
17 changes: 17 additions & 0 deletions
17
...de-integration-tests/suites/client-reports/drop-reasons/traces-sampler-throws/scenario.ts
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. l: can we add a test what happens when we set |
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,17 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| transport: loggingTransport, | ||
| tracesSampler: () => { | ||
| throw new Error('tracesSampler failed'); | ||
| }, | ||
| }); | ||
|
|
||
| Sentry.startSpan({ name: 'this should not be sampled because tracesSampler throws' }, () => { | ||
| // no-op | ||
| }); | ||
|
|
||
| // eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
| Sentry.flush(); |
35 changes: 35 additions & 0 deletions
35
...s/node-integration-tests/suites/client-reports/drop-reasons/traces-sampler-throws/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,35 @@ | ||
| import { afterAll, test } from 'vitest'; | ||
| import { cleanupChildProcesses, createRunner } from '../../../../utils/runner'; | ||
|
|
||
| afterAll(() => { | ||
| cleanupChildProcesses(); | ||
| }); | ||
|
|
||
| test('records a client report and no error event when tracesSampler throws', async () => { | ||
| await createRunner(__dirname, 'scenario.ts') | ||
| .unignore('client_report') | ||
| .expect({ | ||
| client_report: { | ||
| discarded_events: [ | ||
| { | ||
| category: 'span', | ||
| quantity: 1, | ||
| reason: 'sample_rate', | ||
| }, | ||
| ], | ||
| }, | ||
| }) | ||
| .start() | ||
| .completed(); | ||
| }); | ||
|
|
||
| test('sends the span when tracesSampler throws but tracesSampleRate is 1', async () => { | ||
| await createRunner(__dirname, 'scenario-fallback.ts') | ||
| .expect({ | ||
| transaction: { | ||
| transaction: 'sampled via tracesSampleRate fallback', | ||
| }, | ||
| }) | ||
| .start() | ||
| .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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could also have a second scenario where we throw in an async event processor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes good idea, added 👍