-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
docs(cloudflare): Add TanStack Start on Cloudflare docs #17595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,213 @@ | ||
| --- | ||
| title: TanStack Start on Cloudflare | ||
| description: "Learn how to instrument your TanStack Start app on Cloudflare Workers and capture your first errors with Sentry." | ||
| --- | ||
|
|
||
| <PlatformContent includePath="getting-started-primer" /> | ||
|
|
||
| <Alert level="warning"> | ||
|
|
||
| This guide is for TanStack Start deployed to **Cloudflare Workers** using the `@cloudflare/vite-plugin`. For Node.js-based deployments, see our [TanStack Start guide](/platforms/javascript/guides/tanstackstart-react/). | ||
|
|
||
| </Alert> | ||
|
|
||
| <StepConnector selector="h2" showNumbers={true}> | ||
|
|
||
| ## Install | ||
|
|
||
| Choose the features you want to configure, and this guide will show you how: | ||
|
|
||
| <OnboardingOptionButtons | ||
| options={["error-monitoring", "performance", "logs"]} | ||
| /> | ||
|
|
||
| <Include name="quick-start-features-expandable" /> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be the cloudflare specific include? |
||
|
|
||
| ### Install the Sentry SDK | ||
|
|
||
| <SplitLayout> | ||
| <SplitSection> | ||
| <SplitSectionText> | ||
|
|
||
| Run the command for your preferred package manager to add the Sentry SDK to your application: | ||
|
|
||
| </SplitSectionText> | ||
| <SplitSectionCode> | ||
|
|
||
| <PlatformContent includePath="getting-started-install" /> | ||
|
|
||
| </SplitSectionCode> | ||
| </SplitSection> | ||
| </SplitLayout> | ||
|
|
||
| ## Configure | ||
|
|
||
| When deploying TanStack Start to Cloudflare Workers, you need to wrap the server entry point with `Sentry.withSentry` from `@sentry/cloudflare`. TanStack Start allows you to create a custom server entry file for this purpose. | ||
|
|
||
| ### Wrangler Configuration | ||
|
|
||
| <PlatformContent | ||
| includePath="getting-started-config" | ||
| platform="javascript.cloudflare.splitlayout" | ||
| /> | ||
|
|
||
| ### Create a Custom Server Entry | ||
|
|
||
| <SplitLayout> | ||
| <SplitSection> | ||
| <SplitSectionText> | ||
|
|
||
| Create a `src/server.ts` file that wraps the TanStack Start handler with Sentry: | ||
|
|
||
| </SplitSectionText> | ||
| <SplitSectionCode> | ||
|
|
||
| ```typescript {filename:src/server.ts} | ||
| import * as Sentry from "@sentry/cloudflare"; | ||
| import handler from "@tanstack/react-start/server-entry"; | ||
|
|
||
| export default Sentry.withSentry( | ||
| (env) => ({ | ||
| dsn: env.SENTRY_DSN, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we usually use |
||
| // Adds request headers and IP for users, for more info visit: | ||
| // https://docs.sentry.io/platforms/javascript/guides/cloudflare/configuration/options/#sendDefaultPii | ||
| sendDefaultPii: true, | ||
| // ___PRODUCT_OPTION_START___ logs | ||
|
|
||
| // Enable logs to be sent to Sentry | ||
| enableLogs: true, | ||
| // ___PRODUCT_OPTION_END___ logs | ||
| // ___PRODUCT_OPTION_START___ performance | ||
|
|
||
| // Set tracesSampleRate to 1.0 to capture 100% of spans for tracing. | ||
| tracesSampleRate: 1.0, | ||
| // ___PRODUCT_OPTION_END___ performance | ||
| }), | ||
| handler | ||
| ); | ||
| ``` | ||
|
|
||
| </SplitSectionCode> | ||
| </SplitSection> | ||
| </SplitLayout> | ||
|
|
||
| ### Update Wrangler Configuration | ||
|
|
||
| <SplitLayout> | ||
| <SplitSection> | ||
| <SplitSectionText> | ||
|
|
||
| Update your `wrangler.jsonc` (or `wrangler.toml`) to use your custom server entry: | ||
|
|
||
| </SplitSectionText> | ||
| <SplitSectionCode> | ||
|
|
||
| ```json {diff} {filename:wrangler.jsonc} | ||
| { | ||
| "name": "my-tanstack-app", | ||
| + "main": "src/server.ts", | ||
| // ... rest of config | ||
| } | ||
| ``` | ||
|
|
||
| </SplitSectionCode> | ||
| </SplitSection> | ||
| </SplitLayout> | ||
|
|
||
| ### Configure Client-Side Sentry | ||
|
|
||
| <SplitLayout> | ||
| <SplitSection> | ||
| <SplitSectionText> | ||
|
|
||
| Initialize Sentry in your `src/router.tsx` file for client-side error tracking: | ||
|
|
||
| </SplitSectionText> | ||
| <SplitSectionCode> | ||
|
|
||
| ```tsx {diff} {filename:src/router.tsx} | ||
| +import * as Sentry from "@sentry/tanstackstart-react"; | ||
| import { createRouter } from '@tanstack/react-router' | ||
|
|
||
| export const getRouter = () => { | ||
| const router = createRouter(); | ||
|
|
||
| + if (!router.isServer) { | ||
| + Sentry.init({ | ||
| + dsn: "___PUBLIC_DSN___", | ||
| + integrations: [ | ||
| + // ___PRODUCT_OPTION_START___ performance | ||
| + Sentry.browserTracingIntegration(), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The guide uses the generic Suggested FixReplace Prompt for AI AgentDid we get this right? 👍 / 👎 to inform future reviews.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JPeer264 - is this correct? |
||
| + // ___PRODUCT_OPTION_END___ performance | ||
| + ], | ||
| + // ___PRODUCT_OPTION_START___ performance | ||
| + tracesSampleRate: 1.0, | ||
| + // ___PRODUCT_OPTION_END___ performance | ||
| + }); | ||
| + } | ||
|
Comment on lines
+136
to
+147
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we include any of: sendDefaultPii: true, enableLogs: true (under logs option), Sentry.replayIntegration() (under session-replay option), Sentry.feedbackIntegration() (under user-feedback option), replaysSessionSampleRate/replaysOnErrorSampleRate. Looks like other Cloudflare guides include them. |
||
|
|
||
| return router; | ||
| } | ||
| ``` | ||
|
|
||
| </SplitSectionCode> | ||
| </SplitSection> | ||
| </SplitLayout> | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. m: I think we should also put in here how to set up server side error capturing with the sentry middlewares? |
||
| ### Add Readable Stack Traces With Source Maps (Optional) | ||
|
|
||
| <PlatformContent | ||
| includePath="getting-started-sourcemaps-short-version-splitlayout" | ||
| platform="javascript" | ||
| /> | ||
|
|
||
| ## Verify Your Setup | ||
|
|
||
| <SplitLayout> | ||
| <SplitSection> | ||
| <SplitSectionText> | ||
|
|
||
| To verify Sentry is capturing errors, add a test button to one of your pages: | ||
|
|
||
| </SplitSectionText> | ||
| <SplitSectionCode> | ||
|
|
||
| ```tsx | ||
| <button | ||
| type="button" | ||
| onClick={() => { | ||
| throw new Error("Sentry Test Error"); | ||
| }} | ||
| > | ||
| Break the world | ||
| </button> | ||
| ``` | ||
|
|
||
| </SplitSectionCode> | ||
| </SplitSection> | ||
| </SplitLayout> | ||
|
|
||
| Run your app with `wrangler dev` (or through your Vite build with Cloudflare plugin), click the button, and check your Sentry project for the error. | ||
|
|
||
| <Include name="quick-start-locate-data-expandable" /> | ||
|
|
||
| ## Next Steps | ||
|
|
||
| At this point, you should have integrated Sentry and should already be sending data to your Sentry project. | ||
|
|
||
| Now's a good time to customize your setup and look into more advanced topics. Our next recommended steps for you are: | ||
|
|
||
| - Learn how to [manually capture errors](/platforms/javascript/guides/cloudflare/usage/) | ||
| - Continue to [customize your configuration](/platforms/javascript/guides/cloudflare/configuration/) | ||
| - Make use of [Cloudflare-specific features](/platforms/javascript/guides/cloudflare/features) | ||
| - Get familiar with [Sentry's product features](/product) like tracing, insights, and alerts | ||
|
|
||
| <Expandable permalink={false} title="Are you having problems setting up the SDK?"> | ||
|
|
||
| - Check out setup instructions for other popular [frameworks on Cloudflare](/platforms/javascript/guides/cloudflare/frameworks/) | ||
| - Find various support topics in <PlatformLink to="/troubleshooting">troubleshooting</PlatformLink> | ||
| - [Get support](https://sentry.zendesk.com/hc/en-us/) | ||
|
|
||
| </Expandable> | ||
|
|
||
| </StepConnector> | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we also include session replay and user feedback? They seem to be referenced in other Cloudflare frameworks.