Skip to content

feat(tanstackstart-react): Add global sentry exception middlewares#19330

Merged
nicohrubec merged 22 commits intodevelopfrom
nh/tss-error-middleware
Feb 17, 2026
Merged

feat(tanstackstart-react): Add global sentry exception middlewares#19330
nicohrubec merged 22 commits intodevelopfrom
nh/tss-error-middleware

Conversation

@nicohrubec
Copy link
Member

@nicohrubec nicohrubec commented Feb 16, 2026

This PR adds sentryGlobalRequestMiddleware and sentryGlobalFunctionMiddleware that capture unhandled errors from all HTTP requests and server function invocations. Users add these as the first entries in the requestMiddleware / functionMiddleware arrays of createStart(). These internal middlewares get marked with a __SENTRY_INTERNAL__, so that they can be easily skipped in the vite plugin to exclude them from middleware auto-instrumentation. Originally we wanted to do this in the server-entry-point, but since there haven't been any updates on this front in months I propose this as an alternative solution for now. This is probably slightly worse UX but in my case better than having nothing in place.

We could also think about auto-injecting this during the build, but maybe not worth the effort since this is a one-time setup step.

Limitations

Tanstack Start has three types of server-side errors that we care about. With these middlewares we can capture 2 of these (route, function exceptions). We cannot capture SSR exceptions like this, because the exceptions are serialized at a deeper layer and newer thrown.

Usage

import { sentryGlobalFunctionMiddleware, sentryGlobalRequestMiddleware } from '@sentry/tanstackstart-react';
import { createStart } from '@tanstack/react-start';

export const startInstance = createStart(() => ({
  requestMiddleware: [sentryGlobalRequestMiddleware, ...otherMiddleware],
  functionMiddleware: [sentryGlobalFunctionMiddleware, ...otherMiddleware],
}));

Tests

  • Updated E2E tests to verify server side function/route errors are being captured
  • Added an E2E test to document that SSR exceptions are NOT being captured

Closes #18283

@github-actions
Copy link
Contributor

github-actions bot commented Feb 16, 2026

Codecov Results 📊


Generated by Codecov Action

@github-actions
Copy link
Contributor

github-actions bot commented Feb 16, 2026

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 8,523 - 11,206 -24%
GET With Sentry 1,580 19% 1,856 -15%
GET With Sentry (error only) 5,978 70% 7,570 -21%
POST Baseline 1,135 - 1,166 -3%
POST With Sentry 569 50% 572 -1%
POST With Sentry (error only) 1,018 90% 1,025 -1%
MYSQL Baseline 3,246 - 3,984 -19%
MYSQL With Sentry 445 14% 515 -14%
MYSQL With Sentry (error only) 2,608 80% 3,288 -21%

View base workflow run

@nicohrubec nicohrubec changed the title feat(tanstackstart-react): Add sentry exception middleware feat(tanstackstart-react): Add global sentry exception middlewares Feb 16, 2026
// eslint-disable-next-line @typescript-eslint/no-explicit-any
'~types': any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
options: { server?: (...args: any[]) => any };
Copy link
Member Author

Choose a reason for hiding this comment

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

typescript kept complaining in my sample app that the types of the new sentry middlewares clash with what is expected from tanstack (it was still running fine thought), had to change it to this to fix that

@nicohrubec nicohrubec marked this pull request as ready for review February 16, 2026 15:22
Copy link
Member

@andreiborza andreiborza left a comment

Choose a reason for hiding this comment

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

LGTM overall! Nice workaround for the time being.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 17, 2026

size-limit report 📦

Path Size % Change Change
@sentry/browser 25.56 kB - -
@sentry/browser - with treeshaking flags 24.08 kB - -
@sentry/browser (incl. Tracing) 42.36 kB - -
@sentry/browser (incl. Tracing, Profiling) 47.03 kB - -
@sentry/browser (incl. Tracing, Replay) 81.18 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 70.8 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 85.87 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 98.03 kB - -
@sentry/browser (incl. Feedback) 42.29 kB - -
@sentry/browser (incl. sendFeedback) 30.23 kB - -
@sentry/browser (incl. FeedbackAsync) 35.22 kB - -
@sentry/browser (incl. Metrics) 26.74 kB - -
@sentry/browser (incl. Logs) 26.88 kB - -
@sentry/browser (incl. Metrics & Logs) 27.56 kB - -
@sentry/react 27.33 kB - -
@sentry/react (incl. Tracing) 44.72 kB - -
@sentry/vue 30.01 kB - -
@sentry/vue (incl. Tracing) 44.22 kB - -
@sentry/svelte 25.58 kB - -
CDN Bundle 28.11 kB - -
CDN Bundle (incl. Tracing) 43.2 kB - -
CDN Bundle (incl. Logs, Metrics) 28.95 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 44.03 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 68.02 kB - -
CDN Bundle (incl. Tracing, Replay) 80.07 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 80.94 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 85.5 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 86.4 kB - -
CDN Bundle - uncompressed 82.22 kB - -
CDN Bundle (incl. Tracing) - uncompressed 127.93 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 85.05 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 130.76 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 208.71 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 244.81 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 247.63 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 257.61 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 260.42 kB - -
@sentry/nextjs (client) 47.07 kB - -
@sentry/sveltekit (client) 42.81 kB - -
@sentry/node-core 52.15 kB +0.02% +9 B 🔺
@sentry/node 166.53 kB +0.01% +5 B 🔺
@sentry/node - without tracing 93.95 kB +0.02% +12 B 🔺
@sentry/aws-serverless 109.45 kB +0.01% +9 B 🔺

View base workflow run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Capture server-side errors

2 participants