-
Notifications
You must be signed in to change notification settings - Fork 580
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,9 +74,8 @@ describe('mongoose instrumentation [common]', () => { | |
}); | ||
}, | ||
}); | ||
instrumentation.enable(); | ||
await loadUsers(); | ||
await User.createIndexes(); | ||
instrumentation.enable(); | ||
}); | ||
|
||
afterEach(async () => { | ||
|
@@ -321,6 +320,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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Added for insertMany. |
||
const documents = [ | ||
{ | ||
firstName: 'John', | ||
lastName: 'Doe', | ||
email: 'john.doe+1@example.com', | ||
}, | ||
{ | ||
firstName: 'Jane', | ||
lastName: 'Doe', | ||
email: 'jane.doe+1@example.com', | ||
}, | ||
]; | ||
await User.insertMany(documents); | ||
|
||
const spans = getTestSpans(); | ||
expect(spans.length).toBe(1); | ||
assertSpan(spans[0] as ReadableSpan); | ||
expect(spans[0].attributes[SEMATTRS_DB_OPERATION]).toBe('insertMany'); | ||
const statement = getStatement(spans[0] as ReadableSpan); | ||
expect(statement.documents).toEqual(documents); | ||
}); | ||
|
||
it('instrumenting bulkWrite operation', async () => { | ||
const operations = [ | ||
{ | ||
insertOne: { | ||
document: { | ||
firstName: 'Jane', | ||
lastName: 'Doe', | ||
email: 'jane.doe+2@example.com', | ||
age: 25, | ||
}, | ||
}, | ||
}, | ||
{ | ||
updateMany: { | ||
filter: { age: { $lte: 20 } }, | ||
update: { $set: { age: 20 } }, | ||
}, | ||
}, | ||
{ | ||
updateOne: { | ||
filter: { firstName: 'Jane' }, | ||
update: { $inc: { age: 1 } }, | ||
}, | ||
}, | ||
{ deleteOne: { filter: { firstName: 'Michael' } } }, | ||
{ | ||
updateOne: { | ||
filter: { firstName: 'Zara' }, | ||
update: { | ||
$set: { lastName: 'Doe', age: 40, email: 'zara@example.com' }, | ||
}, | ||
upsert: true, | ||
}, | ||
}, | ||
]; | ||
await User.bulkWrite(operations); | ||
|
||
const spans = getTestSpans(); | ||
expect(spans.length).toBe(1); | ||
assertSpan(spans[0] as ReadableSpan); | ||
expect(spans[0].attributes[SEMATTRS_DB_OPERATION]).toBe('bulkWrite'); | ||
const statement = getStatement(spans[0] as ReadableSpan); | ||
expect(statement.operations).toEqual([ | ||
{ | ||
insertOne: { | ||
document: { | ||
firstName: 'Jane', | ||
lastName: 'Doe', | ||
email: 'jane.doe+2@example.com', | ||
age: 25, | ||
}, | ||
}, | ||
}, | ||
{ | ||
updateMany: { | ||
filter: { age: { $lte: 20 } }, | ||
update: { $set: { age: 20 } }, | ||
}, | ||
}, | ||
{ | ||
updateOne: { | ||
filter: { firstName: 'Jane' }, | ||
update: { $inc: { age: 1 } }, | ||
}, | ||
}, | ||
{ deleteOne: { filter: { firstName: 'Michael' } } }, | ||
{ | ||
updateOne: { | ||
filter: { firstName: 'Zara' }, | ||
update: { | ||
$set: { lastName: 'Doe', age: 40, email: 'zara@example.com' }, | ||
}, | ||
upsert: true, | ||
}, | ||
}, | ||
]); | ||
}); | ||
|
||
it('instrumenting aggregate operation', async () => { | ||
await User.aggregate([ | ||
{ $match: { firstName: 'John' } }, | ||
|
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 thetype
property and a specific type per opration inpayload
. This way we provide some hints to the devs who want to implement a serializerCheck this small example in TS playground.