From 01b589134c04ab12b861ba2334054718db4ac236 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Mon, 1 Aug 2022 14:34:16 +0200 Subject: [PATCH 1/2] fix(node): Check if router exists before it is instrumented --- .../tracing/src/integrations/node/express.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/tracing/src/integrations/node/express.ts b/packages/tracing/src/integrations/node/express.ts index 7e6037f9866a..3f4112132031 100644 --- a/packages/tracing/src/integrations/node/express.ts +++ b/packages/tracing/src/integrations/node/express.ts @@ -259,6 +259,24 @@ function instrumentRouter(appOrRouter: ExpressRouter): void { } const router = isApp ? appOrRouter._router : appOrRouter; + + if (!router) { + /* + If we end up here, this means likely that this integration is used with Express 3 or Express 5. + For now, we don't support these version (3 is very old and 5 is still in beta). To support Express 5, + we'd need to make more changes to the routing instrumentation because the router is no longer part of + the Express core package but maintained in its own package. The new router has different function + signatures and works slightly differently, demanding more changes than just taking the router from + `app.router` instead of `app._router`. + @see https://github.com/pillarjs/router + + TODO: Proper Express 5 support + */ + __DEBUG_BUILD__ && logger.debug('Cannot instrument router for URL Parameterization (did not find a valid router).'); + __DEBUG_BUILD__ && logger.debug('Routing instrumentation is currently only supported in Express 4.'); + return; + } + const routerProto = Object.getPrototypeOf(router) as ExpressRouter; const originalProcessParams = routerProto.process_params; From 8a14312be1d15ac688a2e4c06bf64d7ce0976602 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Mon, 1 Aug 2022 14:59:16 +0200 Subject: [PATCH 2/2] Update packages/tracing/src/integrations/node/express.ts Co-authored-by: Luca Forstner --- packages/tracing/src/integrations/node/express.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/tracing/src/integrations/node/express.ts b/packages/tracing/src/integrations/node/express.ts index 3f4112132031..a211dc279e28 100644 --- a/packages/tracing/src/integrations/node/express.ts +++ b/packages/tracing/src/integrations/node/express.ts @@ -263,7 +263,7 @@ function instrumentRouter(appOrRouter: ExpressRouter): void { if (!router) { /* If we end up here, this means likely that this integration is used with Express 3 or Express 5. - For now, we don't support these version (3 is very old and 5 is still in beta). To support Express 5, + For now, we don't support these versions (3 is very old and 5 is still in beta). To support Express 5, we'd need to make more changes to the routing instrumentation because the router is no longer part of the Express core package but maintained in its own package. The new router has different function signatures and works slightly differently, demanding more changes than just taking the router from