-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtransactions.test.ts
More file actions
85 lines (67 loc) · 3.24 KB
/
transactions.test.ts
File metadata and controls
85 lines (67 loc) · 3.24 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
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, so RPC spans are disconnected from
// the HTTP transaction. Instead of appearing as child spans of the HTTP transaction, auto-instrumented
// NestJS guard/interceptor/pipe spans become separate standalone transactions.
// This documents the current (broken) behavior — ideally these should be connected to the HTTP trace.
test('Microservice spans are not connected to the HTTP transaction', async ({ baseURL }) => {
const httpTransactionPromise = 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 httpTransaction = await httpTransactionPromise;
// The microservice span should be part of this transaction but isn't due to missing trace propagation
const microserviceSpan = httpTransaction.spans?.find(span => span.description === 'microservice-sum-operation');
expect(microserviceSpan).toBeUndefined();
});
test('Microservice guard is emitted as a standalone transaction instead of being part of the HTTP trace', async ({
baseURL,
}) => {
const guardTransactionPromise = waitForTransaction('nestjs-microservices', transactionEvent => {
return transactionEvent?.transaction === 'ExampleGuard';
});
await fetch(`${baseURL}/test-microservice-guard`);
const guardTransaction = await guardTransactionPromise;
expect(guardTransaction).toBeDefined();
});
test('Microservice interceptor is emitted as a standalone transaction instead of being part of the HTTP trace', async ({
baseURL,
}) => {
const interceptorTransactionPromise = waitForTransaction('nestjs-microservices', transactionEvent => {
return transactionEvent?.transaction === 'ExampleInterceptor';
});
await fetch(`${baseURL}/test-microservice-interceptor`);
const interceptorTransaction = await interceptorTransactionPromise;
expect(interceptorTransaction).toBeDefined();
});
test('Microservice pipe is emitted as a standalone transaction instead of being part of the HTTP trace', async ({
baseURL,
}) => {
const pipeTransactionPromise = waitForTransaction('nestjs-microservices', transactionEvent => {
return transactionEvent?.transaction === 'ExamplePipe';
});
await fetch(`${baseURL}/test-microservice-pipe`);
const pipeTransaction = await pipeTransactionPromise;
expect(pipeTransaction).toBeDefined();
});