You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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/)
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`.
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."
4
4
sdk: sentry.javascript.cloudflare
5
5
categories:
6
6
- javascript
@@ -9,7 +9,7 @@ categories:
9
9
- serverless
10
10
---
11
11
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:
13
13
14
14
-**[Astro](frameworks/astro/)**
15
15
-**[Hono](frameworks/hono/)**
@@ -18,36 +18,41 @@ You can use the Sentry Cloudflare SDK with popular frameworks running on Cloudfl
18
18
-**[Remix](frameworks/remix/)**
19
19
-**[SvelteKit](frameworks/sveltekit/)**
20
20
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/).
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
24
24
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:
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
72
77
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:
75
80
76
81
```javascript {filename:functions/_middleware.js}
77
82
import*asSentryfrom"@sentry/cloudflare";
@@ -94,11 +99,11 @@ export const onRequest = [
94
99
// Enable logs to be sent to Sentry
95
100
enableLogs:true,
96
101
// ___PRODUCT_OPTION_END___ logs
97
-
98
102
// ___PRODUCT_OPTION_START___ performance
103
+
99
104
// Set tracesSampleRate to 1.0 to capture 100% of spans for tracing.
##Step 3: Add Readable Stack Traces With Source Maps (Optional)
111
116
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.
113
118
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:
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
+
```
119
130
120
-
See the [Cloudflare Workflows](features/workflows/) guide for more information.
131
+
Next, run the Sentry Wizard to finish your setup:
121
132
122
-
## Add Readable Stack Traces to Errors
133
+
```bash
134
+
npx @sentry/wizard@latest -i sourcemaps
135
+
```
123
136
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
125
138
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.
127
140
128
-
To start, set the `upload_source_maps` option to `true` in your wrangler config file to enable source map uploading.
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
+
exportdefault {
151
+
asyncfetch(request) {
152
+
consturl=newURL(request.url);
153
+
154
+
if (url.pathname==="/debug-sentry") {
155
+
thrownewError("My first Sentry error!");
156
+
}
157
+
158
+
// Your existing routes and logic here...
159
+
returnnewResponse("...");
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
+
exportasyncfunctiononRequest(context) {
170
+
thrownewError("My first Sentry error!");
133
171
}
134
172
```
135
173
136
-
```toml {tabTitle:Toml} {filename:wrangler.toml}
137
-
upload_source_maps = true
174
+
<OnboardingOptionoptionId="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
+
exportdefault {
182
+
asyncfetch(request) {
183
+
consturl=newURL(request.url);
184
+
185
+
if (url.pathname==="/debug-sentry") {
186
+
awaitSentry.startSpan(
187
+
{
188
+
op:"test",
189
+
name:"My First Test Transaction",
190
+
},
191
+
async () => {
192
+
awaitnewPromise((resolve) =>setTimeout(resolve, 100)); // Wait for 100ms
193
+
thrownewError("My first Sentry error!");
194
+
}
195
+
);
196
+
}
197
+
198
+
// Your existing routes and logic here...
199
+
returnnewResponse("...");
200
+
},
201
+
};
202
+
```
203
+
204
+
#### Cloudflare Pages
205
+
206
+
```javascript {filename:debug-sentry.js}
207
+
exportasyncfunctiononRequest(context) {
208
+
awaitSentry.startSpan(
209
+
{
210
+
op:"test",
211
+
name:"My First Test Transaction",
212
+
},
213
+
async () => {
214
+
awaitnewPromise((resolve) =>setTimeout(resolve, 100)); // Wait for 100ms
For more information on source maps or for more options to upload them, head over to our <PlatformLinkto="/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).
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.
Copy file name to clipboardExpand all lines: platform-includes/getting-started-config/javascript.cloudflare.mdx
+3-5Lines changed: 3 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff 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:
0 commit comments