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: correctly disable Express instrumentation #972

Merged
merged 2 commits into from
Apr 15, 2022

Conversation

nwalters512
Copy link
Contributor

Which problem is this PR solving?

Fixes #970.

Short description of the changes

I changed from calling this._unwrap with moduleExports.Router.prototype to calling it with module.Router. This is consistent with how we call this._wrap.

While investigating this, I discovered that the existing test for disabling was broken. It never actually called instrumentation.disable(), and in fact, calling instrumentation.disable() did not produce any change in the test's behavior. I changed the test to use the serverWithMiddleware, which AFAICT is necessary for the instrumentation to produce any spans. The test now fails as expected if you remove the instrumentation.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

  • Ran npm run test-all-versions for the edited package(s) on the latest commit if applicable.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Apr 12, 2022

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: nwalters512 / name: Nathan Walters (43e8a7b)

@nwalters512 nwalters512 reopened this Apr 12, 2022
Comment on lines +291 to +297
const customMiddleware: express.RequestHandler = (req, res, next) => {
for (let i = 0; i < 1000; i++) {
continue;
}
return next();
};
app.use(customMiddleware);
Copy link
Contributor Author

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.

Copy link
Member

@rauno56 rauno56 Apr 13, 2022

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.

@nwalters512 nwalters512 marked this pull request as ready for review April 12, 2022 21:50
@nwalters512 nwalters512 requested a review from a team April 12, 2022 21:50
@codecov
Copy link

codecov bot commented Apr 12, 2022

Codecov Report

Merging #972 (e8626fe) into main (baaacbd) will increase coverage by 0.58%.
The diff coverage is 100.00%.

@@            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     
Impacted Files Coverage Δ
...try-instrumentation-express/src/instrumentation.ts 99.25% <100.00%> (ø)
...opentelemetry-instrumentation-express/src/types.ts 100.00% <0.00%> (ø)
...nstrumentation-express/src/enums/AttributeNames.ts 100.00% <0.00%> (ø)
...opentelemetry-instrumentation-express/src/utils.ts 97.36% <0.00%> (ø)
...tapackages/auto-instrumentations-node/src/utils.ts 97.91% <0.00%> (ø)
...trumentation-express/src/enums/ExpressLayerType.ts 100.00% <0.00%> (ø)

@rauno56 rauno56 changed the title fix: Correctly disable Express instrumentation fix: correctly disable Express instrumentation Apr 13, 2022
Copy link
Member

@dyladan dyladan left a 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.

@vmarchaud vmarchaud merged commit b55b79b into open-telemetry:main Apr 15, 2022
@dyladan dyladan mentioned this pull request Apr 15, 2022
@nwalters512 nwalters512 deleted the fix-express-disable branch January 19, 2023 17:41
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.

"no function to unwrap" logged when disabling Express instrumentation
4 participants