-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtest.ts
More file actions
99 lines (94 loc) · 3.98 KB
/
test.ts
File metadata and controls
99 lines (94 loc) · 3.98 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
import { SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME } from '@sentry/core';
import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/node';
import { afterAll, describe, expect, test } from 'vitest';
import { cleanupChildProcesses, createRunner } from '../../../../utils/runner';
describe('express v5 tracing', () => {
afterAll(() => {
cleanupChildProcesses();
});
describe('CJS', () => {
// This test documents the unfortunate behaviour of using `span.updateName` on the server-side.
// For http.server root spans (which is the root span on the server 99% of the time), Otel's http instrumentation
// calls `span.updateName` and overwrites whatever the name was set to before (by us or by users).
test("calling just `span.updateName` doesn't update the final name in express (missing source)", async () => {
const runner = createRunner(__dirname, 'server.js')
.expect({
transaction: {
transaction: 'GET /test/:id/span-updateName',
transaction_info: {
source: 'route',
},
},
})
.start();
runner.makeRequest('get', '/test/123/span-updateName');
await runner.completed();
});
// Also calling `updateName` AND setting a source doesn't change anything - Otel has no concept of source, this is sentry-internal.
// Therefore, only the source is updated but the name is still overwritten by Otel.
test("calling `span.updateName` and setting attribute source doesn't update the final name in express but it updates the source", async () => {
const runner = createRunner(__dirname, 'server.js')
.expect({
transaction: {
transaction: 'GET /test/:id/span-updateName-source',
transaction_info: {
source: 'custom',
},
},
})
.start();
runner.makeRequest('get', '/test/123/span-updateName-source');
await runner.completed();
});
// This test documents the correct way to update the span name (and implicitly the source) in Node:
test('calling `Sentry.updateSpanName` updates the final name and source in express', async () => {
const runner = createRunner(__dirname, 'server.js')
.expect({
transaction: txnEvent => {
expect(txnEvent).toMatchObject({
transaction: 'new-name',
transaction_info: {
source: 'custom',
},
contexts: {
trace: {
op: 'http.server',
data: { [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'custom' },
},
},
});
// ensure we delete the internal attribute once we're done with it
expect(txnEvent.contexts?.trace?.data?.[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]).toBeUndefined();
},
})
.start();
runner.makeRequest('get', '/test/123/updateSpanName');
await runner.completed();
});
});
// This test documents the correct way to update the span name (and implicitly the source) in Node:
test('calling `Sentry.updateSpanName` and setting source subsequently updates the final name and sets correct source', async () => {
const runner = createRunner(__dirname, 'server.js')
.expect({
transaction: txnEvent => {
expect(txnEvent).toMatchObject({
transaction: 'new-name',
transaction_info: {
source: 'component',
},
contexts: {
trace: {
op: 'http.server',
data: { [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'component' },
},
},
});
// ensure we delete the internal attribute once we're done with it
expect(txnEvent.contexts?.trace?.data?.[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME]).toBeUndefined();
},
})
.start();
runner.makeRequest('get', '/test/123/updateSpanNameAndSource');
await runner.completed();
});
});