Skip to content

Commit d28c030

Browse files
committed
add cloudflare test
1 parent 867d345 commit d28c030

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import * as Sentry from '@sentry/cloudflare';
2+
3+
interface Env {
4+
SENTRY_DSN: string;
5+
}
6+
7+
export default Sentry.withSentry(
8+
(env: Env) => ({
9+
dsn: env.SENTRY_DSN,
10+
release: '1.0.0',
11+
environment: 'test',
12+
serverName: 'mi-servidor.com',
13+
}),
14+
{
15+
async fetch(_request, _env, _ctx) {
16+
Sentry.metrics.count('test.counter', 1, { attributes: { endpoint: '/api/test' } });
17+
await Sentry.flush();
18+
return new Response('OK');
19+
},
20+
},
21+
);
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import type { SerializedMetricContainer } from '@sentry/core';
2+
import { expect, it } from 'vitest';
3+
import { createRunner } from '../../../../runner';
4+
5+
it('should add server.address attribute to metrics when serverName is set', async ({ signal }) => {
6+
const runner = createRunner(__dirname)
7+
.expect(envelope => {
8+
const metric = envelope[1]?.[0]?.[1] as SerializedMetricContainer;
9+
10+
expect(metric.items[0]).toEqual(
11+
expect.objectContaining({
12+
name: 'test.counter',
13+
type: 'counter',
14+
value: 1,
15+
span_id: expect.any(String),
16+
timestamp: expect.any(Number),
17+
trace_id: expect.any(String),
18+
attributes: {
19+
endpoint: {
20+
type: 'string',
21+
value: '/api/test',
22+
},
23+
'sentry.environment': {
24+
type: 'string',
25+
value: 'test',
26+
},
27+
'sentry.release': {
28+
type: 'string',
29+
value: expect.any(String),
30+
},
31+
'sentry.sdk.name': {
32+
type: 'string',
33+
value: 'sentry.javascript.cloudflare',
34+
},
35+
'sentry.sdk.version': {
36+
type: 'string',
37+
value: expect.any(String),
38+
},
39+
'server.address': {
40+
type: 'string',
41+
value: 'mi-servidor.com',
42+
},
43+
},
44+
}),
45+
);
46+
})
47+
.start(signal);
48+
await runner.makeRequest('get', '/');
49+
await runner.completed();
50+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "worker-name",
3+
"compatibility_date": "2025-06-17",
4+
"main": "index.ts",
5+
"compatibility_flags": ["nodejs_compat"],
6+
}

0 commit comments

Comments
 (0)