-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathtransactions.test.ts
124 lines (109 loc) · 4.11 KB
/
transactions.test.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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { expect, test } from '@playwright/test';
import { waitForTransaction } from '@sentry-internal/event-proxy-server';
import axios from 'axios';
test('Sends successful transaction', async ({ baseURL }) => {
const pageloadTransactionEventPromise = waitForTransaction('node-hapi', transactionEvent => {
return (
transactionEvent?.contexts?.trace?.op === 'http.server' && transactionEvent?.transaction === 'GET /test-success'
);
});
await axios.get(`${baseURL}/test-success`);
const transactionEvent = await pageloadTransactionEventPromise;
const transactionEventId = transactionEvent.event_id;
expect(transactionEvent.contexts?.trace).toEqual({
data: {
'sentry.source': 'route',
'sentry.origin': 'auto.http.otel.http',
'sentry.op': 'http.server',
'sentry.sample_rate': 1,
url: 'http://localhost:3030/test-success',
'otel.kind': 'SERVER',
'http.response.status_code': 200,
'http.url': 'http://localhost:3030/test-success',
'http.host': 'localhost:3030',
'net.host.name': 'localhost',
'http.method': 'GET',
'http.scheme': 'http',
'http.target': '/test-success',
'http.user_agent': 'axios/1.6.7',
'http.flavor': '1.1',
'net.transport': 'ip_tcp',
'net.host.ip': expect.any(String),
'net.host.port': expect.any(Number),
'net.peer.ip': expect.any(String),
'net.peer.port': expect.any(Number),
'http.status_code': 200,
'http.status_text': 'OK',
'http.route': '/test-success',
},
op: 'http.server',
span_id: expect.any(String),
status: 'ok',
trace_id: expect.any(String),
origin: 'auto.http.otel.http',
});
expect(transactionEvent).toEqual(
expect.objectContaining({
transaction: 'GET /test-success',
type: 'transaction',
transaction_info: {
source: 'route',
},
}),
);
const spans = transactionEvent.spans || [];
expect(spans).toEqual([
{
data: {
'hapi.type': 'router',
'http.method': 'GET',
'http.route': '/test-success',
'otel.kind': 'INTERNAL',
'sentry.op': 'router.hapi',
'sentry.origin': 'auto.http.otel.hapi',
},
description: 'GET /test-success',
op: 'router.hapi',
origin: 'auto.http.otel.hapi',
parent_span_id: expect.any(String),
span_id: expect.any(String),
start_timestamp: expect.any(Number),
status: 'ok',
timestamp: expect.any(Number),
trace_id: expect.any(String),
},
]);
});
test('Sends parameterized transactions to Sentry', async ({ baseURL }) => {
const pageloadTransactionEventPromise = waitForTransaction('node-hapi', transactionEvent => {
return (
transactionEvent?.contexts?.trace?.op === 'http.server' &&
transactionEvent?.transaction === 'GET /test-param/{param}'
);
});
await axios.get(`${baseURL}/test-param/123`);
const transactionEvent = await pageloadTransactionEventPromise;
const transactionEventId = transactionEvent.event_id;
expect(transactionEvent?.contexts?.trace?.op).toBe('http.server');
expect(transactionEvent?.contexts?.trace?.data?.['http.route']).toBe('/test-param/{param}');
expect(transactionEvent?.transaction).toBe('GET /test-param/{param}');
});
test('Isolates requests', async ({ baseURL }) => {
const transaction1Promise = waitForTransaction('node-hapi', transactionEvent => {
return (
transactionEvent?.contexts?.trace?.op === 'http.server' &&
transactionEvent?.contexts?.trace?.data?.['http.target'] === '/test-param/888'
);
});
const transaction2Promise = waitForTransaction('node-hapi', transactionEvent => {
return (
transactionEvent?.contexts?.trace?.op === 'http.server' &&
transactionEvent?.contexts?.trace?.data?.['http.target'] === '/test-param/999'
);
});
await Promise.all([axios.get(`${baseURL}/test-param/888`), axios.get(`${baseURL}/test-param/999`)]);
const transaction1 = await transaction1Promise;
const transaction2 = await transaction2Promise;
expect(transaction1.tags).toEqual({ 'param-888': 'yes' });
expect(transaction2.tags).toEqual({ 'param-999': 'yes' });
});