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(instr-express): keep hidden properties in layer handlers #2137

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

david-luna
Copy link
Contributor

Which problem is this PR solving?

  • The original handle function of an express layer may contain certain metadata, specially in the router layer. When instrumentation does the "patch" the patched function does not have the same properties so any code relying on those props will find nothing. That may not be the case in express itself but 3rd party tools that look into that metadata are failing.

Fixes: #1950

Short description of the changes

  • The patched function now exposes same properties proxying the ones from the original handle function.
  • A test has been added to check the stack property is available for the router layer.

@david-luna david-luna requested a review from a team as a code owner April 22, 2024 17:19
@@ -165,8 +165,7 @@ export class ExpressInstrumentation extends InstrumentationBase<
) {
const route = original.apply(this, args);
const layer = this._router.stack[this._router.stack.length - 1];
instrumentation._applyPatch.call(
instrumentation,
instrumentation._applyPatch(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note for reviewer: this usage of Function.protptype.call comes from this commit 0723d06 as a new addition.

I did not dig further to get the original implementation but I think there is no need to use .call(...) since we have access to the container object and therefore calling _applyPatch with the right context.

Copy link

codecov bot commented Apr 22, 2024

Codecov Report

Attention: Patch coverage is 77.77778% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 90.45%. Comparing base (dfb2dff) to head (261b756).
Report is 108 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2137      +/-   ##
==========================================
- Coverage   90.97%   90.45%   -0.52%     
==========================================
  Files         146      149       +3     
  Lines        7492     7599     +107     
  Branches     1502     1591      +89     
==========================================
+ Hits         6816     6874      +58     
- Misses        676      725      +49     
Files Coverage Δ
...try-instrumentation-express/src/instrumentation.ts 98.61% <77.77%> (-1.39%) ⬇️

... and 35 files with indirect coverage changes

@david-luna
Copy link
Contributor Author

... will decrease coverage by 0.65%.

This is due to no tests are manipulating the hidden properties of the handle function of the layers. so the setter is not covered in the tests.

Screenshot 2024-04-23 at 10 18 27

I can remove the setter since until now not having the property at all was not breaking apps. But I think is a matter of time to get a new issue because of a lib trying to update those rops

Copy link
Member

@JamieDanielson JamieDanielson left a comment

Choose a reason for hiding this comment

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

Thanks @david-luna ! I will review this week. In the meantime can you run npm run lint:fix to update the lint errors?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Node - TypeError: Cannot read properties of undefined (reading 'forEach')
3 participants