Skip to content

feat(node): Use diagnostics channel for Fastify v5 error handling #16715

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

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

onurtemizkan
Copy link
Collaborator

Resolves: #15936

Copy link
Contributor

github-actions bot commented Jun 24, 2025

size-limit report 📦

Path Size % Change Change
@sentry/browser 23.99 kB - -
@sentry/browser - with treeshaking flags 23.76 kB - -
@sentry/browser (incl. Tracing) 38.84 kB - -
@sentry/browser (incl. Tracing, Replay) 76.98 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 70.07 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 81.74 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 93.83 kB - -
@sentry/browser (incl. Feedback) 40.75 kB - -
@sentry/browser (incl. sendFeedback) 28.7 kB - -
@sentry/browser (incl. FeedbackAsync) 33.59 kB - -
@sentry/react 25.76 kB - -
@sentry/react (incl. Tracing) 40.84 kB - -
@sentry/vue 28.36 kB - -
@sentry/vue (incl. Tracing) 40.7 kB - -
@sentry/svelte 24.01 kB - -
CDN Bundle 25.5 kB - -
CDN Bundle (incl. Tracing) 38.92 kB - -
CDN Bundle (incl. Tracing, Replay) 74.83 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 80.29 kB - -
CDN Bundle - uncompressed 74.5 kB - -
CDN Bundle (incl. Tracing) - uncompressed 115.42 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 229.47 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 242.3 kB - -
@sentry/nextjs (client) 42.47 kB - -
@sentry/sveltekit (client) 39.33 kB - -
@sentry/node 151.07 kB +0.14% +198 B 🔺
@sentry/node - without tracing 98.63 kB - -
@sentry/aws-serverless 124.4 kB +0.01% +1 B 🔺

View base workflow run

@onurtemizkan onurtemizkan force-pushed the onur/fastify-diag-error-handling branch from 53d3aac to 134bf84 Compare June 24, 2025 10:41
}
});

if (fastify.version?.startsWith('5.')) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This will break for > v5!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was intentional, just in case Fastify v6 uses a different diagnostics channel hook for errors when published. It won't break if 6.x is used here, in the worst scenario, the error will be captured twice, and deduped eventually.

Copy link
Member

Choose a reason for hiding this comment

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

I'd rather we check if our tracing:fastify.request.handler:error diagnostics channel listener was registered, that feels like a more robust check.

I guess this is hard because others can also register on tracing:fastify.request.handler:error. Perhaps we can do this by setting a field on the integration? Then you can grab the current client fastify integration instance and check.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I have just tried that. Looks like it's a bit tricky because dc.subscribe does not return anything (we don't know if it subscribed or not at instrumentation time. If the hook is not found, it fails silently). We can set a flag in dc hook when an error happens, but the error handler plugin will be registered already, then we can maybe unregister it. Wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

We can set a flag in dc hook when an error happens, but the error handler plugin will be registered already, then we can maybe unregister it

yeah lets give this a try

Copy link
Member

@andreiborza andreiborza left a comment

Choose a reason for hiding this comment

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

Nice work! Need to think of how to document this best but this looks good.

Sign up for free to 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.

Automatic error handler setup for Fastify v5
4 participants