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.
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
fix(instr-express): keep hidden properties in layer handlers #2137
Changes from 8 commits
7152206
82b4b83
e35bc7b
04d2918
cb556b4
e0fb92e
8f2f66c
261b756
20d765c
618e80b
686c669
49fd215
aa93499
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
While I understand the purpose of what we're trying to achieve, the error that comes up here feels very relevant and makes me wonder if there's a better way to do 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.
@JamieDanielson
Thanks for your review :)
For "better" you meant at the type level or you think the usage of
Object.defineProperty
is not a good solution? I'll put my thoughts on both.Type error
The type error we get is:
The internal typings define the
handle
property of the layer as a Function. I've also checked@types/express
to see if we can get the type from there but the router stack (where the layers are stored) is defines asany[]
. So at the time of writing it adding comment to highlight express is "leveraging" the Object nature of functions to hide metadata felt the right thing to do. Note: the type error also arises with @blumamir's proposal since its a type level error.We may get rid of the error by doing some improvements in the internal types so the compiler will know the function being patched is also used as a record. Something like the type below should work.
Object.defineProperty vs copy
Doing the shallow copy proposed by @blumamir fixes this issue as well but those properties represents the state of the layer. If that state is modified for the
handler
to change it's behaviour the original one will not notice that change and keep behaving according the original state (before the copy). WithdefineProperty
we keep patched and original in sync (sharing state) so the instrumentation will not interfere with any code accessing or changing the state.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.
Ooh, that sounds like a good idea to use that new
HandlerType
. Would you be open to adding that intointernal-types
, and using that instead of ignoring the TypeScript error?Also thank you for the detailed explanation, that helps me understand much better!
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 support doing 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'll update the types :)
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.
Done @JamieDanielson :)
Check warning on line 324 in plugins/node/opentelemetry-instrumentation-express/src/instrumentation.ts
Codecov / codecov/patch
plugins/node/opentelemetry-instrumentation-express/src/instrumentation.ts#L324
Check warning on line 326 in plugins/node/opentelemetry-instrumentation-express/src/instrumentation.ts
Codecov / codecov/patch
plugins/node/opentelemetry-instrumentation-express/src/instrumentation.ts#L326