-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathkafka.ts
45 lines (40 loc) · 1.29 KB
/
kafka.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
44
45
import { KafkaJsInstrumentation } from '@opentelemetry/instrumentation-kafkajs';
import { defineIntegration } from '@sentry/core';
import type { IntegrationFn } from '@sentry/types';
import { generateInstrumentOnce } from '../../otel/instrument';
import { addOriginToSpan } from '../../utils/addOriginToSpan';
const INTEGRATION_NAME = 'Kafka';
export const instrumentKafka = generateInstrumentOnce(
INTEGRATION_NAME,
() =>
new KafkaJsInstrumentation({
consumerHook(span) {
addOriginToSpan(span, 'auto.kafkajs.otel.consumer');
},
producerHook(span) {
addOriginToSpan(span, 'auto.kafkajs.otel.producer');
},
}),
);
const _kafkaIntegration = (() => {
return {
name: INTEGRATION_NAME,
setupOnce() {
instrumentKafka();
},
};
}) satisfies IntegrationFn;
/**
* Adds Sentry tracing instrumentation for the [kafkajs](https://www.npmjs.com/package/kafkajs) library.
*
* For more information, see the [`kafkaIntegration` documentation](https://docs.sentry.io/platforms/javascript/guides/node/configuration/integrations/kafka/).
*
* @example
* ```javascript
* const Sentry = require('@sentry/node');
*
* Sentry.init({
* integrations: [Sentry.kafkaIntegration()],
* });
*/
export const kafkaIntegration = defineIntegration(_kafkaIntegration);