-
Notifications
You must be signed in to change notification settings - Fork 539
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: correctly disable Express instrumentation #972
fix: correctly disable Express instrumentation #972
Conversation
|
const customMiddleware: express.RequestHandler = (req, res, next) => { | ||
for (let i = 0; i < 1000; i++) { | ||
continue; | ||
} | ||
return next(); | ||
}; | ||
app.use(customMiddleware); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we could further simplify this test by removing this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's here to ensure that the instrumentation is also disabled on the app level, not only router level.
Treating Express as a black box and keeping at least one of those middleware makes sense imho.
Codecov Report
@@ Coverage Diff @@
## main #972 +/- ##
==========================================
+ Coverage 95.91% 96.50% +0.58%
==========================================
Files 13 19 +6
Lines 856 1086 +230
Branches 178 230 +52
==========================================
+ Hits 821 1048 +227
- Misses 35 38 +3
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Can go either way on the customMiddleware test in the disable.
Which problem is this PR solving?
Fixes #970.
Short description of the changes
I changed from calling
this._unwrap
withmoduleExports.Router.prototype
to calling it withmodule.Router
. This is consistent with how we callthis._wrap
.While investigating this, I discovered that the existing test for disabling was broken. It never actually called
instrumentation.disable()
, and in fact, callinginstrumentation.disable()
did not produce any change in the test's behavior. I changed the test to use theserverWithMiddleware
, which AFAICT is necessary for the instrumentation to produce any spans. The test now fails as expected if you remove theinstrumentation.disable()
that I added.While comparing tests, I realized that the
should create a child span for middlewares
test has some unused, unnecessary code. I opted to remove that too, though I'd be happy to shift that to another PR if preferred.Checklist
npm run test-all-versions
for the edited package(s) on the latest commit if applicable.