Skip to content

Commit c902df2

Browse files
committed
Check for '__sentry_fastify_wrapped__' prop in 'instrumentServer' mod
1 parent ce20bb4 commit c902df2

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

packages/remix/src/utils/instrumentServer.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ function makeWrappedDataFunction(
244244
manuallyInstrumented: boolean,
245245
): DataFunction {
246246
return async function (this: unknown, args: DataFunctionArgs): Promise<Response | AppData> {
247-
if (args.context.__sentry_express_wrapped__ && !manuallyInstrumented) {
247+
const alreadyWrapped = args.context.__sentry_express_wrapped__ || args.context.__sentry_fastify_wrapped__;
248+
if (alreadyWrapped && !manuallyInstrumented) {
248249
return origFn.call(this, args);
249250
}
250251

@@ -424,9 +425,9 @@ function wrapRequestHandler(origRequestHandler: RequestHandler, build: ServerBui
424425
const routes = createRoutes(build.routes);
425426

426427
return async function (this: unknown, request: RemixRequest, loadContext?: AppLoadContext): Promise<Response> {
427-
// This means that the request handler of the adapter (ex: express) is already wrapped.
428+
// This means that the request handler of the adapter (ex: express or fastify) is already wrapped.
428429
// So we don't want to double wrap it.
429-
if (loadContext?.__sentry_express_wrapped__) {
430+
if (loadContext?.__sentry_express_wrapped__ || loadContext?.__sentry_fastify_wrapped__) {
430431
return origRequestHandler.call(this, request, loadContext);
431432
}
432433

packages/remix/src/utils/vendor/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ export type RemixRequest = Request &
6565
agent: Agent | ((parsedURL: URL) => Agent) | undefined;
6666
};
6767

68-
export type AppLoadContext = Record<string, unknown> & { __sentry_express_wrapped__?: boolean };
68+
export type AppLoadContext = Record<string, unknown> & {
69+
__sentry_express_wrapped__?: boolean;
70+
__sentry_fastify_wrapped__?: boolean;
71+
};
6972
export type AppData = any;
7073
export type RequestHandler = (request: RemixRequest, loadContext?: AppLoadContext) => Promise<Response>;
7174
export type CreateRequestHandlerFunction = (this: unknown, build: ServerBuild, ...args: any[]) => RequestHandler;

0 commit comments

Comments
 (0)