Skip to content

ref(node)!: Remove deprecated fastify exports, deprecate setupFastifyErrorHandler - #23460

Merged
mydea merged 22 commits into
developfrom
fn/streamline-fastify
Aug 27, 2026
Merged

ref(node)!: Remove deprecated fastify exports, deprecate setupFastifyErrorHandler#23460
mydea merged 22 commits into
developfrom
fn/streamline-fastify

Conversation

@mydea

@mydeamydea commented Aug 20, 2026

Copy link
Copy Markdown
Member

This consolidates the Fastify instrumentation onto a single, diagnostics-channel-based
fastifyIntegration and removes the deprecated/unneeded Fastify exports.

Node, Bun, and Elysia now use the channel-based fastifyIntegration from
@sentry/server-utils, and the old Node-specific integration (which wrapped the
OpenTelemetry Fastify instrumentation) is deleted. A single plugin now instruments
Fastify v3.21–v5, including error capture, so error handling no longer depends on
the Fastify version or on the user wiring anything up manually.

What changes for users

  • setupFastifyErrorHandler(app) is no longer required — errors are captured
    automatically once fastifyIntegration() is added. It is now deprecated and kept
    only as a thin shim that forwards a shouldHandleError callback to the integration.
  • shouldHandleError is configured directly on fastifyIntegration({ shouldHandleError })
    for all supported versions. Previously this only applied to v5, with v3/v4 going through
    setupFastifyErrorHandler.
  • Breaking: the deprecated instrumentFastify and handleFastifyError exports were
    removed. They are no longer needed now that the integration instruments and captures on
    its own.

Notable decisions

  • One channel-based plugin for all versions. Subscribing to Fastify's
    fastify.initialization / error diagnostics channels lets us instrument v3.21 → v5
    uniformly, without per-version branching and without asking users to register an error
    handler by hand.
  • Per-request error dedupe. On v5 the same route-handler error surfaces on both the
    diagnostics channel and the onError hook. Rather than leaning on captureException's
    error-object dedupe, we mark the request with a non-enumerable symbol once captured and
    bail out on the second path. Errors that reach only one path (thrown in an onRequest
    hook, or on v3/v4 which have no channel) are still captured exactly once.

Root cause note (instance patching)

The plugin is applied synchronously from the fastify.initialization channel rather
than via instance.register(). register() defers work to the boot phase (listen()/
ready()), but addHook runs immediately — so hooks a user adds synchronously before
listen() would otherwise slip through un-instrumented. Patching synchronously (the init
channel fires before Fastify() returns) ensures every hook is wrapped. The onError
hook is registered as an async hook so Fastify awaits it correctly and the error response
is not left hanging.

Tests

  • Dropped the separate app-handle-error-override.ts E2E apps and their
    playwright.override.config.mjs from the node-fastify-3/4/5 test apps.
  • Moved override coverage into node-integration-tests (scenario-error-handler.mjs),
    and added a no-tracing scenario plus a regression case for a hook added synchronously
    before listen().

Migration guide updated for both the setupFastifyErrorHandler deprecation and the
removed exports.

Comment threadpackages/server-utils/src/integrations/fastify/instrumentation.ts Outdated
@github-actions

github-actionsBot commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize% ChangeChange
@sentry/browser28.57 kB--
@sentry/browser - with treeshaking flags26.92 kB--
@sentry/browser - with treeshaking flags tracing without tracing26.82 kB--
@sentry/browser (incl. Tracing)48.61 kB--
@sentry/browser (incl. Tracing + Span Streaming)48.63 kB--
@sentry/browser (incl. Tracing, Profiling)51.54 kB--
@sentry/browser (incl. Tracing, Replay)88.1 kB--
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags77.48 kB--
@sentry/browser (incl. Tracing, Replay with Canvas)92.8 kB--
@sentry/browser (incl. Tracing, Replay, Feedback)105.48 kB--
@sentry/browser (incl. Feedback)45.79 kB--
@sentry/browser (incl. sendFeedback)33.35 kB--
@sentry/browser (incl. FeedbackAsync)38.46 kB--
@sentry/browser (incl. Metrics)29.51 kB--
@sentry/browser (incl. Logs)29.8 kB--
@sentry/browser (incl. Metrics & Logs)30.43 kB--
@sentry/react30.31 kB--
@sentry/react (incl. Tracing)50.82 kB--
@sentry/vue35.69 kB--
@sentry/vue (incl. Tracing)50.86 kB--
@sentry/svelte28.59 kB--
CDN Bundle30.36 kB--
CDN Bundle (incl. Tracing)49.09 kB--
CDN Bundle (incl. Logs, Metrics)32.56 kB--
CDN Bundle (incl. Tracing, Logs, Metrics)50.98 kB--
CDN Bundle (incl. Replay, Logs, Metrics)73 kB--
CDN Bundle (incl. Tracing, Replay)86.6 kB--
CDN Bundle (incl. Tracing, Replay, Logs, Metrics)88.5 kB--
CDN Bundle (incl. Tracing, Replay, Feedback)92.38 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics)94.3 kB--
CDN Bundle - uncompressed89.97 kB--
CDN Bundle (incl. Tracing) - uncompressed146.77 kB--
CDN Bundle (incl. Logs, Metrics) - uncompressed96.26 kB--
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed152.46 kB--
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed225.42 kB--
CDN Bundle (incl. Tracing, Replay) - uncompressed266.27 kB--
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed271.94 kB--
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed279.96 kB--
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed285.62 kB--
@sentry/nextjs (client)53.39 kB--
@sentry/sveltekit (client)49.05 kB--
@sentry/core/server65.3 kB--
@sentry/core/browser52.35 kB--
@sentry/node122.35 kB-0.3%-363 B 🔽
@sentry/node/import (ESM hook with diagnostics-channel injection)85.22 kB--
@sentry/node - without tracing87.67 kB-0.36%-312 B 🔽
@sentry/node - without channel injection102.05 kB-0.34%-340 B 🔽
@sentry/aws-serverless95.82 kB-0.38%-365 B 🔽
@sentry/cloudflare (withSentry) - minified199.57 kB--
@sentry/cloudflare (withSentry)495.71 kB--

View base workflow run

@mydea
mydea marked this pull request as ready for review August 20, 2026 10:53
@mydea
mydea requested review from a team as code ownersAugust 20, 2026 10:53
@mydea
mydea requested review from JPeer264, chargome, isaacs and s1gr1d and removed request for a teamAugust 20, 2026 10:53
Comment threadpackages/server-utils/src/integrations/fastify/errors.ts Outdated
@mydea
mydea marked this pull request as draft August 20, 2026 11:33
@mydea
mydeaforce-pushed the fn/streamline-fastify branch from 3004b8c to 3a04de5CompareAugust 20, 2026 13:37
@mydea
mydea marked this pull request as ready for review August 20, 2026 13:55
Comment threadpackages/server-utils/src/integrations/fastify/instrumentation.ts Outdated
@mydea
mydeaforce-pushed the fn/streamline-fastify branch from 3a04de5 to 07fbd58CompareAugust 21, 2026 09:50

@isaacsisaacs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found a few nits and questions/cleanup opportunities, mostly fairly low severity.

This is a really nice cleanup, very deep cuts. Love to see it!

The only blocking issue imo is that Fastify will silently not track errors anymore unless tracing is enabled, and requiring someone to specifically opt into the integration isn't meaningfully easier than requiring them to attach a custom error handler. I'd recommend just having it turned on all the time.

Also, there's some orphaned e2e test files that I think can be deleted:

  • dev-packages/e2e-tests/test-applications/node-fastify-3/playwright.override.config.mjs
  • dev-packages/e2e-tests/test-applications/node-fastify-4/playwright.override.config.mjs
  • dev-packages/e2e-tests/test-applications/node-fastify-5/playwright.override.config.mjs

Comment threadpackages/server-utils/src/integrations/fastify/errors.ts Outdated
Comment threadpackages/node/src/integrations/tracing/index.ts
Comment threadpackages/server-utils/src/integrations/fastify/instrumentation.ts Outdated
Comment threadpackages/server-utils/src/integrations/fastify/instrumentation.ts Outdated
Comment threadpackages/server-utils/src/integrations/fastify/errors.ts Outdated
Comment threadpackages/server-utils/src/integrations/fastify/instrumentation.ts Outdated
Comment threadpackages/server-utils/src/integrations/fastify/instrumentation.ts Outdated
Comment threadpackages/server-utils/src/integrations/fastify/index.ts Outdated
@mydea

Copy link
Copy Markdown
MemberAuthor

@isaacs I will go through your feedback in more details later, but I think the core thing should be handled here: #23473 - which is true, we need to ensure to always run this, even without performance, for this to make sense!

@s1gr1d

Copy link
Copy Markdown
Member

Just quickly cross-referencing this other Fastify PR here:

Comment threadpackages/server-utils/src/integrations/fastify/instrumentation.ts Outdated
@mydea
mydeaforce-pushed the fn/streamline-fastify branch from ffd446a to 3024abcCompareAugust 24, 2026 12:51
Comment threadpackages/server-utils/src/integrations/fastify/instrumentation.ts Outdated
@isaacs

Copy link
Copy Markdown
Member

@mydea

I think the core thing should be handled here: #23473

Ah! Yes, that does evaporate a lot of the comments here. Seems fine to dismiss that stuff then, and leave it for the next PR to address.

@mydea
mydeaforce-pushed the fn/streamline-fastify branch from 3024abc to 88fc5d8CompareAugust 26, 2026 07:18
@mydea
mydea requested a review from isaacsAugust 26, 2026 07:18

@cursorcursorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit d6cde9e. Configure here.

@isaacsisaacs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All concerns addressed! LGTM! 🚢

@mydea
mydeaforce-pushed the fn/streamline-fastify branch from d6cde9e to 95e8de1CompareAugust 27, 2026 06:57
@mydea
mydea merged commit 2325c8d into developAug 27, 2026
204 checks passed
@mydea
mydea deleted the fn/streamline-fastify branch August 27, 2026 07:13
s1gr1d added a commit that referenced this pull request Aug 27, 2026
Resolves conflicts with #23460, which consolidated Fastify onto a single
channel-based `fastifyIntegration` and moved everything out of
`packages/node/src/integrations/tracing/fastify/`.
Conflict resolutions (all modify/delete — upstream deletion accepted):
- The three e2e `app-handle-error-override.ts` apps: #23460 deleted them
and moved override coverage into node-integration-tests.
- `packages/node/src/integrations/tracing/fastify/index.ts`: deleted, the
integration now lives in `@sentry/server-utils`.
- `docs/migration/v11-end-state.md`: deleted by #23623, which folded the
guide into MIGRATION.md. The Fastify entries were ported there.
Reapplied on top: `setupFastifyErrorHandler` no longer accepts
`shouldHandleError`. After removing `setShouldHandleError`, forwarding the
option was the shim's only remaining job, so it is now a deprecated no-op
kept purely so existing `setupFastifyErrorHandler(app)` calls do not break.
The node-integration-test that covered the option was repointed at
`fastifyIntegration({ shouldHandleError })`.
Co-Authored-By: Opus 5 <noreply@anthropic.com>
s1gr1d added a commit that referenced this pull request Aug 31, 2026
…ndler` and `setupFasitfyErrorHandler` (#23734)
Express:
- #23732
- #23464
- #23763
Fastify:
- #23460
- #23464
- #23411
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@mydea@s1gr1d@isaacs@JPeer264