-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtest.ts
More file actions
110 lines (106 loc) · 4.09 KB
/
test.ts
File metadata and controls
110 lines (106 loc) · 4.09 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
import { afterAll, describe, expect, test } from 'vitest';
import { cleanupChildProcesses, createRunner } from '../../../utils/runner';
describe('redis v5 diagnostics_channel auto instrumentation', () => {
afterAll(() => {
cleanupChildProcesses();
});
test('should create spans for redis v5 commands via diagnostics_channel', { timeout: 60_000 }, async () => {
const EXPECTED_TRANSACTION = {
transaction: 'Test Span Redis 5 DC',
spans: expect.arrayContaining([
expect.objectContaining({
op: 'db.redis',
origin: 'auto.db.otel.redis',
data: expect.objectContaining({
'sentry.op': 'db.redis',
'sentry.origin': 'auto.db.otel.redis',
'db.system': 'redis',
'db.statement': 'SET dc-test-key [1 other arguments]',
}),
}),
// cache SET: span name updated to key by cacheResponseHook
expect.objectContaining({
description: 'dc-cache:test-key',
op: 'cache.put',
origin: 'auto.db.otel.redis',
data: expect.objectContaining({
'sentry.origin': 'auto.db.otel.redis',
'db.statement': 'SET dc-cache:test-key [1 other arguments]',
'cache.key': ['dc-cache:test-key'],
'cache.item_size': 2,
}),
}),
// cache SET with EX option: redis v5 sends SET key value EX 10 as the command
expect.objectContaining({
description: 'dc-cache:test-key-ex',
op: 'cache.put',
origin: 'auto.db.otel.redis',
data: expect.objectContaining({
'sentry.origin': 'auto.db.otel.redis',
'db.statement': 'SET dc-cache:test-key-ex [3 other arguments]',
'cache.key': ['dc-cache:test-key-ex'],
'cache.item_size': 2,
}),
}),
expect.objectContaining({
op: 'db.redis',
origin: 'auto.db.otel.redis',
data: expect.objectContaining({
'sentry.op': 'db.redis',
'sentry.origin': 'auto.db.otel.redis',
'db.system': 'redis',
'db.statement': 'GET dc-test-key',
}),
}),
// cache GET (hit)
expect.objectContaining({
description: 'dc-cache:test-key',
op: 'cache.get',
origin: 'auto.db.otel.redis',
data: expect.objectContaining({
'sentry.origin': 'auto.db.otel.redis',
'db.statement': 'GET dc-cache:test-key',
'cache.hit': true,
'cache.key': ['dc-cache:test-key'],
'cache.item_size': 10,
}),
}),
// cache GET (miss)
expect.objectContaining({
description: 'dc-cache:unavailable-data',
op: 'cache.get',
origin: 'auto.db.otel.redis',
data: expect.objectContaining({
'sentry.origin': 'auto.db.otel.redis',
'db.statement': 'GET dc-cache:unavailable-data',
'cache.hit': false,
'cache.key': ['dc-cache:unavailable-data'],
}),
}),
// MGET: mixed cache/non-cache keys, span name is all keys joined
expect.objectContaining({
description: 'dc-test-key, dc-cache:test-key, dc-cache:unavailable-data',
op: 'cache.get',
origin: 'auto.db.otel.redis',
data: expect.objectContaining({
'sentry.origin': 'auto.db.otel.redis',
'db.statement': 'MGET [3 other arguments]',
'cache.hit': true,
'cache.key': ['dc-test-key', 'dc-cache:test-key', 'dc-cache:unavailable-data'],
}),
}),
]),
};
// node-redis emits a node-redis:connect DC event for the initial connection.
// That fires before startSpan so it becomes its own root transaction, received after the main one.
const EXPECTED_CONNECT = {
transaction: 'redis-connect',
};
await createRunner(__dirname, 'scenario-redis-5.js')
.withDockerCompose({ workingDirectory: [__dirname] })
.expect({ transaction: EXPECTED_TRANSACTION })
.expect({ transaction: EXPECTED_CONNECT })
.start()
.completed();
});
});