Skip to content

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

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix tests
  • Loading branch information
Vovcharaa committed May 19, 2025
commit 7475099175c25d50cf92456c3511fdda6a6ae520
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ describe('mongoose instrumentation [common]', () => {
});
},
});
instrumentation.enable();
await loadUsers();
await User.createIndexes();
instrumentation.enable();
});

afterEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ describe('mongoose instrumentation [v5/v6]', () => {
});
},
});
instrumentation.enable();
await loadUsers();
await User.createIndexes();
instrumentation.enable();
});

afterEach(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ describe('mongoose instrumentation [v7/v8]', () => {
});
},
});
instrumentation.enable();
await loadUsers();
await User.createIndexes();
instrumentation.enable();
});

afterEach(async () => {
Expand Down
42 changes: 20 additions & 22 deletions plugins/node/instrumentation-mongoose/test/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,25 @@ const User = mongoose.model<IUser>('User', UserSchema);
export default User;

export const loadUsers = async () => {
await context.with(suppressTracing(context.active()), async () => {
await User.insertMany([
new User({
firstName: 'John',
lastName: 'Doe',
email: '[email protected]',
age: 18,
}),
new User({
firstName: 'Jane',
lastName: 'Doe',
email: '[email protected]',
age: 19,
}),
new User({
firstName: 'Michael',
lastName: 'Fox',
email: '[email protected]',
age: 16,
}),
]);
});
await User.insertMany([
new User({
firstName: 'John',
lastName: 'Doe',
email: '[email protected]',
age: 18,
}),
new User({
firstName: 'Jane',
lastName: 'Doe',
email: '[email protected]',
age: 19,
}),
new User({
firstName: 'Michael',
lastName: 'Fox',
email: '[email protected]',
age: 16,
}),
]);
await User.createIndexes();
};