Skip to content

Commit 1834094

Browse files
authored
ref(cloudflare): Adjust event mechanisms and durable object origin (#17618)
- Adjust the event mechanism to use the same value as the surrounding span's origin - Adjust the durable object span origin because it didn't follow the same patter as the other origins closes #17617
1 parent f2e621a commit 1834094

File tree

12 files changed

+33
-29
lines changed

12 files changed

+33
-29
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- ref(astro): Adjust `mechanism` on error events captured by astro middleware ([#17613](https://github.com/getsentry/sentry-javascript/pull/17613))
1919
- ref(aws-severless): Slightly adjust aws-serverless mechanism type ([#17614](https://github.com/getsentry/sentry-javascript/pull/17614))
2020
- ref(bun): Adjust `mechanism` of errors captured in Bun.serve ([#17616](https://github.com/getsentry/sentry-javascript/pull/17616))
21+
- ref(cloudflare): Adjust event `mechanisms` and durable object origin ([#17618](https://github.com/getsentry/sentry-javascript/pull/17618))
2122
- ref(core): Adjust `mechanism` in `captureConsoleIntegration` ([#17633](https://github.com/getsentry/sentry-javascript/pull/17633))
2223
- ref(core): Adjust MCP server error event `mechanism` ([#17622](https://github.com/getsentry/sentry-javascript/pull/17622))
2324
- ref(core): Simplify `linkedErrors` mechanism logic ([#17600](https://github.com/getsentry/sentry-javascript/pull/17600))

dev-packages/cloudflare-integration-tests/suites/basic/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ it('Basic error in fetch handler', async () => {
1515
stacktrace: {
1616
frames: expect.any(Array),
1717
},
18-
mechanism: { type: 'cloudflare', handled: false },
18+
mechanism: { type: 'auto.http.cloudflare', handled: false },
1919
},
2020
],
2121
},

dev-packages/cloudflare-integration-tests/suites/tracing/durableobject/test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ it('traces a durable object method', async () => {
1212
op: 'rpc',
1313
data: expect.objectContaining({
1414
'sentry.op': 'rpc',
15-
'sentry.origin': 'auto.faas.cloudflare_durableobjects',
15+
'sentry.origin': 'auto.faas.cloudflare.durable_object',
1616
}),
17-
origin: 'auto.faas.cloudflare_durableobjects',
17+
origin: 'auto.faas.cloudflare.durable_object',
1818
}),
1919
}),
2020
transaction: 'sayHello',

dev-packages/e2e-tests/test-applications/cloudflare-workers/playwright.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const config = getPlaywrightConfig(
1515
{
1616
// This comes with the risk of tests leaking into each other but the tests run quite slow so we should parallelize
1717
workers: '100%',
18+
retries: 0,
1819
},
1920
);
2021

dev-packages/e2e-tests/test-applications/cloudflare-workers/tests/index.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ test('Index page', async ({ baseURL }) => {
1010

1111
test("worker's withSentry", async ({ baseURL }) => {
1212
const eventWaiter = waitForError('cloudflare-workers', event => {
13-
return event.exception?.values?.[0]?.mechanism?.type === 'cloudflare';
13+
return event.exception?.values?.[0]?.mechanism?.type === 'auto.http.cloudflare';
1414
});
1515
const response = await fetch(`${baseURL}/throwException`);
1616
expect(response.status).toBe(500);
@@ -20,25 +20,27 @@ test("worker's withSentry", async ({ baseURL }) => {
2020

2121
test('RPC method which throws an exception to be logged to sentry', async ({ baseURL }) => {
2222
const eventWaiter = waitForError('cloudflare-workers', event => {
23-
return event.exception?.values?.[0]?.mechanism?.type === 'cloudflare_durableobject';
23+
return event.exception?.values?.[0]?.mechanism?.type === 'auto.faas.cloudflare.durable_object';
2424
});
2525
const response = await fetch(`${baseURL}/rpc/throwException`);
2626
expect(response.status).toBe(500);
2727
const event = await eventWaiter;
2828
expect(event.exception?.values?.[0]?.value).toBe('Should be recorded in Sentry.');
2929
});
30+
3031
test("Request processed by DurableObject's fetch is recorded", async ({ baseURL }) => {
3132
const eventWaiter = waitForError('cloudflare-workers', event => {
32-
return event.exception?.values?.[0]?.mechanism?.type === 'cloudflare_durableobject';
33+
return event.exception?.values?.[0]?.mechanism?.type === 'auto.faas.cloudflare.durable_object';
3334
});
3435
const response = await fetch(`${baseURL}/pass-to-object/throwException`);
3536
expect(response.status).toBe(500);
3637
const event = await eventWaiter;
3738
expect(event.exception?.values?.[0]?.value).toBe('Should be recorded in Sentry.');
3839
});
40+
3941
test('Websocket.webSocketMessage', async ({ baseURL }) => {
4042
const eventWaiter = waitForError('cloudflare-workers', event => {
41-
return event.exception?.values?.[0]?.mechanism?.type === 'cloudflare_durableobject';
43+
return event.exception?.values?.[0]?.mechanism?.type === 'auto.faas.cloudflare.durable_object';
4244
});
4345
const url = new URL('/pass-to-object/ws', baseURL);
4446
url.protocol = url.protocol.replace('http', 'ws');
@@ -53,7 +55,7 @@ test('Websocket.webSocketMessage', async ({ baseURL }) => {
5355

5456
test('Websocket.webSocketClose', async ({ baseURL }) => {
5557
const eventWaiter = waitForError('cloudflare-workers', event => {
56-
return event.exception?.values?.[0]?.mechanism?.type === 'cloudflare_durableobject';
58+
return event.exception?.values?.[0]?.mechanism?.type === 'auto.faas.cloudflare.durable_object';
5759
});
5860
const url = new URL('/pass-to-object/ws', baseURL);
5961
url.protocol = url.protocol.replace('http', 'ws');

packages/cloudflare/src/durableobject.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function wrapMethodWithSentry<T extends OriginalMethod>(
7979
(e: unknown) => {
8080
captureException(e, {
8181
mechanism: {
82-
type: 'cloudflare_durableobject',
82+
type: 'auto.faas.cloudflare.durable_object',
8383
handled: false,
8484
},
8585
});
@@ -94,7 +94,7 @@ function wrapMethodWithSentry<T extends OriginalMethod>(
9494
} catch (e) {
9595
captureException(e, {
9696
mechanism: {
97-
type: 'cloudflare_durableobject',
97+
type: 'auto.faas.cloudflare.durable_object',
9898
handled: false,
9999
},
100100
});
@@ -106,7 +106,7 @@ function wrapMethodWithSentry<T extends OriginalMethod>(
106106
const attributes = wrapperOptions.spanOp
107107
? {
108108
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: wrapperOptions.spanOp,
109-
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.faas.cloudflare_durableobjects',
109+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.faas.cloudflare.durable_object',
110110
}
111111
: {};
112112

@@ -123,7 +123,7 @@ function wrapMethodWithSentry<T extends OriginalMethod>(
123123
(e: unknown) => {
124124
captureException(e, {
125125
mechanism: {
126-
type: 'cloudflare_durableobject',
126+
type: 'auto.faas.cloudflare.durable_object',
127127
handled: false,
128128
},
129129
});
@@ -138,7 +138,7 @@ function wrapMethodWithSentry<T extends OriginalMethod>(
138138
} catch (e) {
139139
captureException(e, {
140140
mechanism: {
141-
type: 'cloudflare_durableobject',
141+
type: 'auto.faas.cloudflare.durable_object',
142142
handled: false,
143143
},
144144
});
@@ -243,7 +243,7 @@ export function instrumentDurableObjectWithSentry<
243243
(_, error) =>
244244
captureException(error, {
245245
mechanism: {
246-
type: 'cloudflare_durableobject_websocket',
246+
type: 'auto.faas.cloudflare.durable_object_websocket',
247247
handled: false,
248248
},
249249
}),

packages/cloudflare/src/handler.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
5959
apply(target, thisArg, args) {
6060
const [err] = args;
6161

62-
captureException(err, { mechanism: { handled: false, type: 'cloudflare' } });
62+
captureException(err, { mechanism: { handled: false, type: 'auto.faas.cloudflare.error_handler' } });
6363

6464
return Reflect.apply(target, thisArg, args);
6565
},
@@ -97,7 +97,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
9797
try {
9898
return await (target.apply(thisArg, args) as ReturnType<typeof target>);
9999
} catch (e) {
100-
captureException(e, { mechanism: { handled: false, type: 'cloudflare' } });
100+
captureException(e, { mechanism: { handled: false, type: 'auto.faas.cloudflare.scheduled' } });
101101
throw e;
102102
} finally {
103103
waitUntil(flush(2000));
@@ -138,7 +138,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
138138
try {
139139
return await (target.apply(thisArg, args) as ReturnType<typeof target>);
140140
} catch (e) {
141-
captureException(e, { mechanism: { handled: false, type: 'cloudflare' } });
141+
captureException(e, { mechanism: { handled: false, type: 'auto.faas.cloudflare.email' } });
142142
throw e;
143143
} finally {
144144
waitUntil(flush(2000));
@@ -188,7 +188,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
188188
try {
189189
return await (target.apply(thisArg, args) as ReturnType<typeof target>);
190190
} catch (e) {
191-
captureException(e, { mechanism: { handled: false, type: 'cloudflare' } });
191+
captureException(e, { mechanism: { handled: false, type: 'auto.faas.cloudflare.queue' } });
192192
throw e;
193193
} finally {
194194
waitUntil(flush(2000));
@@ -220,7 +220,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
220220
try {
221221
return await (target.apply(thisArg, args) as ReturnType<typeof target>);
222222
} catch (e) {
223-
captureException(e, { mechanism: { handled: false, type: 'cloudflare' } });
223+
captureException(e, { mechanism: { handled: false, type: 'auto.faas.cloudflare.tail' } });
224224
throw e;
225225
} finally {
226226
waitUntil(flush(2000));

packages/cloudflare/src/request.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export function wrapRequestHandler(
8484
return await handler();
8585
} catch (e) {
8686
if (captureErrors) {
87-
captureException(e, { mechanism: { handled: false, type: 'cloudflare' } });
87+
captureException(e, { mechanism: { handled: false, type: 'auto.http.cloudflare' } });
8888
}
8989
throw e;
9090
} finally {
@@ -110,7 +110,7 @@ export function wrapRequestHandler(
110110
return res;
111111
} catch (e) {
112112
if (captureErrors) {
113-
captureException(e, { mechanism: { handled: false, type: 'cloudflare' } });
113+
captureException(e, { mechanism: { handled: false, type: 'auto.http.cloudflare' } });
114114
}
115115
throw e;
116116
} finally {

packages/cloudflare/src/workflows.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class WrappedWorkflowStep implements WorkflowStep {
103103
span.setStatus({ code: 1 });
104104
return result;
105105
} catch (error) {
106-
captureException(error, { mechanism: { handled: true, type: 'cloudflare' } });
106+
captureException(error, { mechanism: { handled: true, type: 'auto.faas.cloudflare.workflow' } });
107107
throw error;
108108
} finally {
109109
this._ctx.waitUntil(flush(2000));

packages/cloudflare/test/handler.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ describe('withSentry', () => {
305305

306306
expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
307307
expect(captureExceptionSpy).toHaveBeenLastCalledWith(error, {
308-
mechanism: { handled: false, type: 'cloudflare' },
308+
mechanism: { handled: false, type: 'auto.faas.cloudflare.scheduled' },
309309
});
310310
});
311311

@@ -545,7 +545,7 @@ describe('withSentry', () => {
545545

546546
expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
547547
expect(captureExceptionSpy).toHaveBeenLastCalledWith(error, {
548-
mechanism: { handled: false, type: 'cloudflare' },
548+
mechanism: { handled: false, type: 'auto.faas.cloudflare.email' },
549549
});
550550
});
551551

@@ -784,7 +784,7 @@ describe('withSentry', () => {
784784

785785
expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
786786
expect(captureExceptionSpy).toHaveBeenLastCalledWith(error, {
787-
mechanism: { handled: false, type: 'cloudflare' },
787+
mechanism: { handled: false, type: 'auto.faas.cloudflare.queue' },
788788
});
789789
});
790790

@@ -1027,7 +1027,7 @@ describe('withSentry', () => {
10271027

10281028
expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
10291029
expect(captureExceptionSpy).toHaveBeenLastCalledWith(error, {
1030-
mechanism: { handled: false, type: 'cloudflare' },
1030+
mechanism: { handled: false, type: 'auto.faas.cloudflare.tail' },
10311031
});
10321032
});
10331033

@@ -1102,7 +1102,7 @@ describe('withSentry', () => {
11021102

11031103
expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
11041104
expect(captureExceptionSpy).toHaveBeenLastCalledWith(error, {
1105-
mechanism: { handled: false, type: 'cloudflare' },
1105+
mechanism: { handled: false, type: 'auto.faas.cloudflare.error_handler' },
11061106
});
11071107
expect(errorHandlerResponse?.status).toBe(500);
11081108
});

0 commit comments

Comments
 (0)