Skip to content
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: Mongoose tracing support added to MongoDB #3252

Merged
merged 3 commits into from
Feb 17, 2021
Merged
Changes from all commits
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
9 changes: 6 additions & 3 deletions packages/tracing/src/integrations/mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ interface MongoCollection {
interface MongoOptions {
operations?: Operation[];
describeOperations?: boolean | Operation[];
useMongoose?: boolean;
}

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

private _operations: Operation[];
private _describeOperations?: boolean | Operation[];
private _useMongoose: boolean;

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

/**
* @inheritDoc
*/
public setupOnce(_: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {
let collection: MongoCollection;

const moduleName = this._useMongoose ? 'mongoose' : 'mongodb';
try {
const mongodbModule = dynamicRequire(module, 'mongodb') as { Collection: MongoCollection };
const mongodbModule = dynamicRequire(module, moduleName) as { Collection: MongoCollection };
collection = mongodbModule.Collection;
} catch (e) {
logger.error('Mongo Integration was unable to require `mongodb` package.');
logger.error(`Mongo Integration was unable to require \`${moduleName}\` package.`);
return;
}

Expand Down