Skip to content

Commit 05e2692

Browse files
committed
kafkajs
1 parent d058fa8 commit 05e2692

File tree

3 files changed

+54
-57
lines changed

3 files changed

+54
-57
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as Sentry from '@sentry/node';
2+
import { loggingTransport } from '@sentry-internal/node-integration-tests';
3+
4+
Sentry.init({
5+
dsn: 'https://[email protected]/1337',
6+
release: '1.0',
7+
tracesSampleRate: 1.0,
8+
transport: loggingTransport,
9+
});

dev-packages/node-integration-tests/suites/tracing/kafkajs/scenario.js renamed to dev-packages/node-integration-tests/suites/tracing/kafkajs/scenario.mjs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
1-
const { loggingTransport } = require('@sentry-internal/node-integration-tests');
2-
const Sentry = require('@sentry/node');
3-
4-
Sentry.init({
5-
dsn: 'https://[email protected]/1337',
6-
release: '1.0',
7-
tracesSampleRate: 1.0,
8-
transport: loggingTransport,
9-
});
10-
111
// Stop the process from exiting before the transaction is sent
122
setInterval(() => {}, 1000);
133

14-
const { Kafka } = require('kafkajs');
4+
import { Kafka } from 'kafkajs';
155

166
async function run() {
177
const kafka = new Kafka({
@@ -54,10 +44,6 @@ async function run() {
5444
},
5545
],
5646
});
57-
58-
// Wait for the message to be received
59-
await new Promise(resolve => setTimeout(resolve, 5000));
6047
}
6148

62-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
6349
run();
Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,56 @@
1-
import { afterAll, describe, expect, test } from 'vitest';
2-
import { cleanupChildProcesses, createRunner } from '../../../utils/runner';
1+
import { afterAll, describe, expect } from 'vitest';
2+
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';
33

44
describe('kafkajs', () => {
55
afterAll(() => {
66
cleanupChildProcesses();
77
});
88

9-
test('traces producers and consumers', { timeout: 60_000 }, async () => {
10-
await createRunner(__dirname, 'scenario.js')
11-
.withDockerCompose({
12-
workingDirectory: [__dirname],
13-
readyMatches: ['9092'],
14-
})
15-
.expect({
16-
transaction: {
17-
transaction: 'test-topic',
18-
contexts: {
19-
trace: expect.objectContaining({
20-
op: 'message',
21-
status: 'ok',
22-
data: expect.objectContaining({
23-
'messaging.system': 'kafka',
24-
'messaging.destination': 'test-topic',
25-
'otel.kind': 'PRODUCER',
26-
'sentry.op': 'message',
27-
'sentry.origin': 'auto.kafkajs.otel.producer',
9+
createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createRunner, test) => {
10+
test('traces producers and consumers', { timeout: 60_000 }, async () => {
11+
await createRunner()
12+
.withDockerCompose({
13+
workingDirectory: [__dirname],
14+
readyMatches: ['9092'],
15+
})
16+
.expect({
17+
transaction: {
18+
transaction: 'test-topic',
19+
contexts: {
20+
trace: expect.objectContaining({
21+
op: 'message',
22+
status: 'ok',
23+
data: expect.objectContaining({
24+
'messaging.system': 'kafka',
25+
'messaging.destination': 'test-topic',
26+
'otel.kind': 'PRODUCER',
27+
'sentry.op': 'message',
28+
'sentry.origin': 'auto.kafkajs.otel.producer',
29+
}),
2830
}),
29-
}),
31+
},
3032
},
31-
},
32-
})
33-
.expect({
34-
transaction: {
35-
transaction: 'test-topic',
36-
contexts: {
37-
trace: expect.objectContaining({
38-
op: 'message',
39-
status: 'ok',
40-
data: expect.objectContaining({
41-
'messaging.system': 'kafka',
42-
'messaging.destination': 'test-topic',
43-
'otel.kind': 'CONSUMER',
44-
'sentry.op': 'message',
45-
'sentry.origin': 'auto.kafkajs.otel.consumer',
33+
})
34+
.expect({
35+
transaction: {
36+
transaction: 'test-topic',
37+
contexts: {
38+
trace: expect.objectContaining({
39+
op: 'message',
40+
status: 'ok',
41+
data: expect.objectContaining({
42+
'messaging.system': 'kafka',
43+
'messaging.destination': 'test-topic',
44+
'otel.kind': 'CONSUMER',
45+
'sentry.op': 'message',
46+
'sentry.origin': 'auto.kafkajs.otel.consumer',
47+
}),
4648
}),
47-
}),
49+
},
4850
},
49-
},
50-
})
51-
.start()
52-
.completed();
51+
})
52+
.start()
53+
.completed();
54+
});
5355
});
5456
});

0 commit comments

Comments
 (0)