-
Notifications
You must be signed in to change notification settings - Fork 577
feat(instrumentation-mongoose): add instrumentation of static methods #2748
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
feat(instrumentation-mongoose): add instrumentation of static methods #2748
Conversation
Hi @blumamir, |
Hi. |
Is there anyone who can review this? |
60804e1
to
cd106dc
Compare
Hi @Vovcharaa - @blumamir owns this component, they are the first contact point for reviews. Regardless, a few things that stand out from a high-level perspective:
|
Hi @pichlermarc |
cd106dc
to
62e5b65
Compare
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
Thank you for contributing this enhancement
please also update the new version range:
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2748 +/- ##
==========================================
- Coverage 89.69% 89.68% -0.02%
==========================================
Files 184 184
Lines 8966 9003 +37
Branches 1835 1845 +10
==========================================
+ Hits 8042 8074 +32
- Misses 924 929 +5
🚀 New features to boost your workflow:
|
bfac69d
to
edbb3ff
Compare
@pichlermarc @blumamir Could you pls allow tests to run? |
edbb3ff
to
979415c
Compare
@pichlermarc @blumamir, for some unknown reason, |
@pichlermarc As I see @blumamir quite rarely reviews PRs in this repo, could you, please, approve tests and merge this PR in case everything is good? This PR already has component owner approval. |
@@ -23,6 +23,8 @@ export interface SerializerPayload { | |||
document?: any; | |||
aggregatePipeline?: any; | |||
fields?: any; | |||
documents?: any; |
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.
(not for this PR): I guess the payload properties depend on the operation being serialized. This type and DbStatementSerializer
could be improved by using a union on the type
property and a specific type per opration in payload
. This way we provide some hints to the devs who want to implement a serializer
Check this small example in TS playground.
@@ -99,7 +99,7 @@ export class MongooseInstrumentation extends InstrumentationBase<MongooseInstrum | |||
protected init(): InstrumentationModuleDefinition { | |||
const module = new InstrumentationNodeModuleDefinition( | |||
'mongoose', | |||
['>=5.9.7 <9'], |
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.
the description of the PR states
Changed tested versions of mongoose because some older versions have weird timeouts with callbacks when suppressTracing is used in tests.
But here is actually dropping support for a range of versions (>=6 <6.7.5
) :(
What are exactly the test issues you're facing?
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 fixed one issue with callbacks when there are 3 args on these versions, but the issue with suppressTracing
remains on them.
If loadUsers
is called after instrumentation is enabled and is wrapped in suppressTracing
, spans in callback tests are not created (or ended).
@@ -321,6 +321,107 @@ describe('mongoose instrumentation [common]', () => { | |||
expect(statement.document).toEqual(expect.objectContaining(document)); | |||
}); | |||
|
|||
it('instrumenting insertMany operation', async () => { |
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.
There is not test with options or callback params. Is it possible to ad one test for these cases?
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.
Added for insertMany.
This helped identify the issue with versions that I dropped support for.
72c0f52
to
167682d
Compare
} else if (args.length === 3){ | ||
callbackArgumentIndex = 2; |
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 is the fix for insertMany/bulkWrite with callback and options.
It also fixed issues with older versions, which I previously dropped from support.
Which problem is this PR solving?
Currently Mongoose instrumentation does not track static methods like
insertMany
andbulkWrite
Short description of the changes
Added
patchModelStatic
to allow instrumentation of static model methods.Changed tested versions ofmongoose
because some older versions have weird timeouts with callbacks whensuppressTracing
is used in tests.Related issues
Fixes #2488