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: mongodb async context fix #3657
fix: mongodb async context fix #3657
Changes from 9 commits
6437166
3f7d7e3
0e57880
d7ae1c0
f994ef0
9838d90
b67a5b1
629acd0
066de81
d5ac747
85e17d5
63abf30
1f863aa
527f669
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.
Note for reviewer: check the comment and give feedback please. Was okay to pass the new option? what about other instrumentations.
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.
We weren't using
internals: true
before the changes adding ESM support:so I don't think this is what internals is about. I'm not positive, however.
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.
internals: true
isn't needed if the sub-module path, e.g.@redis/client/dist/lib/client
, is an entry in the first argument toRitmHook
-- i.e. if it is on the explicit list of modules to hook into. If I add these debug-prints to RITM:and run examples/trace-redis.js:
The RITM
opts.internals
value is only used later for internal module paths that are not on the explicitly set of modules to hook.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 did not get those logs for
mongodb
and I think I know why. The last log inside./node_modules/require-in-the-middle/index.js
is inside a conditionalIn my case
The expression allows to pass sub-modules only if the root module is not in the whitelist. I this case the agent is instrumenting the main module and one sub-module. I think it works on
@redis
because its instrumention only sub-modules.I see two options here. Let me know what you think
internals
option.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'd prefer to avoid this. It will mean that we will be calling our
onRequire
hook function for every require'd file under each of the modules we instrument (every lib file in ioredis, in express, in fastify, etc.). There may be a perf impact of this.Option 3: Remove that limitation in RITM.
I think this is a bug in RITM that you cannot do this. Having 'mongodb' on the list of modules to patch shouldn't mean that you cannot patch
mongodb/lib/cmap/connection_pool
. I'll have to stare at this longer... the if/else's in RITM make my eyes swim a bit.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.
internals: true
and name our patches of sub-module files with the trailing.js
-- i.e.mongodb/lib/cmap/connection_pool.js
instead of without the.js
. I have started implementing this (along with implementing Allow Logical Grouping of Instrumentation by Name #2992 so thatdisableInstrumentations: 'mongodb'
would suffice to disable both instrumentation ofmongodb
andmongodb/lib/cmap/connection_pool.js
.I haven't finished this yet. There is also a potential hiccup in maintaining full support for https://www.elastic.co/guide/en/apm/agent/nodejs/current/agent-api.html#apm-add-patch I think it'll be fine.
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.
.js
extension. I've noticed our Hook is reading thepackage.json
file each time is called so enabling internals will do many reads. To avoid this I made use of aMap
to cache versions.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.
This PR solves our use case for instrumenting module and sub-module at the same time. which is what we need for
mongodb
.We still have to look at RITM but since the issue is only reported by us I think we have no rush.
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.
Note for reviewer: both RITM and IITM hooks use this function and will get cached result if they request many times the version for the same
pacakge.json
file