fix(node): Check if router exists before it is instrumented#5502
Merged
fix(node): Check if router exists before it is instrumented#5502
Conversation
d2b5aa8 to
01b5891
Compare
Contributor
size-limit report 📦
|
lforst
approved these changes
Aug 1, 2022
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 |
Contributor
There was a problem hiding this comment.
Damn this kinda sucks. Maybe another reason to have an express package?
Member
Author
There was a problem hiding this comment.
Yup, probably. Let's chat about this at Daily/planning today 👍
Co-authored-by: Luca Forstner <luca.forstner@sentry.io>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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