Skip to content

Commit d2b5aa8

Browse files
committed
fix(node): Check if router exists before it is instrumented
1 parent d5298b5 commit d2b5aa8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

packages/tracing/src/integrations/node/express.ts

+16
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,22 @@ function instrumentRouter(appOrRouter: ExpressRouter): void {
259259
}
260260

261261
const router = isApp ? appOrRouter._router : appOrRouter;
262+
263+
if (!router) {
264+
/*
265+
If we end up here, this means likely that this integration is used with Express 3 or Express 5.
266+
For now, we don't support these version (3 is very old and 5 is still in beta). To support Express 5,
267+
we'd need to make more changes to the routing instrumentation because the router is no longer part of
268+
the Express core package but maintained in its own package. The new router has different function
269+
signatures and works slightly differently, demanding more changes than just taking the router from
270+
`app.router` instead of `app._router`.
271+
@see https://github.com/pillarjs/router
272+
*/
273+
__DEBUG_BUILD__ && logger.debug('Cannot instrument router for URL Parameterization (did not find a valid router).');
274+
__DEBUG_BUILD__ && logger.debug('Routing instrumentation is currently only supported in Express 4.');
275+
return;
276+
}
277+
262278
const routerProto = Object.getPrototypeOf(router) as ExpressRouter;
263279

264280
const originalProcessParams = routerProto.process_params;

0 commit comments

Comments
 (0)