Skip to content

Commit 17e30ba

Browse files
docs(js): Create general Cloudflare Quick Start guide (#14541)
<!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> ## DESCRIBE YOUR PR This PR contains the updated Cloudflare Quick Start guide (for general/non-framework setup). I removed the parts about Durable Objects and Workflows (they were mostly links) and instead added a link to the Cloudflare-specific feature page in the Next Steps section. Let me know if you think it makes sense for the Quick Start Guide to add these removed parts back. Note: I made small changes to the framework-specific guides -> they'll get a quick start guide update later in separate PRs. Closes: #14484 ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [x] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/)
1 parent 93a2969 commit 17e30ba

File tree

10 files changed

+181
-66
lines changed

10 files changed

+181
-66
lines changed

docs/platforms/javascript/guides/cloudflare/frameworks/astro.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ After installing the Sentry Astro SDK, you can now install the Sentry Cloudflare
1515

1616
## Setup
1717

18+
The main Sentry configuration should happen as early as possible in your app's lifecycle.
19+
1820
<PlatformContent includePath="getting-started-config" />
1921

2022
Then create a `functions` directory and add a `_middleware.js` file to it with the following code:
@@ -33,4 +35,4 @@ export const onRequest = [
3335
})),
3436
// Add more middlewares here
3537
];
36-
```
38+
```

docs/platforms/javascript/guides/cloudflare/frameworks/hono.mdx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,23 @@ This guide explains how to set up Sentry in your Hono application running on Clo
1111

1212
## Setup
1313

14+
The main Sentry configuration should happen as early as possible in your app's lifecycle.
15+
1416
<PlatformContent includePath="getting-started-config" />
1517

16-
<PlatformContent includePath="getting-started-config" platform="javascript.cloudflare.workers" />
18+
<PlatformContent
19+
includePath="getting-started-config"
20+
platform="javascript.cloudflare.workers"
21+
/>
1722

18-
<PlatformContent includePath="getting-started-config" platform="javascript.hono" />
23+
<PlatformContent
24+
includePath="getting-started-config"
25+
platform="javascript.hono"
26+
/>
1927

2028
## Verify
2129

22-
<PlatformContent includePath="getting-started-verify" platform="javascript.hono" />
30+
<PlatformContent
31+
includePath="getting-started-verify"
32+
platform="javascript.hono"
33+
/>

docs/platforms/javascript/guides/cloudflare/frameworks/nuxt.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ If you installed the SDK before, make sure that `@sentry/nuxt` version `9.37.0`
2424

2525
## Setup
2626

27+
The main Sentry configuration should happen as early as possible in your app's lifecycle.
28+
2729
<PlatformContent includePath="getting-started-config" />
2830

2931
### Adding the Nitro Plugin
@@ -56,5 +58,3 @@ export default defineNitroPlugin(sentryCloudflareNitroPlugin((nitroApp: NitroApp
5658
}
5759
}))
5860
```
59-
60-

docs/platforms/javascript/guides/cloudflare/frameworks/remix.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Now you can install the Sentry Cloudflare SDK. First, install the SDK with your
2323

2424
## Setup
2525

26+
The main Sentry configuration should happen as early as possible in your app's lifecycle.
27+
2628
<PlatformContent includePath="getting-started-config" />
2729

2830
Then create a `_middleware.js` file in your `functions` directory and add the following code:
@@ -39,4 +41,4 @@ export const onRequest = [
3941
})),
4042
// Add more middlewares here
4143
];
42-
```
44+
```

docs/platforms/javascript/guides/cloudflare/frameworks/sveltekit.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ If you installed the SDK before, make sure that `@sentry/sveltekit` version `9.2
2323

2424
## Setup
2525

26+
The main Sentry configuration should happen as early as possible in your app's lifecycle.
27+
2628
<PlatformContent includePath="getting-started-config" />
2729

2830
Next, update your `src/hooks.server.(ts|js)` file to use the `initCloudflareSentryHandle` method from the Sentry Cloudflare SDK and remove the `Sentry.init` call from `@sentry/sveltekit`.
Lines changed: 131 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Cloudflare
3-
description: "Official Sentry SDK for Cloudflare Workers and Cloudflare Pages."
3+
description: "Learn how to manually set up Sentry for Cloudflare Workers and Cloudflare Pages and capture your first errors."
44
sdk: sentry.javascript.cloudflare
55
categories:
66
- javascript
@@ -9,7 +9,7 @@ categories:
99
- serverless
1010
---
1111

12-
You can use the Sentry Cloudflare SDK with popular frameworks running on Cloudflare:
12+
Use this guide for general instructions on using the Sentry SDK with Cloudflare. If you're using any of the listed frameworks, follow their specific setup instructions:
1313

1414
- **[Astro](frameworks/astro/)**
1515
- **[Hono](frameworks/hono/)**
@@ -18,36 +18,41 @@ You can use the Sentry Cloudflare SDK with popular frameworks running on Cloudfl
1818
- **[Remix](frameworks/remix/)**
1919
- **[SvelteKit](frameworks/sveltekit/)**
2020

21-
Take a look at your framework of choice, as there are likely additional instructions for setting up Sentry with it. For more framework-specific guidance, see the [frameworks section](frameworks/).
21+
<PlatformContent includePath="getting-started-prerequisites" />
2222

23-
If you're not using one of these frameworks, or are just looking for general instructions for Cloudflare usage, you're in the right place.
23+
## Step 1: Install
2424

25-
## Features
26-
27-
In addition to capturing errors, you can monitor interactions between multiple services or applications by [enabling tracing](/concepts/key-terms/tracing/).
28-
29-
Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.
25+
Choose the features you want to configure, and this guide will show you how:
3026

3127
<OnboardingOptionButtons
3228
options={["error-monitoring", "performance", "logs"]}
3329
/>
3430

35-
## Install
31+
<PlatformContent includePath="getting-started-features-expandable" />
32+
33+
### Install the Sentry SDK
34+
35+
Run the command for your preferred package manager to add the Sentry SDK to your application:
3636

3737
<PlatformContent includePath="getting-started-install" />
3838

39-
## Setup
39+
## Step 2: Configure
40+
41+
The main Sentry configuration should happen as early as possible in your app's lifecycle.
42+
43+
### Wrangler Configuration
4044

4145
<PlatformContent includePath="getting-started-config" />
4246

43-
### Setup (Cloudflare Workers)
47+
### Setup for Cloudflare Workers
4448

4549
<PlatformContent
4650
includePath="getting-started-config"
4751
platform="javascript.cloudflare.workers"
4852
/>
4953

50-
If you do not have access to the `onRequest` middleware API, you can use the `wrapRequestHandler` API instead. For example:
54+
<Expandable title="Don't have access to onRequest?">
55+
If you don't have access to the `onRequest` middleware API, you can use the `wrapRequestHandler` API instead. For example:
5156

5257
```javascript
5358
// hooks.server.js
@@ -66,12 +71,12 @@ export const handle = ({ event, resolve }) => {
6671
};
6772
```
6873

69-
### Setup (Cloudflare Pages)
74+
</Expandable>
7075

71-
To use this SDK, add the `sentryPagesPlugin` as [middleware to your Cloudflare Pages application](https://developers.cloudflare.com/pages/functions/middleware/).
76+
### Setup for Cloudflare Pages
7277

73-
We recommend adding a `functions/_middleware.js` for the middleware setup so that Sentry is initialized for your entire
74-
app.
78+
To use the Sentry SDK, add the `sentryPagesPlugin` as [middleware to your Cloudflare Pages application](https://developers.cloudflare.com/pages/functions/middleware/).
79+
For this, we recommend you create a `functions/_middleware.js` file to set up the middleware for your entire app:
7580

7681
```javascript {filename:functions/_middleware.js}
7782
import * as Sentry from "@sentry/cloudflare";
@@ -94,11 +99,11 @@ export const onRequest = [
9499
// Enable logs to be sent to Sentry
95100
enableLogs: true,
96101
// ___PRODUCT_OPTION_END___ logs
97-
98102
// ___PRODUCT_OPTION_START___ performance
103+
99104
// Set tracesSampleRate to 1.0 to capture 100% of spans for tracing.
100105
// Learn more at
101-
// https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
106+
// https://docs.sentry.io/platforms/javascript/guides/cloudflare/configuration/options/#tracesSampleRate
102107
tracesSampleRate: 1.0,
103108
// ___PRODUCT_OPTION_END___ performance
104109
};
@@ -107,58 +112,135 @@ export const onRequest = [
107112
];
108113
```
109114

110-
### Cloudflare Durable Objects
115+
## Step 3: Add Readable Stack Traces With Source Maps (Optional)
111116

112-
You can use the `instrumentDurableObjectWithSentry` method to instrument [Cloudflare Durable Objects](https://developers.cloudflare.com/durable-objects/). This will need to be done alongside the worker setup.
117+
The stack traces in your Sentry errors probably won't look like your actual code. To fix this, upload your source maps to Sentry.
113118

114-
See the [Cloudflare Durable Objects](features/durableobject/) guide for more information.
119+
First, set the `upload_source_maps` option to `true` in your `wrangler.(jsonc|toml)` config file to enable source map uploading:
115120

116-
### Cloudflare Workflows
121+
```jsonc {tabTitle:JSON} {filename:wrangler.jsonc}
122+
{
123+
"upload_source_maps": true,
124+
}
125+
```
117126

118-
You can use the `instrumentWorkflowWithSentry` method to instrument [Cloudflare Workflows](https://developers.cloudflare.com/workflows/). This will need to be done alongside the worker setup.
127+
```toml {tabTitle:Toml} {filename:wrangler.toml}
128+
upload_source_maps = true
129+
```
119130

120-
See the [Cloudflare Workflows](features/workflows/) guide for more information.
131+
Next, run the Sentry Wizard to finish your setup:
121132

122-
## Add Readable Stack Traces to Errors
133+
```bash
134+
npx @sentry/wizard@latest -i sourcemaps
135+
```
123136

124-
Depending on how you've set up your project, the stack traces in your Sentry errors probably don't look like your actual code.
137+
## Step 4: Verify Your Setup
125138

126-
To fix this, upload your source maps to Sentry.
139+
Let's test your setup and confirm that Sentry is working correctly and sending data to your Sentry project.
127140

128-
To start, set the `upload_source_maps` option to `true` in your wrangler config file to enable source map uploading.
141+
### Issues
129142

130-
```jsonc {tabTitle:JSON} {filename:wrangler.jsonc}
131-
{
132-
"upload_source_maps": true,
143+
First, let's make sure Sentry is correctly capturing errors and creating issues in your project.
144+
145+
#### Cloudflare Workers
146+
147+
Add the following code snippet to your main worker file to create a `/debug-sentry` route that triggers an error when called:
148+
149+
```javascript {filename:index.js}
150+
export default {
151+
async fetch(request) {
152+
const url = new URL(request.url);
153+
154+
if (url.pathname === "/debug-sentry") {
155+
throw new Error("My first Sentry error!");
156+
}
157+
158+
// Your existing routes and logic here...
159+
return new Response("...");
160+
},
161+
};
162+
```
163+
164+
#### Cloudflare Pages
165+
166+
Create a new route that throws an error when called by adding the following code snippet to a file in your `functions` directory, such as `functions/debug-sentry.js`:
167+
168+
```javascript {filename:debug-sentry.js}
169+
export async function onRequest(context) {
170+
throw new Error("My first Sentry error!");
133171
}
134172
```
135173

136-
```toml {tabTitle:Toml} {filename:wrangler.toml}
137-
upload_source_maps = true
174+
<OnboardingOption optionId="performance">
175+
### Tracing
176+
To test your tracing configuration, update the previous code snippet by starting a trace to measure the time it takes to run your code.
177+
178+
#### Cloudflare Workers
179+
180+
```javascript {filename:index.js}
181+
export default {
182+
async fetch(request) {
183+
const url = new URL(request.url);
184+
185+
if (url.pathname === "/debug-sentry") {
186+
await Sentry.startSpan(
187+
{
188+
op: "test",
189+
name: "My First Test Transaction",
190+
},
191+
async () => {
192+
await new Promise((resolve) => setTimeout(resolve, 100)); // Wait for 100ms
193+
throw new Error("My first Sentry error!");
194+
}
195+
);
196+
}
197+
198+
// Your existing routes and logic here...
199+
return new Response("...");
200+
},
201+
};
202+
```
203+
204+
#### Cloudflare Pages
205+
206+
```javascript {filename:debug-sentry.js}
207+
export async function onRequest(context) {
208+
await Sentry.startSpan(
209+
{
210+
op: "test",
211+
name: "My First Test Transaction",
212+
},
213+
async () => {
214+
await new Promise((resolve) => setTimeout(resolve, 100)); // Wait for 100ms
215+
throw new Error("My first Sentry error!");
216+
}
217+
);
218+
}
138219
```
139220

140-
Then run the Sentry Wizard to finish your setup:
221+
</OnboardingOption>
141222

142-
<Include name="sourcemaps-wizard-instructions.mdx" />
223+
### View Captured Data in Sentry
143224

144-
For more information on source maps or for more options to upload them, head over to our <PlatformLink to="/sourcemaps/">Source Maps</PlatformLink> documentation.
225+
Now, head over to your project on [Sentry.io](https://sentry.io) to view the collected data (it takes a couple of moments for the data to appear).
145226

146-
## Verify
227+
<PlatformContent includePath="getting-started-verify-locate-data" />
147228

148-
This snippet includes an intentional error, so you can test that everything is working as soon as you set it up.
229+
## Next Steps
149230

150-
Verify your setup by adding the following snippet anywhere in your code and running it:
231+
At this point, you should have integrated Sentry and should already be sending data to your Sentry project.
151232

152-
```javascript
153-
setTimeout(() => {
154-
throw new Error();
155-
});
156-
```
233+
Now's a good time to customize your setup and look into more advanced topics. Our next recommended steps for you are:
157234

158-
<Alert>
235+
- Learn how to [manually capture errors](/platforms/javascript/guides/cloudflare/usage/)
236+
- Continue to [customize your configuration](/platforms/javascript/guides/cloudflare/configuration/)
237+
- Make use of [Cloudflare-specific features](/platforms/javascript/guides/cloudflare/features)
238+
- Get familiar with [Sentry's product features](/product) like tracing, insights, and alerts
159239

160-
Learn more about manually capturing an error or message in our <PlatformLink to="/usage/">Usage documentation</PlatformLink>.
240+
<Expandable permalink={false} title="Are you having problems setting up the SDK?">
161241

162-
</Alert>
242+
- Check out setup instructions for popular [frameworks on Cloudflare](/platforms/javascript/guides/cloudflare/frameworks/)
243+
- Find various support topics in <PlatformLink to="/troubleshooting">troubleshooting</PlatformLink>
244+
- [Get support](https://sentry.zendesk.com/hc/en-us/)
163245

164-
To view and resolve the recorded error, log into [sentry.io](https://sentry.io) and select your project. Clicking on the error's title will open a page where you can see detailed information and mark it as resolved.
246+
</Expandable>

platform-includes/getting-started-config/javascript.cloudflare.mdx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
Configuration should happen as early as possible in your application's lifecycle.
2-
3-
To use the SDK, you'll need to set either the `nodejs_compat` or `nodejs_als` compatibility flags in your `wrangler.jsonc` / `wrangler.toml` config. This is because the SDK needs access to the `AsyncLocalStorage` API to work correctly.
1+
Since the SDK needs access to the `AsyncLocalStorage` API, you need to set either the `nodejs_compat` or `nodejs_als` compatibility flags in your `wrangler.(jsonc|toml)` configuration file:
42

53
```jsonc {tabTitle:JSON} {filename:wrangler.jsonc}
64
{
@@ -16,13 +14,13 @@ compatibility_flags = ["nodejs_als"]
1614
# compatibility_flags = ["nodejs_compat"]
1715
```
1816

19-
You will also want to add the `CF_VERSION_METADATA` binding:
17+
Additionally, add the `CF_VERSION_METADATA` binding in the same file:
2018

2119
```jsonc {tabTitle:JSON} {filename:wrangler.jsonc}
2220
{
2321
// ...
2422
"version_metadata": {
25-
"binding": "CF_VERSION_METADATA"
23+
"binding": "CF_VERSION_METADATA",
2624
},
2725
}
2826
```

0 commit comments

Comments
 (0)