feat(node): Capture Express errors automatically via expressIntegration - #23464
Draft
mydea wants to merge 2 commits into
Draft
feat(node): Capture Express errors automatically via expressIntegration#23464mydea wants to merge 2 commits into
expressIntegration#23464mydea wants to merge 2 commits into
Conversation
…ion` `expressIntegration()` now captures errors thrown from route handlers on its own, at the throw site (before user error-handling middleware runs), gated by a new `shouldHandleError` option. Passing `shouldHandleError: false` opts out entirely. This moves Express error capture into `@sentry/server-utils` (alongside the channel-based tracing) and deprecates the now-superseded core Express exports (`setupExpressErrorHandler`, `expressErrorHandler`, `patchExpressModule` and the related types), to be removed in the next major. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 0e8547a. Configure here.
Contributor
size-limit report 📦
|
The channel `error` event runs outside the layer span's async context, so `captureException` was recording events with no `parent_span_id`. Re-activate the span bound by `bindTracingChannelToSpan` (now typed on `HandleChannelContext`) around the capture so the error event is parented to the request's trace. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

expressIntegration()now captures errors thrown from Express route handlers automatically, sosetupExpressErrorHandler(app)is no longer needed. Capture happens on the routing layer'shandle_requestdiagnostics channel — i.e. at the throw site, before any user error-handling middleware runs — and is gated by a newshouldHandleErroroption on the integration.shouldHandleError(error) => boolean→ custom gate.false→ disables Sentry's automatic capture entirely. Use this as an escape hatch when you want to capture errors yourself viaSentry.captureExceptionfrom your own middleware.The option is passed into the instrumentation directly (not read back from the integration instance), matching the approach used for Fastify/Hapi.
Why this shape
setupExpressErrorHandler— are collapsed bycaptureException's per-object__sentry_captured__dedup, so only one event is sent.next('route')/next('router')control-flow signals are filtered out so they aren't mistaken for errors.shouldHandleErrorsees the error as thrown (its own status), not a final response status — this is intentional and matches the other framework integrations.Deprecations
The core Express exports are now superseded by
expressIntegration()and are unused internally. They are deprecated and will be removed in the next major:setupExpressErrorHandler,expressErrorHandler,patchExpressModule, and the typesExpressIntegrationOptions,ExpressHandlerOptions,ExpressMiddleware,ExpressErrorMiddleware. Downstream re-exports keep working (lint suppressed at the re-export sites) and surface the deprecation via TypeScript.Behavior change
Express errors are now captured without
setupExpressErrorHandler, and the resulting mechanism type isauto.http.express(the channel wins over the deprecated middleware, which is deduped). Existing e2e/integration assertions were updated accordingly.shouldHandleErrorpassed to the deprecatedsetupExpressErrorHandlerno longer takes effect — configure it onexpressIntegration()instead.A migration guide entry is included.