@@ -10,52 +10,46 @@ import {
1010 spanToJSON ,
1111} from '@sentry/core' ;
1212import type { IntegrationFn , Span } from '@sentry/core' ;
13- import { generateInstrumentOnce } from '../../otel/instrument' ;
14- import { FastifyInstrumentationV3 } from './fastify- v3/instrumentation' ;
13+ import { generateInstrumentOnce } from '../../../ otel/instrument' ;
14+ import { FastifyInstrumentationV3 } from './v3/instrumentation' ;
1515import * as diagnosticsChannel from 'node:diagnostics_channel' ;
16- import type { FastifyInstance } from './fastify-v3/internal-types' ;
17- import { DEBUG_BUILD } from '../../debug-build' ;
18-
19- /**
20- * Minimal request type containing properties around route information.
21- * Works for Fastify 3, 4 and presumably 5.
22- *
23- * Based on https://github.com/fastify/fastify/blob/ce3811f5f718be278bbcd4392c615d64230065a6/types/request.d.ts
24- */
25- // eslint-disable-next-line @typescript-eslint/no-explicit-any
26- interface MinimalFastifyRequest extends Record < string , any > {
27- method ?: string ;
28- 29- routeOptions ?: {
30- url ?: string ;
31- } ;
32- routerPath ?: string ;
33- }
34-
35- /**
36- * Minimal reply type containing properties needed for error handling.
37- *
38- * Based on https://github.com/fastify/fastify/blob/ce3811f5f718be278bbcd4392c615d64230065a6/types/reply.d.ts
39- */
40- // eslint-disable-next-line @typescript-eslint/no-explicit-any
41- interface MinimalFastifyReply extends Record < string , any > {
42- statusCode : number ;
43- }
44-
45- // We inline the types we care about here
46- interface Fastify {
47- // eslint-disable-next-line @typescript-eslint/no-explicit-any
48- register : ( plugin : any ) => void ;
49- addHook : ( hook : string , handler : ( ...params : unknown [ ] ) => void ) => void ;
50- }
51-
52- interface FastifyWithHooks extends Omit < Fastify , 'addHook' > {
53- addHook (
54- hook : 'onError' ,
55- handler : ( request : MinimalFastifyRequest , reply : MinimalFastifyReply , error : Error ) => void ,
56- ) : void ;
57- addHook ( hook : 'onRequest' , handler : ( request : MinimalFastifyRequest , reply : MinimalFastifyReply ) => void ) : void ;
58- }
16+ import { DEBUG_BUILD } from '../../../debug-build' ;
17+ import type { FastifyInstance , FastifyReply , FastifyRequest } from './types' ;
18+
19+ // /**
20+ // * Minimal request type containing properties around route information.
21+ // * Works for Fastify 3, 4 and presumably 5.
22+ // *
23+ // * Based on https://github.com/fastify/fastify/blob/ce3811f5f718be278bbcd4392c615d64230065a6/types/request.d.ts
24+ // */
25+ // // eslint-disable-next-line @typescript-eslint/no-explicit-any
26+ // interface MinimalFastifyRequest extends Record<string, any> {
27+ // method?: string;
28+ 29+ // routeOptions?: {
30+ // url?: string;
31+ // };
32+ // routerPath?: string;
33+ // }
34+
35+ // /**
36+ // * Minimal reply type containing properties needed for error handling.
37+ // *
38+ // * Based on https://github.com/fastify/fastify/blob/ce3811f5f718be278bbcd4392c615d64230065a6/types/reply.d.ts
39+ // */
40+ // // eslint-disable-next-line @typescript-eslint/no-explicit-any
41+ // interface MinimalFastifyReply extends Record<string, any> {
42+ // statusCode: number;
43+ // }
44+
45+ // // We inline the types we care about here
46+ // interface Fastify {
47+ // // eslint-disable-next-line @typescript-eslint/no-explicit-any
48+ // version: string;
49+ // register: (plugin: any) => Fastify;
50+ // after: (listener?: (err: Error) => void) => Fastify;
51+ // addHook: (name: string, handler: (...params: unknown[]) => void) => Fastify;
52+ // }
5953
6054interface FastifyHandlerOptions {
6155 /**
@@ -89,7 +83,7 @@ interface FastifyHandlerOptions {
8983 * });
9084 * ```
9185 */
92- shouldHandleError : ( error : Error , request : MinimalFastifyRequest , reply : MinimalFastifyReply ) => boolean ;
86+ shouldHandleError : ( error : Error , request : FastifyRequest , reply : FastifyReply ) => boolean ;
9387}
9488
9589const INTEGRATION_NAME = 'Fastify' ;
@@ -157,7 +151,7 @@ export const fastifyIntegration = defineIntegration(_fastifyIntegration);
157151 *
158152 * 3xx and 4xx errors are not sent by default.
159153 */
160- function defaultShouldHandleError ( _error : Error , _request : MinimalFastifyRequest , reply : MinimalFastifyReply ) : boolean {
154+ function defaultShouldHandleError ( _error : Error , _request : FastifyRequest , reply : FastifyReply ) : boolean {
161155 const statusCode = reply . statusCode ;
162156 // 3xx and 4xx errors are not sent by default.
163157 return statusCode >= 500 || statusCode <= 299 ;
@@ -183,11 +177,11 @@ function defaultShouldHandleError(_error: Error, _request: MinimalFastifyRequest
183177 * app.listen({ port: 3000 });
184178 * ```
185179 */
186- export function setupFastifyErrorHandler ( fastify : Fastify , options ?: Partial < FastifyHandlerOptions > ) : void {
180+ export function setupFastifyErrorHandler ( fastify : FastifyInstance , options ?: Partial < FastifyHandlerOptions > ) : void {
187181 const shouldHandleError = options ?. shouldHandleError || defaultShouldHandleError ;
188182
189183 const plugin = Object . assign (
190- function ( fastify : FastifyWithHooks , _options : unknown , done : ( ) => void ) : void {
184+ function ( fastify : FastifyInstance , _options : unknown , done : ( ) => void ) : void {
191185 fastify . addHook ( 'onError' , async ( request , reply , error ) => {
192186 if ( shouldHandleError ( error , request , reply ) ) {
193187 captureException ( error ) ;
0 commit comments