-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtest.ts
More file actions
79 lines (65 loc) · 3.07 KB
/
test.ts
File metadata and controls
79 lines (65 loc) · 3.07 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
import { expect } from '@playwright/test';
import { SEMANTIC_LINK_ATTRIBUTE_LINK_TYPE } from '@sentry/core';
import { sentryTest } from '../../../../../utils/fixtures';
import { shouldSkipTracingTest } from '../../../../../utils/helpers';
import { getSpanOp, waitForStreamedSpan } from '../../../../../utils/spanUtils';
/*
This is quite peculiar behavior but it's a result of the route-based trace lifetime.
Once we shortened trace lifetime, this whole scenario will change as the interaction
spans will be their own trace. So most likely, we can replace this test with a new one
that covers the new default behavior.
*/
sentryTest(
'only the first root spans in the trace link back to the previous trace',
async ({ getLocalTestUrl, page }) => {
sentryTest.skip(shouldSkipTracingTest());
const url = await getLocalTestUrl({ testDir: __dirname });
const pageloadSpan = await sentryTest.step('Initial pageload', async () => {
const pageloadSpanPromise = waitForStreamedSpan(page, span => getSpanOp(span) === 'pageload');
await page.goto(url);
const span = await pageloadSpanPromise;
expect(span).toBeDefined();
expect(span.links).toBeUndefined();
return span;
});
await sentryTest.step('Click Before navigation', async () => {
const interactionSpanPromise = waitForStreamedSpan(page, span => getSpanOp(span) === 'ui.action.click');
await page.click('#btn');
const interactionSpan = await interactionSpanPromise;
// sanity check: route-based trace lifetime means the trace_id should be the same
expect(interactionSpan.trace_id).toBe(pageloadSpan.trace_id);
// no links yet as previous root span belonged to same trace
expect(interactionSpan.links).toBeUndefined();
});
const navigationSpan = await sentryTest.step('Navigation', async () => {
const navigationSpanPromise = waitForStreamedSpan(page, span => getSpanOp(span) === 'navigation');
await page.goto(`${url}#foo`);
const span = await navigationSpanPromise;
expect(getSpanOp(span)).toBe('navigation');
expect(span.links).toEqual([
{
trace_id: pageloadSpan.trace_id,
span_id: pageloadSpan.span_id,
sampled: true,
attributes: {
[SEMANTIC_LINK_ATTRIBUTE_LINK_TYPE]: {
type: 'string',
value: 'previous_trace',
},
},
},
]);
expect(span.trace_id).not.toEqual(span.links![0].trace_id);
return span;
});
await sentryTest.step('Click After navigation', async () => {
const interactionSpanPromise = waitForStreamedSpan(page, span => getSpanOp(span) === 'ui.action.click');
await page.click('#btn');
const interactionSpan = await interactionSpanPromise;
// sanity check: route-based trace lifetime means the trace_id should be the same
expect(interactionSpan.trace_id).toBe(navigationSpan.trace_id);
// since this is the second root span in the trace, it doesn't link back to the previous trace
expect(interactionSpan.links).toBeUndefined();
});
},
);