-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtransactions.test.ts
More file actions
54 lines (44 loc) · 1.95 KB
/
transactions.test.ts
File metadata and controls
54 lines (44 loc) · 1.95 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
import { expect, test } from '@playwright/test';
import { waitForTransaction } from '@sentry-internal/test-utils';
test('Sends an HTTP transaction', async ({ baseURL }) => {
const transactionEventPromise = waitForTransaction('nestjs-microservices', transactionEvent => {
return (
transactionEvent?.contexts?.trace?.op === 'http.server' &&
transactionEvent?.transaction === 'GET /test-transaction'
);
});
const response = await fetch(`${baseURL}/test-transaction`);
expect(response.status).toBe(200);
const transactionEvent = await transactionEventPromise;
expect(transactionEvent.contexts?.trace).toEqual(
expect.objectContaining({
op: 'http.server',
status: 'ok',
}),
);
});
// Trace context does not propagate over NestJS TCP transport.
// The manual span created inside the microservice handler is orphaned, not a child of the HTTP transaction.
// This test documents this gap — if trace propagation is ever fixed, test.fail() will alert us.
test.fail('Microservice spans are captured as children of the HTTP transaction', async ({ baseURL }) => {
const transactionEventPromise = waitForTransaction('nestjs-microservices', transactionEvent => {
return (
transactionEvent?.contexts?.trace?.op === 'http.server' &&
transactionEvent?.transaction === 'GET /test-microservice-sum'
);
});
const response = await fetch(`${baseURL}/test-microservice-sum`);
expect(response.status).toBe(200);
const body = await response.json();
expect(body.result).toBe(6);
const transactionEvent = await transactionEventPromise;
expect(transactionEvent.contexts?.trace).toEqual(
expect.objectContaining({
op: 'http.server',
status: 'ok',
}),
);
const microserviceSpan = transactionEvent.spans?.find(span => span.description === 'microservice-sum-operation');
expect(microserviceSpan).toBeDefined();
expect(microserviceSpan.trace_id).toBe(transactionEvent.contexts?.trace?.trace_id);
});