Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add test: manual instrumentation works in server routes
  • Loading branch information
nicohrubec committed Dec 3, 2025
commit 860af0e16b26b8a50136c5f7341a3cbcdc95b813
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as Sentry from '@sentry/tanstackstart-react';
import { createFileRoute } from '@tanstack/react-router'

export const Route = createFileRoute('/api/error')({
server: {
handlers: {
GET: async () => {
// This will throw a server-side error that Sentry should catch
try {
throw new Error('Sentry API Route Test Error');
} catch (error) {
Sentry.captureException(error);
throw error;
}
},
},
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ function Home() {
>
Break server function
</button>
<button
type="button"
onClick={async () => {
await fetch('/api/error');
}}
>
Break API route
</button>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,33 @@ 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 }) => {
const errorEventPromise = waitForError('tanstackstart-react', errorEvent => {
return errorEvent?.exception?.values?.[0]?.value === 'Sentry API Route Test Error';
});

await page.goto(`/`);

await expect(page.locator('button').filter({ hasText: 'Break API route' })).toBeVisible();

await page.locator('button').filter({ hasText: 'Break API route' }).click();

const errorEvent = await errorEventPromise;

expect(errorEvent).toMatchObject({
exception: {
values: [
{
type: 'Error',
value: 'Sentry API Route Test Error',
mechanism: {
handled: true,
Comment thread
nicohrubec marked this conversation as resolved.
},
},
],
},
});

expect(errorEvent.transaction).toBe('GET /api/error');
});