Skip to content

fix(tanstackstart-react): Flush events in server entry point for serverless environments#19513

Merged
nicohrubec merged 3 commits intodevelopfrom
nh/tss-flush
Feb 25, 2026
Merged

fix(tanstackstart-react): Flush events in server entry point for serverless environments#19513
nicohrubec merged 3 commits intodevelopfrom
nh/tss-flush

Conversation

@nicohrubec
Copy link
Member

@nicohrubec nicohrubec commented Feb 25, 2026

As of today server-side Sentry does not work for Tanstack Start if run in serverless environments. Deployment works fine, but no data is actually sent to Sentry. After some experimentation I figured out that we can make it work if we make the following two changes:

  • Import instrument.server.mjs in the server.ts file that has the server entry point. Eventually we can do this automatically during the build, but for now I'll update the documentation to do that.
  • Events need to be explicitly flushed(), so that data is sent off before the serverless function dies. This PR adds a flushIfServerless() call to the wrapFetchWithSentry wrapper.

With these modifications errors, logs and basic tracing work (tested on Netlify and Vercel). For cloudflare we'll likely need a slightly modified approach.

Tests:

  • Added basic unit tests that check that flush() is called.
  • Tried to add a netlify e2e test so we can properly test this behavior, but couldn't get anything server-side to work with that. With manual deployments it works fine.

Closes #19507

@github-actions
Copy link
Contributor

github-actions bot commented Feb 25, 2026

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 25.62 kB - -
@sentry/browser - with treeshaking flags 24.12 kB - -
@sentry/browser (incl. Tracing) 42.42 kB - -
@sentry/browser (incl. Tracing, Profiling) 47.09 kB - -
@sentry/browser (incl. Tracing, Replay) 81.24 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 70.86 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 85.94 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 98.2 kB - -
@sentry/browser (incl. Feedback) 42.43 kB - -
@sentry/browser (incl. sendFeedback) 30.29 kB - -
@sentry/browser (incl. FeedbackAsync) 35.34 kB - -
@sentry/browser (incl. Metrics) 26.79 kB - -
@sentry/browser (incl. Logs) 26.93 kB - -
@sentry/browser (incl. Metrics & Logs) 27.61 kB - -
@sentry/react 27.37 kB - -
@sentry/react (incl. Tracing) 44.76 kB - -
@sentry/vue 30.07 kB - -
@sentry/vue (incl. Tracing) 44.27 kB - -
@sentry/svelte 25.64 kB - -
CDN Bundle 28.16 kB - -
CDN Bundle (incl. Tracing) 43.25 kB - -
CDN Bundle (incl. Logs, Metrics) 29 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 44.09 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 68.08 kB - -
CDN Bundle (incl. Tracing, Replay) 80.13 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 80.99 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 85.64 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 86.53 kB - -
CDN Bundle - uncompressed 82.34 kB - -
CDN Bundle (incl. Tracing) - uncompressed 128.06 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 85.18 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 130.89 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 208.84 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 244.94 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 247.76 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 257.85 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 260.66 kB - -
@sentry/nextjs (client) 47.17 kB - -
@sentry/sveltekit (client) 42.88 kB - -
@sentry/node-core 52.18 kB +0.02% +9 B 🔺
@sentry/node 173.46 kB +0.01% +9 B 🔺
@sentry/node - without tracing 97.33 kB +0.01% +8 B 🔺
@sentry/aws-serverless 113.13 kB +0.01% +8 B 🔺

View base workflow run

@nicohrubec nicohrubec marked this pull request as ready for review February 25, 2026 13:05
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.

@nicohrubec nicohrubec merged commit 89b437f into develop Feb 25, 2026
133 of 135 checks passed
@nicohrubec nicohrubec deleted the nh/tss-flush branch February 25, 2026 15:47
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.

Flush events in server entry point

2 participants