Skip to content

Commit b5b5f98

Browse files
committed
test(mongoose): use unique collections
1 parent 9e2aff8 commit b5b5f98

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

packages/instrumentation-mongoose/test/asserts.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ import {
2626
import { SpanStatusCode } from '@opentelemetry/api';
2727
import { SerializerPayload } from '../src';
2828
import { DB_NAME, MONGO_HOST, MONGO_PORT } from './config';
29+
import User from './user';
2930

3031
export const assertSpan = (span: ReadableSpan) => {
3132
expect(span.status.code).toBe(SpanStatusCode.UNSET);
3233
expect(span.attributes[SEMATTRS_DB_SYSTEM]).toEqual('mongoose');
33-
expect(span.attributes[SEMATTRS_DB_MONGODB_COLLECTION]).toEqual('users');
34+
expect(span.attributes[SEMATTRS_DB_MONGODB_COLLECTION]).toEqual(
35+
User.collection.name
36+
);
3437
expect(span.attributes[SEMATTRS_DB_NAME]).toEqual(DB_NAME);
3538
expect(span.attributes[SEMATTRS_NET_PEER_NAME]).toEqual(MONGO_HOST);
3639
expect(span.attributes[SEMATTRS_NET_PEER_PORT]).toEqual(MONGO_PORT);

packages/instrumentation-mongoose/test/user.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
import { Schema, Document } from 'mongoose';
1717
import * as mongoose from 'mongoose';
18+
import * as crypto from 'node:crypto';
1819

1920
export interface IUser extends Document {
2021
email: string;
@@ -31,7 +32,7 @@ const UserSchema: Schema = new Schema({
3132
});
3233

3334
// Export the model and return your IUser interface
34-
const User = mongoose.model<IUser>('User', UserSchema);
35+
const User = mongoose.model<IUser>(crypto.randomUUID() + 'User', UserSchema);
3536
export default User;
3637

3738
export const loadUsers = async () => {

0 commit comments

Comments
 (0)