-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtest.ts
More file actions
86 lines (77 loc) · 3.13 KB
/
test.ts
File metadata and controls
86 lines (77 loc) · 3.13 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import type { TransactionEvent } from '@sentry/core';
import { afterAll, describe, expect } from 'vitest';
import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner';
describe('kafkajs', () => {
afterAll(() => {
cleanupChildProcesses();
});
createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createRunner, test) => {
test('traces producers and consumers', { timeout: 60_000 }, async () => {
// The producer and consumer transactions can arrive in any order,
// so we collect them and assert after both have been received.
const receivedTransactions: TransactionEvent[] = [];
await createRunner()
.withDockerCompose({
workingDirectory: [__dirname],
})
.expect({
transaction: (transaction: TransactionEvent) => {
receivedTransactions.push(transaction);
},
})
.expect({
transaction: (transaction: TransactionEvent) => {
receivedTransactions.push(transaction);
const producer = receivedTransactions.find(
t => t.contexts?.trace?.data?.['sentry.origin'] === 'auto.kafkajs.otel.producer',
);
const consumer = receivedTransactions.find(
t => t.contexts?.trace?.data?.['sentry.origin'] === 'auto.kafkajs.otel.consumer',
);
expect(producer).toBeDefined();
expect(consumer).toBeDefined();
for (const t of [producer, consumer]) {
// just to assert on the basic shape (for more straight-forward tests, this is usually done by the runner)
expect(t).toMatchObject({
event_id: expect.any(String),
timestamp: expect.anything(),
start_timestamp: expect.anything(),
spans: expect.any(Array),
type: 'transaction',
});
}
expect(producer!.transaction).toBe('send test-topic');
expect(consumer!.transaction).toBe('process test-topic');
expect(producer!.contexts?.trace).toMatchObject(
expect.objectContaining({
op: 'message',
status: 'ok',
data: expect.objectContaining({
'messaging.system': 'kafka',
'messaging.destination.name': 'test-topic',
'otel.kind': 'PRODUCER',
'sentry.op': 'message',
'sentry.origin': 'auto.kafkajs.otel.producer',
}),
}),
);
expect(consumer!.contexts?.trace).toMatchObject(
expect.objectContaining({
op: 'message',
status: 'ok',
data: expect.objectContaining({
'messaging.system': 'kafka',
'messaging.destination.name': 'test-topic',
'otel.kind': 'CONSUMER',
'sentry.op': 'message',
'sentry.origin': 'auto.kafkajs.otel.consumer',
}),
}),
);
},
})
.start()
.completed();
});
});
});