-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathtest.ts
More file actions
79 lines (72 loc) · 3.02 KB
/
Copy pathtest.ts
File metadata and controls
79 lines (72 loc) · 3.02 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 type { Envelope } from '@sentry/core';
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';
import { expect, it } from 'vitest';
import { createRunner } from '../../../runner';
const flushMarkerMatcher = (envelope: Envelope): void => {
const [, items] = envelope;
const [itemHeader, itemBody] = items[0] as [{ type: string }, Record<string, unknown>];
expect(itemHeader.type).toBe('event');
expect(itemBody.message).toBe('flush-marker');
};
it('instruments SQL exec operations on Durable Object storage', async ({ signal }) => {
const runner = createRunner(__dirname)
.expect(envelope => {
const transactionEvent = envelope[1]?.[0]?.[1];
const spans = transactionEvent?.spans ?? [];
expect(transactionEvent).toEqual(
expect.objectContaining({
type: 'transaction',
transaction: 'GET /exec',
}),
);
const sqlSpans = (spans as Array<Record<string, unknown>>).filter(
s => s.origin === 'auto.db.cloudflare.durable_object.sql',
);
expect(sqlSpans).toHaveLength(3);
expect(sqlSpans).toEqual(
expect.arrayContaining([
expect.objectContaining({
description: 'CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)',
op: 'db.query',
origin: 'auto.db.cloudflare.durable_object.sql',
data: expect.objectContaining({
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'db.query',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.db.cloudflare.durable_object.sql',
'db.system.name': 'cloudflare-durable-object-sql',
'db.operation.name': 'exec',
'db.query.text': 'CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)',
'cloudflare.durable_object.query.bindings': 0,
}),
}),
expect.objectContaining({
description: 'INSERT INTO users (name) VALUES (?)',
op: 'db.query',
origin: 'auto.db.cloudflare.durable_object.sql',
data: expect.objectContaining({
'db.system.name': 'cloudflare-durable-object-sql',
'db.operation.name': 'exec',
'db.query.text': 'INSERT INTO users (name) VALUES (?)',
'cloudflare.durable_object.query.bindings': 1,
}),
}),
expect.objectContaining({
description: 'SELECT * FROM users',
op: 'db.query',
origin: 'auto.db.cloudflare.durable_object.sql',
data: expect.objectContaining({
'db.system.name': 'cloudflare-durable-object-sql',
'db.operation.name': 'exec',
'db.query.text': 'SELECT * FROM users',
'cloudflare.durable_object.query.bindings': 0,
}),
}),
]),
);
})
.expect(flushMarkerMatcher)
.unordered()
.start(signal);
await runner.makeRequest('get', '/exec');
await runner.makeRequest('get', '/flush-marker');
await runner.completed();
});