-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtest.ts
More file actions
143 lines (135 loc) · 5.43 KB
/
test.ts
File metadata and controls
143 lines (135 loc) · 5.43 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
import {
SDK_VERSION,
SEMANTIC_ATTRIBUTE_SENTRY_OP,
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,
} from '@sentry/core';
import { expect, test } from 'vitest';
import { createRunner } from '../../../../utils/runner';
test('sends a streamed span envelope with correct envelope header', async () => {
await createRunner(__dirname, 'scenario.ts')
.expectHeader({
span: {
sent_at: expect.any(String),
sdk: {
name: 'sentry.javascript.node-core',
version: SDK_VERSION,
},
trace: expect.objectContaining({
public_key: 'public',
sample_rate: '1',
sampled: 'true',
trace_id: expect.stringMatching(/^[\da-f]{32}$/),
transaction: 'test-span',
}),
},
})
.start()
.completed();
});
test('sends a streamed span envelope with correct spans for a manually started span with children', async () => {
await createRunner(__dirname, 'scenario.ts')
.expect({
span: container => {
const spans = container.items;
expect(spans.length).toBe(4);
const segmentSpan = spans.find(s => !!s.is_segment);
expect(segmentSpan).toBeDefined();
const segmentSpanId = segmentSpan!.span_id;
const traceId = segmentSpan!.trace_id;
const childSpan = spans.find(s => s.name === 'test-child-span');
expect(childSpan).toBeDefined();
expect(childSpan).toEqual({
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: {
type: 'string',
value: 'test-child',
},
[SEMANTIC_ATTRIBUTE_SENTRY_SDK_NAME]: { type: 'string', value: 'sentry.javascript.node-core' },
[SEMANTIC_ATTRIBUTE_SENTRY_SDK_VERSION]: { type: 'string', value: SDK_VERSION },
[SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_ID]: { type: 'string', value: segmentSpanId },
[SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_NAME]: { type: 'string', value: 'test-span' },
},
name: 'test-child-span',
is_segment: false,
parent_span_id: segmentSpanId,
trace_id: traceId,
span_id: expect.stringMatching(/^[\da-f]{16}$/),
start_timestamp: expect.any(Number),
end_timestamp: expect.any(Number),
status: 'ok',
});
const inactiveSpan = spans.find(s => s.name === 'test-inactive-span');
expect(inactiveSpan).toBeDefined();
expect(inactiveSpan).toEqual({
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_SDK_NAME]: { type: 'string', value: 'sentry.javascript.node-core' },
[SEMANTIC_ATTRIBUTE_SENTRY_SDK_VERSION]: { type: 'string', value: SDK_VERSION },
[SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_ID]: { type: 'string', value: segmentSpanId },
[SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_NAME]: { type: 'string', value: 'test-span' },
},
links: [
{
attributes: {
'sentry.link.type': {
type: 'string',
value: 'some_relation',
},
},
sampled: true,
span_id: segmentSpanId,
trace_id: traceId,
},
],
name: 'test-inactive-span',
is_segment: false,
parent_span_id: segmentSpanId,
trace_id: traceId,
span_id: expect.stringMatching(/^[\da-f]{16}$/),
start_timestamp: expect.any(Number),
end_timestamp: expect.any(Number),
status: 'ok',
});
const manualSpan = spans.find(s => s.name === 'test-manual-span');
expect(manualSpan).toBeDefined();
expect(manualSpan).toEqual({
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_SDK_NAME]: { type: 'string', value: 'sentry.javascript.node-core' },
[SEMANTIC_ATTRIBUTE_SENTRY_SDK_VERSION]: { type: 'string', value: SDK_VERSION },
[SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_ID]: { type: 'string', value: segmentSpanId },
[SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_NAME]: { type: 'string', value: 'test-span' },
},
name: 'test-manual-span',
is_segment: false,
parent_span_id: segmentSpanId,
trace_id: traceId,
span_id: expect.stringMatching(/^[\da-f]{16}$/),
start_timestamp: expect.any(Number),
end_timestamp: expect.any(Number),
status: 'ok',
});
expect(segmentSpan).toEqual({
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: { type: 'string', value: 'test' },
[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: { type: 'integer', value: 1 },
[SEMANTIC_ATTRIBUTE_SENTRY_SDK_NAME]: { type: 'string', value: 'sentry.javascript.node-core' },
[SEMANTIC_ATTRIBUTE_SENTRY_SDK_VERSION]: { type: 'string', value: SDK_VERSION },
[SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_ID]: { type: 'string', value: segmentSpanId },
[SEMANTIC_ATTRIBUTE_SENTRY_SEGMENT_NAME]: { type: 'string', value: 'test-span' },
},
name: 'test-span',
is_segment: true,
trace_id: traceId,
span_id: segmentSpanId,
start_timestamp: expect.any(Number),
end_timestamp: expect.any(Number),
status: 'ok',
});
},
})
.start()
.completed();
});