-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathmongo.ts
43 lines (38 loc) · 1.2 KB
/
mongo.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { MongoDBInstrumentation } from '@opentelemetry/instrumentation-mongodb';
import { defineIntegration } from '@sentry/core';
import type { IntegrationFn } from '@sentry/types';
import { generateInstrumentOnce } from '../../otel/instrument';
import { addOriginToSpan } from '../../utils/addOriginToSpan';
const INTEGRATION_NAME = 'Mongo';
export const instrumentMongo = generateInstrumentOnce(
INTEGRATION_NAME,
() =>
new MongoDBInstrumentation({
responseHook(span) {
addOriginToSpan(span, 'auto.db.otel.mongo');
},
}),
);
const _mongoIntegration = (() => {
return {
name: INTEGRATION_NAME,
setupOnce() {
instrumentMongo();
},
};
}) satisfies IntegrationFn;
/**
* Adds Sentry tracing instrumentation for the [mongodb](https://www.npmjs.com/package/mongodb) library.
*
* For more information, see the [`mongoIntegration` documentation](https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/mongo/).
*
* @example
* ```javascript
* const Sentry = require('@sentry/node');
*
* Sentry.init({
* integrations: [Sentry.mongoIntegration()],
* });
* ```
*/
export const mongoIntegration = defineIntegration(_mongoIntegration);