Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
],
Expand All @@ -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';
});
Expand All @@ -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',
},
},
],
Expand Down
26 changes: 23 additions & 3 deletions packages/tanstackstart-react/src/server/wrapFetchWithSentry.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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;
}
},
});
}
Expand Down
Loading