Skip to content
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

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

Merged
merged 2 commits into from Aug 1, 2022

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented Aug 1, 2022

This PR hotfixes a problem in our router instrumentation introduced in #5450 which would cause Express 5 Node apps to crash on startup. Because the internals of Express 5 (which is still in beta) have changed quite a bit compared to Express 4, there is unfortunately no quick way of supporting the new version in our current router instrumentation.

Therefore, this PR simply checks if the router we retrieve from Express 4 apps (which we get from app._router) exists. In case it does, we can patch it; in case it doesn't, we know that the integration is either used with Express 3 or 5. In both cases, we early return and do not patch the router.

We can revisit adding proper support for early URL parameterization of Express 5 apps but for now, this PR will unblock Express 5 users by skipping instrumentation. This means that for Express 5, we fall back to our old way of instrumenting routes (which means we get paramterized routes for transaction names but only after the route handler was executed and the transaction is finished).

fixes #5501

@Lms24 Lms24 requested review from lforst and AbhiPrasad August 1, 2022 12:46
@github-actions
Copy link
Contributor

github-actions bot commented Aug 1, 2022

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.35 KB (-0.02% 🔽)
@sentry/browser - ES5 CDN Bundle (minified) 59.92 KB (0%)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 17.93 KB (-0.01% 🔽)
@sentry/browser - ES6 CDN Bundle (minified) 52.79 KB (0%)
@sentry/browser - Webpack (gzipped + minified) 19.69 KB (0%)
@sentry/browser - Webpack (minified) 64.13 KB (0%)
@sentry/react - Webpack (gzipped + minified) 19.71 KB (0%)
@sentry/nextjs Client - Webpack (gzipped + minified) 44.11 KB (0%)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 25.76 KB (-0.01% 🔽)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 24.01 KB (-0.02% 🔽)

packages/tracing/src/integrations/node/express.ts Outdated Show resolved Hide resolved
Comment on lines +267 to +271
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
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 👍

Co-authored-by: Luca Forstner <luca.forstner@sentry.io>
@Lms24 Lms24 enabled auto-merge (squash) August 1, 2022 13:01
Lms24 added a commit that referenced this pull request Aug 1, 2022
@Lms24 Lms24 merged commit 0b86dd8 into master Aug 1, 2022
@Lms24 Lms24 deleted the lms-express5-router branch August 1, 2022 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeError: Cannot convert undefined or null to object
2 participants