Skip to content

fix(node): Check if router exists before it is instrumented #5502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/tracing/src/integrations/node/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 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
`app.router` instead of `app._router`.
@see https://github.com/pillarjs/router
Comment on lines +267 to +271
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn this kinda sucks. Maybe another reason to have an express package?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, probably. Let's chat about this at Daily/planning today 👍


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;
Expand Down