-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtest.ts
More file actions
145 lines (134 loc) · 4.7 KB
/
test.ts
File metadata and controls
145 lines (134 loc) · 4.7 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import { expect } from '@playwright/test';
import {
SDK_VERSION,
SEMANTIC_ATTRIBUTE_SENTRY_OP,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE,
SEMANTIC_ATTRIBUTE_SENTRY_SDK_NAME,
SEMANTIC_ATTRIBUTE_SENTRY_SDK_VERSION,
SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_ID,
SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_NAME,
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
} from '@sentry/core';
import { sentryTest } from '../../../../utils/fixtures';
import { shouldSkipTracingTest, testingCdnBundle } from '../../../../utils/helpers';
import { getSpanOp, getSpansFromEnvelope, waitForStreamedSpanEnvelope } from '../../../../utils/spanUtils';
sentryTest(
'creates a pageload streamed span envelope with url as pageload span name source',
async ({ getLocalTestUrl, page }) => {
sentryTest.skip(shouldSkipTracingTest() || testingCdnBundle());
const spanEnvelopePromise = waitForStreamedSpanEnvelope(
page,
env => !!getSpansFromEnvelope(env).find(s => getSpanOp(s) === 'pageload'),
);
const url = await getLocalTestUrl({ testDir: __dirname });
await page.goto(url);
const spanEnvelope = await spanEnvelopePromise;
const envelopeHeader = spanEnvelope[0];
const envelopeItem = spanEnvelope[1];
const spans = envelopeItem[0][1].items;
const pageloadSpan = spans.find(s => getSpanOp(s) === 'pageload');
const timeOrigin = await page.evaluate<number>('window._testBaseTimestamp');
expect(envelopeHeader).toEqual({
sdk: {
name: 'sentry.javascript.browser',
version: SDK_VERSION,
},
sent_at: expect.any(String),
trace: {
environment: 'production',
public_key: 'public',
sample_rand: expect.any(String),
sample_rate: '1',
sampled: 'true',
trace_id: expect.stringMatching(/^[\da-f]{32}$/),
},
});
const numericSampleRand = parseFloat(envelopeHeader.trace!.sample_rand!);
const traceId = envelopeHeader.trace!.trace_id;
expect(Number.isNaN(numericSampleRand)).toBe(false);
expect(envelopeItem[0][0].item_count).toBeGreaterThan(1);
expect(pageloadSpan?.start_timestamp).toBeCloseTo(timeOrigin, 1);
expect(pageloadSpan).toEqual({
attributes: {
// formerly known as 'effectiveConnectionType'
'network.connection.effective_type': {
type: 'string',
value: expect.any(String),
},
// formerly known as 'hardwareConcurrency'
'device.processor_count': {
type: expect.stringMatching(/^(integer)|(double)$/),
value: expect.any(Number),
},
'browser.performance.navigation.activation_start': {
type: expect.stringMatching(/^(integer)|(double)$/),
value: expect.any(Number),
},
'browser.performance.time_origin': {
type: expect.stringMatching(/^(integer)|(double)$/),
value: expect.any(Number),
},
'network.connection.rtt': {
type: expect.stringMatching(/^(integer)|(double)$/),
value: expect.any(Number),
},
'browser.web_vital.ttfb.request_time': {
type: expect.stringMatching(/^(integer)|(double)$/),
value: expect.any(Number),
},
'browser.web_vital.ttfb.value': {
type: expect.stringMatching(/^(integer)|(double)$/),
value: expect.any(Number),
},
'sentry.idle_span_finish_reason': {
type: 'string',
value: 'idleTimeout',
},
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: {
type: 'string',
value: 'pageload',
},
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: {
type: 'string',
value: 'auto.pageload.browser',
},
[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: {
type: 'integer',
value: 1,
},
[SEMANTIC_ATTRIBUTE_SENTRY_SDK_NAME]: {
type: 'string',
value: 'sentry.javascript.browser',
},
[SEMANTIC_ATTRIBUTE_SENTRY_SDK_VERSION]: {
type: 'string',
value: SDK_VERSION,
},
[SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_ID]: {
type: 'string',
value: pageloadSpan?.span_id,
},
[SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_NAME]: {
type: 'string',
value: '/index.html',
},
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: {
type: 'string',
value: 'url',
},
'sentry.span.source': {
type: 'string',
value: 'url',
},
},
end_timestamp: expect.any(Number),
is_segment: true,
name: '/index.html',
span_id: expect.stringMatching(/^[\da-f]{16}$/),
start_timestamp: expect.any(Number),
status: 'ok',
trace_id: traceId,
});
},
);