Skip to content

Commit 61572bc

Browse files
feat: Mongoose tracing support added to MongoDB (#3252)
* Add flag to switch to mongoose as the wrapped mongo library
1 parent 7c03a77 commit 61572bc

File tree

1 file changed

+6
-3
lines changed
  • packages/tracing/src/integrations

1 file changed

+6
-3
lines changed

packages/tracing/src/integrations/mongo.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ interface MongoCollection {
8585
interface MongoOptions {
8686
operations?: Operation[];
8787
describeOperations?: boolean | Operation[];
88+
useMongoose?: boolean;
8889
}
8990

9091
/** Tracing integration for mongo package */
@@ -101,6 +102,7 @@ export class Mongo implements Integration {
101102

102103
private _operations: Operation[];
103104
private _describeOperations?: boolean | Operation[];
105+
private _useMongoose: boolean;
104106

105107
/**
106108
* @inheritDoc
@@ -110,19 +112,20 @@ export class Mongo implements Integration {
110112
? options.operations
111113
: ((OPERATIONS as unknown) as Operation[]);
112114
this._describeOperations = 'describeOperations' in options ? options.describeOperations : true;
115+
this._useMongoose = !!options.useMongoose;
113116
}
114117

115118
/**
116119
* @inheritDoc
117120
*/
118121
public setupOnce(_: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {
119122
let collection: MongoCollection;
120-
123+
const moduleName = this._useMongoose ? 'mongoose' : 'mongodb';
121124
try {
122-
const mongodbModule = dynamicRequire(module, 'mongodb') as { Collection: MongoCollection };
125+
const mongodbModule = dynamicRequire(module, moduleName) as { Collection: MongoCollection };
123126
collection = mongodbModule.Collection;
124127
} catch (e) {
125-
logger.error('Mongo Integration was unable to require `mongodb` package.');
128+
logger.error(`Mongo Integration was unable to require \`${moduleName}\` package.`);
126129
return;
127130
}
128131

0 commit comments

Comments
 (0)