-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathbasic.test.ts
85 lines (76 loc) · 2.82 KB
/
basic.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
import * as child_process from 'child_process';
import { expect, test } from '@playwright/test';
import { waitForTransaction } from '@sentry-internal/test-utils';
test('AWS Serverless SDK sends events in ESM mode', async ({ request }) => {
const transactionEventPromise = waitForTransaction('aws-serverless-esm', transactionEvent => {
return transactionEvent?.transaction === 'my-lambda';
});
// Waiting for 1s here because attaching the listener for events in `waitForTransaction` is not synchronous
// Since in this test, we don't start a browser via playwright, we don't have the usual delays (page.goto, etc)
// which are usually enough for us to never have noticed this race condition before.
// This is a workaround but probably sufficient as long as we only experience it in this test.
await new Promise<void>(resolve =>
setTimeout(() => {
resolve();
}, 1000),
);
child_process.execSync('pnpm start', {
stdio: 'inherit',
});
const transactionEvent = await transactionEventPromise;
// shows the SDK sent a transaction
expect(transactionEvent.transaction).toEqual('my-lambda'); // name should be the function name
expect(transactionEvent.contexts?.trace).toEqual({
data: {
'sentry.sample_rate': 1,
'sentry.source': 'custom',
'sentry.origin': 'auto.otel.aws-lambda',
'sentry.op': 'function.aws.lambda',
'cloud.account.id': '123453789012',
'faas.id': 'arn:aws:lambda:us-east-1:123453789012:function:my-lambda',
'faas.coldstart': true,
'otel.kind': 'SERVER',
},
op: 'function.aws.lambda',
origin: 'auto.otel.aws-lambda',
span_id: expect.stringMatching(/[a-f0-9]{16}/),
status: 'ok',
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
});
expect(transactionEvent.spans).toHaveLength(3);
// shows that the Otel Http instrumentation is working
expect(transactionEvent.spans).toContainEqual(
expect.objectContaining({
data: expect.objectContaining({
'sentry.op': 'http.client',
'sentry.origin': 'auto.http.otel.http',
url: 'http://example.com/',
}),
description: 'GET http://example.com/',
op: 'http.client',
}),
);
expect(transactionEvent.spans).toContainEqual(
expect.objectContaining({
data: {
'sentry.op': 'function.aws.lambda',
'sentry.origin': 'auto.function.serverless',
'sentry.source': 'component',
},
description: 'my-lambda',
op: 'function.aws.lambda',
origin: 'auto.function.serverless',
}),
);
// shows that the manual span creation is working
expect(transactionEvent.spans).toContainEqual(
expect.objectContaining({
data: expect.objectContaining({
'sentry.op': 'manual',
'sentry.origin': 'manual',
}),
description: 'manual-span',
op: 'manual',
}),
);
});