From 1d75bc1dfff7f47cd00c62d37e0854a072ba3a15 Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Tue, 15 Sep 2026 11:12:06 +0200 Subject: [PATCH 1/3] docs(fastify): Fix imports in error handler snippet The error handler page imported setupFastifyErrorHandler from @sentry/fastify, a package that does not exist, and called fastify() without importing it. Use the @sentry/node namespace import and import Fastify. Fixes SDK-1496 Co-Authored-By: Claude Opus 5 --- .../guides/fastify/features/error-handler.mdx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/platforms/javascript/guides/fastify/features/error-handler.mdx b/docs/platforms/javascript/guides/fastify/features/error-handler.mdx index af18d44139e9db..d7f365cae7f4cf 100644 --- a/docs/platforms/javascript/guides/fastify/features/error-handler.mdx +++ b/docs/platforms/javascript/guides/fastify/features/error-handler.mdx @@ -11,9 +11,9 @@ You can configure the error handler using the `setupFastifyErrorHandler` functio ```javascript import * as Sentry from "@sentry/node"; -import { setupFastifyErrorHandler } from "@sentry/fastify"; +import Fastify from "fastify"; -const app = fastify(); +const app = Fastify(); // Initialize Sentry Sentry.init({ @@ -21,7 +21,7 @@ Sentry.init({ }); // Setup the error handler -setupFastifyErrorHandler(app); +Sentry.setupFastifyErrorHandler(app); ``` ## Options @@ -41,7 +41,7 @@ declare function shouldHandleError( ``` ```javascript -setupFastifyErrorHandler(app, { +Sentry.setupFastifyErrorHandler(app, { shouldHandleError(error, request, reply) { return reply.statusCode >= 500 || reply.statusCode <= 399; }, @@ -53,7 +53,7 @@ If using TypeScript, you can cast the request and reply to get full type safety. ```typescript import { FastifyRequest, FastifyReply } from "fastify"; -setupFastifyErrorHandler(app, { +Sentry.setupFastifyErrorHandler(app, { shouldHandleError(error, minimalRequest, minimalReply) { const request = minimalRequest as FastifyRequest; const reply = minimalReply as FastifyReply; From 79e5360486405763b900e17f62994de753c63c5d Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Thu, 17 Sep 2026 13:41:18 +0200 Subject: [PATCH 2/3] docs(fastify): Configure shouldHandleError on fastifyIntegration The handler-level shouldHandleError option is deprecated since 10.x and is removed in 11.0.0. Document the option on fastifyIntegration, which applies to every supported Fastify version, and flag the deprecated form. Refs SDK-1496 --- .../guides/fastify/features/error-handler.mdx | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/docs/platforms/javascript/guides/fastify/features/error-handler.mdx b/docs/platforms/javascript/guides/fastify/features/error-handler.mdx index d7f365cae7f4cf..c098ed96765de1 100644 --- a/docs/platforms/javascript/guides/fastify/features/error-handler.mdx +++ b/docs/platforms/javascript/guides/fastify/features/error-handler.mdx @@ -26,11 +26,11 @@ Sentry.setupFastifyErrorHandler(app); ## Options -The `setupFastifyErrorHandler` function accepts an optional options object that can be used to customize the error handler. +`Sentry.fastifyIntegration` accepts the following options: - `shouldHandleError` _version 9.9.0+_ -A function that determines whether an error should be captured. +A function that determines whether an error should be captured. Set it on `fastifyIntegration()` so that it applies to every supported Fastify version. ```typescript declare function shouldHandleError( @@ -41,10 +41,15 @@ declare function shouldHandleError( ``` ```javascript -Sentry.setupFastifyErrorHandler(app, { - shouldHandleError(error, request, reply) { - return reply.statusCode >= 500 || reply.statusCode <= 399; - }, +Sentry.init({ + dsn: "your-dsn", + integrations: [ + Sentry.fastifyIntegration({ + shouldHandleError(error, request, reply) { + return reply.statusCode >= 500 || reply.statusCode <= 399; + }, + }), + ], }); ``` @@ -53,7 +58,7 @@ If using TypeScript, you can cast the request and reply to get full type safety. ```typescript import { FastifyRequest, FastifyReply } from "fastify"; -Sentry.setupFastifyErrorHandler(app, { +Sentry.fastifyIntegration({ shouldHandleError(error, minimalRequest, minimalReply) { const request = minimalRequest as FastifyRequest; const reply = minimalReply as FastifyReply; @@ -61,3 +66,9 @@ Sentry.setupFastifyErrorHandler(app, { }, }); ``` + + + +Passing `shouldHandleError` to `Sentry.setupFastifyErrorHandler` is deprecated and will be removed in version 11.0.0. Set the option on `Sentry.fastifyIntegration` instead. + + From 5e89064f0fb82a98e7406818d4427473df2acf58 Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Thu, 17 Sep 2026 14:09:25 +0200 Subject: [PATCH 3/3] docs(fastify): Document error capture on fastifyIntegration setupFastifyErrorHandler is a deprecated no-op in v11, so document the happy path only: errors are captured by the default-enabled fastifyIntegration, and shouldHandleError is configured on the integration. Refs SDK-1496 --- .../guides/fastify/features/error-handler.mdx | 49 ++++++------------- 1 file changed, 16 insertions(+), 33 deletions(-) diff --git a/docs/platforms/javascript/guides/fastify/features/error-handler.mdx b/docs/platforms/javascript/guides/fastify/features/error-handler.mdx index c098ed96765de1..43e3c0f8cf935e 100644 --- a/docs/platforms/javascript/guides/fastify/features/error-handler.mdx +++ b/docs/platforms/javascript/guides/fastify/features/error-handler.mdx @@ -1,36 +1,38 @@ --- title: Fastify Error Handler -description: "Learn about Sentry's Fastify SDK Error Handler and how to configure it." +description: "Learn how Sentry's Fastify integration captures errors and how to configure it." --- -The Fastify error handler integration automatically captures errors in your Fastify application and sends them to Sentry. By default, it captures all errors with status codes 5xx and above, as well as errors with status codes 2xx and below. +The `fastifyIntegration` captures errors in your Fastify application and sends them to Sentry. It's enabled by default, so you only need to add it to your `Sentry.init` call to configure it. + +By default, errors with status codes 5xx and above, as well as errors with status codes 2xx and below, are captured. Errors with 3xx and 4xx status codes aren't sent to Sentry. ## Configuration -You can configure the error handler using the `setupFastifyErrorHandler` function: +To control which errors are captured, pass `shouldHandleError` to `Sentry.fastifyIntegration`: ```javascript import * as Sentry from "@sentry/node"; -import Fastify from "fastify"; - -const app = Fastify(); -// Initialize Sentry Sentry.init({ dsn: "your-dsn", + integrations: [ + Sentry.fastifyIntegration({ + shouldHandleError(error, request, reply) { + return reply.statusCode >= 500; + }, + }), + ], }); - -// Setup the error handler -Sentry.setupFastifyErrorHandler(app); ``` ## Options `Sentry.fastifyIntegration` accepts the following options: -- `shouldHandleError` _version 9.9.0+_ +- `shouldHandleError` -A function that determines whether an error should be captured. Set it on `fastifyIntegration()` so that it applies to every supported Fastify version. +A function that determines whether an error should be captured. ```typescript declare function shouldHandleError( @@ -40,35 +42,16 @@ declare function shouldHandleError( ): boolean; ``` -```javascript -Sentry.init({ - dsn: "your-dsn", - integrations: [ - Sentry.fastifyIntegration({ - shouldHandleError(error, request, reply) { - return reply.statusCode >= 500 || reply.statusCode <= 399; - }, - }), - ], -}); -``` - If using TypeScript, you can cast the request and reply to get full type safety. ```typescript -import { FastifyRequest, FastifyReply } from "fastify"; +import type { FastifyRequest, FastifyReply } from "fastify"; Sentry.fastifyIntegration({ shouldHandleError(error, minimalRequest, minimalReply) { const request = minimalRequest as FastifyRequest; const reply = minimalReply as FastifyReply; - return reply.statusCode >= 500 || reply.statusCode <= 399; + return reply.statusCode >= 500; }, }); ``` - - - -Passing `shouldHandleError` to `Sentry.setupFastifyErrorHandler` is deprecated and will be removed in version 11.0.0. Set the option on `Sentry.fastifyIntegration` instead. - -