-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtest.ts
More file actions
98 lines (82 loc) · 3.46 KB
/
test.ts
File metadata and controls
98 lines (82 loc) · 3.46 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
87
88
89
90
91
92
93
94
95
96
97
98
import { expect } from '@playwright/test';
import type { ClientReport } from '@sentry/core';
import { extractTraceparentData, parseBaggageHeader } from '@sentry/core';
import type { SerializedStreamedSpan } from '@sentry/core/src';
import { sentryTest } from '../../../../../../utils/fixtures';
import {
envelopeRequestParser,
hidePage,
shouldSkipTracingTest,
waitForClientReportRequest,
waitForTracingHeadersOnUrl,
} from '../../../../../../utils/helpers';
import { observeStreamedSpan } from '../../../../../../utils/spanUtils';
const metaTagSampleRand = 0.9;
const metaTagSampleRate = 0.2;
const metaTagTraceId = '12345678901234567890123456789012';
sentryTest.describe('When `consistentTraceSampling` is `true` and page contains <meta> tags', () => {
sentryTest(
'Continues negative sampling decision from meta tag across all traces and downstream propagations',
async ({ getLocalTestUrl, page }) => {
sentryTest.skip(shouldSkipTracingTest());
const url = await getLocalTestUrl({ testDir: __dirname });
const spansReceived: SerializedStreamedSpan[] = [];
observeStreamedSpan(page, span => {
spansReceived.push(span);
return false;
});
const clientReportPromise = waitForClientReportRequest(page);
await sentryTest.step('Initial pageload', async () => {
await page.goto(url);
expect(spansReceived).toHaveLength(0);
});
await sentryTest.step('Custom instrumented button click', async () => {
await page.locator('#btn1').click();
expect(spansReceived).toHaveLength(0);
});
await sentryTest.step('Navigation', async () => {
await page.goto(`${url}#foo`);
expect(spansReceived).toHaveLength(0);
});
await sentryTest.step('Make fetch request', async () => {
const tracingHeadersPromise = waitForTracingHeadersOnUrl(page, 'http://sentry-test-external.io');
await page.locator('#btn2').click();
const { baggage, sentryTrace } = await tracingHeadersPromise;
expect(sentryTrace).toBeDefined();
expect(baggage).toBeDefined();
expect(extractTraceparentData(sentryTrace)).toEqual({
traceId: expect.not.stringContaining(metaTagTraceId),
parentSpanId: expect.stringMatching(/^[\da-f]{16}$/),
parentSampled: false,
});
expect(parseBaggageHeader(baggage)).toEqual({
'sentry-environment': 'production',
'sentry-public_key': 'public',
'sentry-sample_rand': `${metaTagSampleRand}`,
'sentry-sample_rate': `${metaTagSampleRate}`,
'sentry-sampled': 'false',
'sentry-trace_id': expect.not.stringContaining(metaTagTraceId),
'sentry-transaction': 'custom root span 2',
});
expect(spansReceived).toHaveLength(0);
});
await sentryTest.step('Client report', async () => {
await hidePage(page);
const clientReport = envelopeRequestParser<ClientReport>(await clientReportPromise);
expect(clientReport).toEqual({
timestamp: expect.any(Number),
discarded_events: [
{
category: 'span',
quantity: expect.any(Number),
reason: 'sample_rate',
},
],
});
// exact number depends on performance observer emissions
expect(clientReport.discarded_events[0].quantity).toBeGreaterThanOrEqual(10);
});
expect(spansReceived).toHaveLength(0);
},
);
});