-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(node): Capture Express errors automatically via expressIntegration
#23464
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
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
55e28fc
feat(node): Capture Express errors automatically via `expressIntegrat…
mydea eab3719
fix(node): Parent captured Express errors to the layer span
mydea e416f86
fix tests
mydea eed35f7
wip tests
mydea 0de5fc7
test fixes
mydea 054cbb2
fixes
mydea c42ffe9
fix tests
mydea 0688da4
add to migration guide
mydea d4ca9db
Update MIGRATION.md
mydea aee661d
more tests
mydea 028c80f
more
mydea d72ff90
Update MIGRATION.md
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,4 +6,7 @@ Sentry.init({ | |
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| release: '1.0', | ||
| transport: loggingTransport, | ||
| // With tracing off, `expressIntegration()` is not a default integration, so opt in explicitly to | ||
| // get automatic error capture. | ||
|
Comment on lines
+9
to
+10
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. I think this is no longer true. Express integration is in the "framework" set, so it's on by default, tracing or no.
Member
Author
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. 👍 can you include in a follow up? |
||
| integrations: [Sentry.expressIntegration()], | ||
| }); | ||
13 changes: 13 additions & 0 deletions
13
...ges/node-integration-tests/suites/express/handle-error/instrument-setup-error-handler.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,13 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
|
|
||
| // Disable the channel-based `expressIntegration()` so the deprecated `setupExpressErrorHandler` | ||
| // middleware is the sole error capturer (mechanism `auto.middleware.express`) — the fallback for | ||
| // setups where the channel-based auto capture is unavailable. | ||
| Sentry.init({ | ||
| traceLifecycle: 'static', | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| release: '1.0', | ||
| transport: loggingTransport, | ||
| integrations: integrations => integrations.filter(integration => integration.name !== 'Express'), | ||
| }); |
16 changes: 16 additions & 0 deletions
16
...ges/node-integration-tests/suites/express/handle-error/instrument-should-handle-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,16 @@ | ||
| 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', | ||
| release: '1.0', | ||
| transport: loggingTransport, | ||
| integrations: [ | ||
| Sentry.expressIntegration({ | ||
| shouldHandleError: error => { | ||
| return error.message === 'error_2'; | ||
| }, | ||
| }), | ||
| ], | ||
| }); |
24 changes: 24 additions & 0 deletions
24
...e-integration-tests/suites/express/handle-error/scenario-setup-error-handler-fallback.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,24 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests'; | ||
| import cors from 'cors'; | ||
| import express from 'express'; | ||
|
|
||
| const app = express(); | ||
|
|
||
| app.use(cors()); | ||
|
|
||
| app.get('/test1', (_req, _res) => { | ||
| throw new Error('error_1'); | ||
| }); | ||
|
|
||
| app.get('/test2', (_req, _res) => { | ||
| throw new Error('error_2'); | ||
| }); | ||
|
|
||
| // With `expressIntegration` disabled (see the instrument file), the deprecated middleware is the sole | ||
| // capturer and its own `shouldHandleError` applies. | ||
| Sentry.setupExpressErrorHandler(app, { | ||
| shouldHandleError: error => error.message === 'error_2', | ||
| }); | ||
|
|
||
| startExpressServerAndSendPortToRunner(app); |
24 changes: 24 additions & 0 deletions
24
...kages/node-integration-tests/suites/express/handle-error/scenario-setup-error-handler.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,24 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { startExpressServerAndSendPortToRunner } from '@sentry-internal/node-integration-tests'; | ||
| import cors from 'cors'; | ||
| import express from 'express'; | ||
|
|
||
| const app = express(); | ||
|
|
||
| app.use(cors()); | ||
|
|
||
| app.get('/test1', (_req, _res) => { | ||
| throw new Error('error_1'); | ||
| }); | ||
|
|
||
| app.get('/test2', (_req, _res) => { | ||
| throw new Error('error_2'); | ||
| }); | ||
|
|
||
| // Deprecated, and here with a permissive (default) predicate that would capture both errors. But the | ||
| // channel-based `expressIntegration` (configured with `shouldHandleError: error_2` in the instrument) | ||
| // takes precedence: it is the single registered handler, so its predicate decides what is captured and | ||
| // this middleware must neither capture `error_1` nor double-capture `error_2`. | ||
| Sentry.setupExpressErrorHandler(app); | ||
|
|
||
| startExpressServerAndSendPortToRunner(app); |
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.
q: A lot of
parent_span_ids were added in the assertions. Was anything changed that this changed or was added?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 is more correct now then before I think, what has changed here is in what span context the error is captured, we ensure to capture this in the span context of the route handler now instead of in the separate middleware which should be better than before.