diff --git a/dev-packages/e2e-tests/test-applications/tanstackstart-react/tests/errors.test.ts b/dev-packages/e2e-tests/test-applications/tanstackstart-react/tests/errors.test.ts index f5d25febb7a4..bd2832bb5d9b 100644 --- a/dev-packages/e2e-tests/test-applications/tanstackstart-react/tests/errors.test.ts +++ b/dev-packages/e2e-tests/test-applications/tanstackstart-react/tests/errors.test.ts @@ -52,6 +52,7 @@ test('Sends server-side function error to Sentry with auto-instrumentation', asy value: 'Sentry Server Function Test Error', mechanism: { handled: false, + type: 'auto.function.tanstackstart.server', }, }, ], @@ -61,7 +62,7 @@ test('Sends server-side function error to Sentry with auto-instrumentation', asy expect(errorEvent.transaction).toBe('/'); }); -test('Sends API route error to Sentry if manually instrumented', async ({ page }) => { +test('Sends API route error to Sentry with auto-instrumentation', async ({ page }) => { const errorEventPromise = waitForError('tanstackstart-react', errorEvent => { return errorEvent?.exception?.values?.[0]?.value === 'Sentry API Route Test Error'; }); @@ -81,7 +82,8 @@ test('Sends API route error to Sentry if manually instrumented', async ({ page } type: 'Error', value: 'Sentry API Route Test Error', mechanism: { - handled: true, + handled: false, + type: 'auto.function.tanstackstart.server', }, }, ], diff --git a/packages/tanstackstart-react/src/server/wrapFetchWithSentry.ts b/packages/tanstackstart-react/src/server/wrapFetchWithSentry.ts index 22d218ef0b48..c0ac4b57a757 100644 --- a/packages/tanstackstart-react/src/server/wrapFetchWithSentry.ts +++ b/packages/tanstackstart-react/src/server/wrapFetchWithSentry.ts @@ -1,4 +1,4 @@ -import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, startSpan } from '@sentry/node'; +import { captureException, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, startSpan } from '@sentry/node'; import { extractServerFunctionSha256 } from './utils'; export type ServerEntry = { @@ -55,12 +55,32 @@ export function wrapFetchWithSentry(serverEntry: ServerEntry): ServerEntry { attributes: serverFunctionSpanAttributes, }, () => { - return target.apply(thisArg, args); + try { + return target.apply(thisArg, args); + } catch (error) { + captureException(error, { + mechanism: { + handled: false, + type: 'auto.function.tanstackstart.server', + }, + }); + throw error; + } }, ); } - return target.apply(thisArg, args); + try { + return target.apply(thisArg, args); + } catch (error) { + captureException(error, { + mechanism: { + handled: false, + type: 'auto.function.tanstackstart.server', + }, + }); + throw error; + } }, }); }