-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtest.ts
More file actions
130 lines (106 loc) · 5.26 KB
/
test.ts
File metadata and controls
130 lines (106 loc) · 5.26 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
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
125
126
127
128
129
130
import { expect } from '@playwright/test';
import { extractTraceparentData } from '@sentry/core';
import { sentryTest } from '../../../../utils/fixtures';
import { shouldSkipTracingTest } from '../../../../utils/helpers';
const META_TAG_TRACE_ID = '12345678901234567890123456789012';
const META_TAG_PARENT_SPAN_ID = '1234567890123456';
const META_TAG_BAGGAGE =
'sentry-trace_id=12345678901234567890123456789012,sentry-public_key=public,sentry-release=1.0.0,sentry-environment=prod,sentry-sample_rand=0.42';
sentryTest(
'outgoing fetch requests have new traceId after navigation (with propagateTraceparent)',
async ({ getLocalTestUrl, page }) => {
if (shouldSkipTracingTest()) {
sentryTest.skip();
}
const url = await getLocalTestUrl({ testDir: __dirname });
await page.route('http://sentry-test-site.example/**', route => {
return route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({}),
});
});
await page.goto(url);
const requestPromise = page.waitForRequest('http://sentry-test-site.example/*');
await page.locator('#fetchBtn').click();
const request = await requestPromise;
const headers = request.headers();
const sentryTraceParentData = extractTraceparentData(headers['sentry-trace']);
// sampling decision is deferred because TwP means we didn't sample any span
expect(sentryTraceParentData).toEqual({
traceId: META_TAG_TRACE_ID,
parentSpanId: expect.stringMatching(/^[0-9a-f]{16}$/),
parentSampled: undefined,
});
expect(headers['baggage']).toBe(META_TAG_BAGGAGE);
// but traceparent propagates a negative sampling decision because it has no concept of deferred sampling
expect(headers['traceparent']).toBe(
`00-${sentryTraceParentData?.traceId}-${sentryTraceParentData?.parentSpanId}-00`,
);
const requestPromise2 = page.waitForRequest('http://sentry-test-site.example/*');
await page.locator('#fetchBtn').click();
const request2 = await requestPromise2;
const headers2 = request2.headers();
const sentryTraceParentData2 = extractTraceparentData(headers2['sentry-trace']);
expect(sentryTraceParentData2).toEqual(sentryTraceParentData);
await page.goto(`${url}#navigation`);
const requestPromise3 = page.waitForRequest('http://sentry-test-site.example/*');
await page.locator('#fetchBtn').click();
const request3 = await requestPromise3;
const headers3 = request3.headers();
const sentryTraceParentData3 = extractTraceparentData(headers3['sentry-trace']);
// sampling decision is deferred because TwP means we didn't sample any span
expect(sentryTraceParentData3).toEqual({
traceId: expect.not.stringContaining(sentryTraceParentData!.traceId!),
parentSpanId: expect.not.stringContaining(sentryTraceParentData!.parentSpanId!),
parentSampled: undefined,
});
expect(headers3['baggage']).toMatch(
/sentry-environment=production,sentry-public_key=public,sentry-trace_id=[0-9a-f]{32}/,
);
expect(headers3['baggage']).not.toContain(`sentry-trace_id=${META_TAG_TRACE_ID}`);
// but traceparent propagates a negative sampling decision because it has no concept of deferred sampling
expect(headers3['traceparent']).toBe(
`00-${sentryTraceParentData3!.traceId}-${sentryTraceParentData3!.parentSpanId}-00`,
);
const requestPromise4 = page.waitForRequest('http://sentry-test-site.example/*');
await page.locator('#fetchBtn').click();
const request4 = await requestPromise4;
const headers4 = request4.headers();
const sentryTraceParentData4 = extractTraceparentData(headers4['sentry-trace']);
expect(sentryTraceParentData4).toEqual(sentryTraceParentData3);
},
);
sentryTest('outgoing XHR requests have new traceId after navigation', async ({ getLocalTestUrl, page }) => {
if (shouldSkipTracingTest()) {
sentryTest.skip();
}
const url = await getLocalTestUrl({ testDir: __dirname });
await page.route('http://sentry-test-site.example/**', route => {
return route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify({}),
});
});
await page.goto(url);
const requestPromise = page.waitForRequest('http://sentry-test-site.example/*');
await page.locator('#xhrBtn').click();
const request = await requestPromise;
const headers = request.headers();
// sampling decision is deferred because TwP means we didn't sample any span
expect(headers['sentry-trace']).toMatch(new RegExp(`^${META_TAG_TRACE_ID}-[0-9a-f]{16}$`));
expect(headers['baggage']).toBe(META_TAG_BAGGAGE);
await page.goto(`${url}#navigation`);
const requestPromise2 = page.waitForRequest('http://sentry-test-site.example/*');
await page.locator('#xhrBtn').click();
const request2 = await requestPromise2;
const headers2 = request2.headers();
// sampling decision is deferred because TwP means we didn't sample any span
expect(headers2['sentry-trace']).toMatch(/^[0-9a-f]{32}-[0-9a-f]{16}$/);
expect(headers2['baggage']).not.toBe(`${META_TAG_TRACE_ID}-${META_TAG_PARENT_SPAN_ID}`);
expect(headers2['baggage']).toMatch(
/sentry-environment=production,sentry-public_key=public,sentry-trace_id=[0-9a-f]{32}/,
);
expect(headers2['baggage']).not.toContain(`sentry-trace_id=${META_TAG_TRACE_ID}`);
});