Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- ref(astro): Adjust `mechanism` on error events captured by astro middleware ([#17613](https://github.com/getsentry/sentry-javascript/pull/17613))
- ref(aws-severless): Slightly adjust aws-serverless mechanism type ([#17614](https://github.com/getsentry/sentry-javascript/pull/17614))
- ref(bun): Adjust `mechanism` of errors captured in Bun.serve ([#17616](https://github.com/getsentry/sentry-javascript/pull/17616))
- ref(cloudflare): Adjust event `mechanisms` and durable object origin ([#17618](https://github.com/getsentry/sentry-javascript/pull/17618))
- ref(core): Adjust `mechanism` in `captureConsoleIntegration` ([#17633](https://github.com/getsentry/sentry-javascript/pull/17633))
- ref(core): Adjust MCP server error event `mechanism` ([#17622](https://github.com/getsentry/sentry-javascript/pull/17622))
- ref(core): Simplify `linkedErrors` mechanism logic ([#17600](https://github.com/getsentry/sentry-javascript/pull/17600))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ it('Basic error in fetch handler', async () => {
stacktrace: {
frames: expect.any(Array),
},
mechanism: { type: 'cloudflare', handled: false },
mechanism: { type: 'auto.http.cloudflare', handled: false },
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ it('traces a durable object method', async () => {
op: 'rpc',
data: expect.objectContaining({
'sentry.op': 'rpc',
'sentry.origin': 'auto.faas.cloudflare_durableobjects',
'sentry.origin': 'auto.faas.cloudflare.durable_object',
}),
origin: 'auto.faas.cloudflare_durableobjects',
origin: 'auto.faas.cloudflare.durable_object',
}),
}),
transaction: 'sayHello',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const config = getPlaywrightConfig(
{
// This comes with the risk of tests leaking into each other but the tests run quite slow so we should parallelize
workers: '100%',
retries: 0,
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test('Index page', async ({ baseURL }) => {

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

test('RPC method which throws an exception to be logged to sentry', async ({ baseURL }) => {
const eventWaiter = waitForError('cloudflare-workers', event => {
return event.exception?.values?.[0]?.mechanism?.type === 'cloudflare_durableobject';
return event.exception?.values?.[0]?.mechanism?.type === 'auto.faas.cloudflare.durable_object';
});
const response = await fetch(`${baseURL}/rpc/throwException`);
expect(response.status).toBe(500);
const event = await eventWaiter;
expect(event.exception?.values?.[0]?.value).toBe('Should be recorded in Sentry.');
});

test("Request processed by DurableObject's fetch is recorded", async ({ baseURL }) => {
const eventWaiter = waitForError('cloudflare-workers', event => {
return event.exception?.values?.[0]?.mechanism?.type === 'cloudflare_durableobject';
return event.exception?.values?.[0]?.mechanism?.type === 'auto.faas.cloudflare.durable_object';
});
const response = await fetch(`${baseURL}/pass-to-object/throwException`);
expect(response.status).toBe(500);
const event = await eventWaiter;
expect(event.exception?.values?.[0]?.value).toBe('Should be recorded in Sentry.');
});

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Test Mismatch with Updated Mechanism Type

Some tests in index.test.ts still expect the cloudflare_durableobject mechanism type. This was updated to auto.faas.cloudflare.durable_object in other parts of the PR, causing these tests to miss expected error events.

Fix in Cursor Fix in Web

test('Websocket.webSocketMessage', async ({ baseURL }) => {
const eventWaiter = waitForError('cloudflare-workers', event => {
return event.exception?.values?.[0]?.mechanism?.type === 'cloudflare_durableobject';
return event.exception?.values?.[0]?.mechanism?.type === 'auto.faas.cloudflare.durable_object';
});
const url = new URL('/pass-to-object/ws', baseURL);
url.protocol = url.protocol.replace('http', 'ws');
Expand All @@ -53,7 +55,7 @@ test('Websocket.webSocketMessage', async ({ baseURL }) => {

test('Websocket.webSocketClose', async ({ baseURL }) => {
const eventWaiter = waitForError('cloudflare-workers', event => {
return event.exception?.values?.[0]?.mechanism?.type === 'cloudflare_durableobject';
return event.exception?.values?.[0]?.mechanism?.type === 'auto.faas.cloudflare.durable_object';
});
const url = new URL('/pass-to-object/ws', baseURL);
url.protocol = url.protocol.replace('http', 'ws');
Expand Down
12 changes: 6 additions & 6 deletions packages/cloudflare/src/durableobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function wrapMethodWithSentry<T extends OriginalMethod>(
(e: unknown) => {
captureException(e, {
mechanism: {
type: 'cloudflare_durableobject',
type: 'auto.faas.cloudflare.durable_object',
handled: false,
},
});
Expand All @@ -94,7 +94,7 @@ function wrapMethodWithSentry<T extends OriginalMethod>(
} catch (e) {
captureException(e, {
mechanism: {
type: 'cloudflare_durableobject',
type: 'auto.faas.cloudflare.durable_object',
handled: false,
},
});
Expand All @@ -106,7 +106,7 @@ function wrapMethodWithSentry<T extends OriginalMethod>(
const attributes = wrapperOptions.spanOp
? {
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: wrapperOptions.spanOp,
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.faas.cloudflare_durableobjects',
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.faas.cloudflare.durable_object',
}
: {};

Expand All @@ -123,7 +123,7 @@ function wrapMethodWithSentry<T extends OriginalMethod>(
(e: unknown) => {
captureException(e, {
mechanism: {
type: 'cloudflare_durableobject',
type: 'auto.faas.cloudflare.durable_object',
handled: false,
},
});
Expand All @@ -138,7 +138,7 @@ function wrapMethodWithSentry<T extends OriginalMethod>(
} catch (e) {
captureException(e, {
mechanism: {
type: 'cloudflare_durableobject',
type: 'auto.faas.cloudflare.durable_object',
handled: false,
},
});
Expand Down Expand Up @@ -243,7 +243,7 @@ export function instrumentDurableObjectWithSentry<
(_, error) =>
captureException(error, {
mechanism: {
type: 'cloudflare_durableobject_websocket',
type: 'auto.faas.cloudflare.durable_object_websocket',
handled: false,
},
}),
Expand Down
10 changes: 5 additions & 5 deletions packages/cloudflare/src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
apply(target, thisArg, args) {
const [err] = args;

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

return Reflect.apply(target, thisArg, args);
},
Expand Down Expand Up @@ -97,7 +97,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
try {
return await (target.apply(thisArg, args) as ReturnType<typeof target>);
} catch (e) {
captureException(e, { mechanism: { handled: false, type: 'cloudflare' } });
captureException(e, { mechanism: { handled: false, type: 'auto.faas.cloudflare.scheduled' } });
throw e;
} finally {
waitUntil(flush(2000));
Expand Down Expand Up @@ -138,7 +138,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
try {
return await (target.apply(thisArg, args) as ReturnType<typeof target>);
} catch (e) {
captureException(e, { mechanism: { handled: false, type: 'cloudflare' } });
captureException(e, { mechanism: { handled: false, type: 'auto.faas.cloudflare.email' } });
throw e;
} finally {
waitUntil(flush(2000));
Expand Down Expand Up @@ -188,7 +188,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
try {
return await (target.apply(thisArg, args) as ReturnType<typeof target>);
} catch (e) {
captureException(e, { mechanism: { handled: false, type: 'cloudflare' } });
captureException(e, { mechanism: { handled: false, type: 'auto.faas.cloudflare.queue' } });
throw e;
} finally {
waitUntil(flush(2000));
Expand Down Expand Up @@ -220,7 +220,7 @@ export function withSentry<Env = unknown, QueueHandlerMessage = unknown, CfHostM
try {
return await (target.apply(thisArg, args) as ReturnType<typeof target>);
} catch (e) {
captureException(e, { mechanism: { handled: false, type: 'cloudflare' } });
captureException(e, { mechanism: { handled: false, type: 'auto.faas.cloudflare.tail' } });
throw e;
} finally {
waitUntil(flush(2000));
Expand Down
4 changes: 2 additions & 2 deletions packages/cloudflare/src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function wrapRequestHandler(
return await handler();
} catch (e) {
if (captureErrors) {
captureException(e, { mechanism: { handled: false, type: 'cloudflare' } });
captureException(e, { mechanism: { handled: false, type: 'auto.http.cloudflare' } });
}
throw e;
} finally {
Expand All @@ -110,7 +110,7 @@ export function wrapRequestHandler(
return res;
} catch (e) {
if (captureErrors) {
captureException(e, { mechanism: { handled: false, type: 'cloudflare' } });
captureException(e, { mechanism: { handled: false, type: 'auto.http.cloudflare' } });
}
throw e;
} finally {
Expand Down
2 changes: 1 addition & 1 deletion packages/cloudflare/src/workflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class WrappedWorkflowStep implements WorkflowStep {
span.setStatus({ code: 1 });
return result;
} catch (error) {
captureException(error, { mechanism: { handled: true, type: 'cloudflare' } });
captureException(error, { mechanism: { handled: true, type: 'auto.faas.cloudflare.workflow' } });
throw error;
} finally {
this._ctx.waitUntil(flush(2000));
Expand Down
10 changes: 5 additions & 5 deletions packages/cloudflare/test/handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ describe('withSentry', () => {

expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
expect(captureExceptionSpy).toHaveBeenLastCalledWith(error, {
mechanism: { handled: false, type: 'cloudflare' },
mechanism: { handled: false, type: 'auto.faas.cloudflare.scheduled' },
});
});

Expand Down Expand Up @@ -545,7 +545,7 @@ describe('withSentry', () => {

expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
expect(captureExceptionSpy).toHaveBeenLastCalledWith(error, {
mechanism: { handled: false, type: 'cloudflare' },
mechanism: { handled: false, type: 'auto.faas.cloudflare.email' },
});
});

Expand Down Expand Up @@ -784,7 +784,7 @@ describe('withSentry', () => {

expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
expect(captureExceptionSpy).toHaveBeenLastCalledWith(error, {
mechanism: { handled: false, type: 'cloudflare' },
mechanism: { handled: false, type: 'auto.faas.cloudflare.queue' },
});
});

Expand Down Expand Up @@ -1027,7 +1027,7 @@ describe('withSentry', () => {

expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
expect(captureExceptionSpy).toHaveBeenLastCalledWith(error, {
mechanism: { handled: false, type: 'cloudflare' },
mechanism: { handled: false, type: 'auto.faas.cloudflare.tail' },
});
});

Expand Down Expand Up @@ -1102,7 +1102,7 @@ describe('withSentry', () => {

expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
expect(captureExceptionSpy).toHaveBeenLastCalledWith(error, {
mechanism: { handled: false, type: 'cloudflare' },
mechanism: { handled: false, type: 'auto.faas.cloudflare.error_handler' },
});
expect(errorHandlerResponse?.status).toBe(500);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/cloudflare/test/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ describe('withSentry', () => {

expect(captureExceptionSpy).toHaveBeenCalledTimes(1);
expect(captureExceptionSpy).toHaveBeenLastCalledWith(error, {
mechanism: { handled: false, type: 'cloudflare' },
mechanism: { handled: false, type: 'auto.http.cloudflare' },
});
});

Expand Down
2 changes: 1 addition & 1 deletion packages/cloudflare/test/workflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ describe.skipIf(NODE_MAJOR_VERSION < 20)('workflows', () => {
expect.objectContaining({
type: 'Error',
value: 'Test error',
mechanism: { type: 'cloudflare', handled: true },
mechanism: { type: 'auto.faas.cloudflare.workflow', handled: true },
}),
],
},
Expand Down