sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

React Router v7 deployed to Cloudflare Workers

Open souredoutlook opened this issue 8 months ago • 3 comments

Description

This is an issue that serves as a place-holder for Abhi to investigate how best to instrument a React Router v7 app that is deployed to Cloudflare Workers

At this time we are recommending folks instrument /cloudflare/worker/app.ts with @sentry/cloudflare to start

souredoutlook avatar Apr 24 '25 14:04 souredoutlook

This won't be done until the React Router SDK is in a stable state, so https://github.com/getsentry/sentry-javascript/issues/14519 is closed

AbhiPrasad avatar Apr 24 '25 14:04 AbhiPrasad

@souredoutlook Are you referring to this? https://github.com/getsentry/sentry-javascript/tree/master/packages/cloudflare#setup-cloudflare-workers

or something more like Toucan.js

airtonix avatar Jun 14 '25 02:06 airtonix

I recommend following the docs here: https://docs.sentry.io/platforms/javascript/guides/cloudflare/

but yup, that's what is being referred to.

AbhiPrasad avatar Jun 16 '25 13:06 AbhiPrasad

From the experimental framework mode docs, how much of that can be reused for cloudflare workers? It seems that the only node-specific instruction is importing the instrumentation as a module before running the server. Can this be done in a cloudflare based environment too?

moishinetzer avatar Jun 19 '25 00:06 moishinetzer

You can probably replace Sentry.createSentryHandleRequest with the wrapRequestHandler method from https://docs.sentry.io/platforms/javascript/guides/cloudflare/#setup-cloudflare-workers - but I haven't tested this out.

AbhiPrasad avatar Jun 19 '25 21:06 AbhiPrasad

given #14519 is closed, is there a next step? i'm unsure if I should be following the cloudflare setup, the react router setup, or the cloudflare hydrogen react router setup (which is not particularly hydrogen specific but is about cloudflare + react router)

sebws avatar Oct 03 '25 04:10 sebws

@sebws in case you're using hydrogen you can follow this guide. Otherwise I'd just follow the standard react-router guide for now, but make sure to import the server instrumentation file. React router will add better support for server-side tracing soon, we'll update the SDK accordingly.

chargome avatar Oct 03 '25 08:10 chargome

@chargome thanks for the quick response!

i have tried for my (not hydrogen) react router v7 cloudflare site

one note – in entry.server.tsx and instrument.server.ts I have used @sentry/react-router/cloudflare which has some different exports for this case. I've used wrapSentryHandleRequest and done the "Do you need to customize your handleError function?" error handler

looking forward to the better react router support!

edit:

I also added the extra cloudflare integration using Sentry.withSentry in the worker export.

sebws avatar Oct 06 '25 22:10 sebws