Skip to content

Commit e7a710b

Browse files
committed
feat: Overhaul Cloudflare docs
- Move various snippets into includes - Cover the 'release' attribute on all worker snippets - General normalization
1 parent 6a97429 commit e7a710b

File tree

8 files changed

+138
-220
lines changed

8 files changed

+138
-220
lines changed

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

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ title: Cloudflare Astro Framework Guide
33
description: "Learn how to add Cloudflare instrumentation to your Astro app."
44
---
55

6+
## Install
7+
68
If you're running your Astro app on Cloudflare Pages, you can use the Sentry Astro SDK in combination with the Sentry Cloudflare SDK to add Sentry instrumentation.
79

810
First, install the Sentry Astro SDK in your application. We recommend [setting up the Astro SDK manually](/platforms/javascript/guides/astro/manual-setup/) and manually initializing the SDK. Make sure you have a `sentry.client.config.js` file created, but do not add a `sentry.server.config.js` file.
@@ -11,27 +13,9 @@ After installing the Sentry Astro SDK, you can now install the Sentry Cloudflare
1113

1214
<PlatformContent includePath="getting-started-install" />
1315

14-
To use the SDK, you'll need to set either the `nodejs_als` or `nodejs_compat` compatibility flags in your `wrangler.jsonc`/`wrangler.toml` config. This is because the SDK
15-
needs access to the `AsyncLocalStorage` API to work correctly.
16-
17-
```jsonc {tabTitle:JSON} {filename:wrangler.jsonc}
18-
{
19-
"compatibility_flags": [
20-
"nodejs_als",
21-
// "nodejs_compat"
22-
],
23-
}
24-
```
25-
26-
```toml {tabTitle:Toml} {filename:wrangler.toml}
27-
compatibility_flags = ["nodejs_als"]
28-
# compatibility_flags = ["nodejs_compat"]
29-
```
30-
31-
```toml {tabTitle:Toml} {filename:wrangler.toml}
32-
compatibility_flags = ["nodejs_compat"]
33-
# compatibility_flags = ["nodejs_als"]
34-
```
16+
## Setup
17+
18+
<PlatformContent includePath="getting-started-config" />
3519

3620
Then create a `functions` directory and add a `_middleware.js` file to it with the following code:
3721

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

Lines changed: 5 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -5,75 +5,15 @@ description: "Learn how to add Cloudflare instrumentation to your Hono app."
55

66
This guide explains how to set up Sentry in your Hono application running on Cloudflare Workers.
77

8-
## Setup
9-
10-
To use the SDK, you'll need to set either the `nodejs_als` or `nodejs_compat` compatibility flags in your `wrangler.jsonc`/`wrangler.toml` config. This is because the SDK
11-
needs access to the `AsyncLocalStorage` API to work correctly.
12-
13-
```jsonc {tabTitle:JSON} {filename:wrangler.jsonc}
14-
{
15-
"compatibility_flags": [
16-
"nodejs_als",
17-
// "nodejs_compat"
18-
],
19-
}
20-
```
21-
22-
```toml {tabTitle:Toml} {filename:wrangler.toml}
23-
compatibility_flags = ["nodejs_als"]
24-
# compatibility_flags = ["nodejs_compat"]
25-
```
26-
27-
You will also want to add the `CF_VERSION_METADATA` binding:
28-
29-
```jsonc {tabTitle:JSON} {filename:wrangler.jsonc}
30-
{
31-
// ...
32-
"version_metadata": {
33-
"binding": "CF_VERSION_METADATA"
34-
},
35-
}
36-
```
8+
## Install
379

38-
```toml {tabTitle:Toml} {filename:wrangler.toml}
39-
version_metadata = { binding = "CF_VERSION_METADATA" }
40-
```
10+
<PlatformContent includePath="getting-started-install" />
4111

42-
## Config
43-
44-
Next, wrap your worker handler with the `withSentry` function. This will initialize the SDK and hook into the
45-
environment. Note that you can turn off almost all side effects using the respective options.
46-
47-
```typescript {filename:index.ts}
48-
import { Hono, HTTPException } from "hono";
49-
import * as Sentry from "@sentry/cloudflare";
50-
51-
// Wrap your Worker binding with Sentry to ensure tracing instrumentation is enabled,
52-
// and Sentry telemetry is flushed at the end of requests.
53-
export default Sentry.withSentry(
54-
(env) => {
55-
const { id: versionId } = env.CF_VERSION_METADATA;
56-
57-
return {
58-
dsn: "___PUBLIC_DSN___",
59-
60-
release: versionId,
12+
## Setup
6113

62-
// Adds request headers and IP for users, for more info visit:
63-
// https://docs.sentry.io/platforms/javascript/guides/cloudflare/configuration/options/#sendDefaultPii
64-
sendDefaultPii: true,
14+
<PlatformContent includePath="getting-started-config" />
6515

66-
// ___PRODUCT_OPTION_START___ performance
67-
// Set tracesSampleRate to 1.0 to capture 100% of spans for tracing.
68-
// Learn more at
69-
// https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
70-
tracesSampleRate: 1.0,
71-
// ___PRODUCT_OPTION_END___ performance
72-
}
73-
},
74-
app
75-
);
76-
```
16+
<PlatformContent includePath="getting-started-config" platform="javascript.cloudflare.workers" />
7717

7818
<PlatformContent includePath="getting-started-config" platform="javascript.hono" />
7919

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

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: "Learn how to add Cloudflare instrumentation to your Remix app."
55

66
If you're running your Remix app on Cloudflare Pages, you can use the Sentry Remix SDK in combination with the Sentry Cloudflare SDK to add Sentry instrumentation.
77

8-
## 1. Installing Sentry Remix SDK
8+
## Install
99

1010
First, install the Sentry Remix SDK in your application. We recommend using the Sentry wizard to automatically install the SDK:
1111

@@ -15,30 +15,15 @@ npx @sentry/wizard@latest -i remix
1515

1616
If the setup through the wizard doesn't work for you, you can also [set up the Remix SDK manually](/platforms/javascript/guides/remix/manual-setup/).
1717

18-
## 2. Installing Sentry Cloudflare SDK
19-
2018
After installing the Sentry Remix SDK, delete the newly generated `instrumentation.server.mjs` file. This instrumentation is not needed when using the Cloudflare SDK.
2119

2220
Now you can install the Sentry Cloudflare SDK. First, install the SDK with your package manager:
2321

2422
<PlatformContent includePath="getting-started-install" />
2523

26-
To use the SDK, you'll need to set either the `nodejs_als` or `nodejs_compat` compatibility flags in your `wrangler.jsonc`/`wrangler.toml` config. This is because the SDK
27-
needs access to the `AsyncLocalStorage` API to work correctly.
28-
29-
```jsonc {tabTitle:JSON} {filename:wrangler.jsonc}
30-
{
31-
"compatibility_flags": [
32-
"nodejs_als",
33-
// "nodejs_compat"
34-
],
35-
}
36-
```
24+
## Setup
3725

38-
```toml {tabTitle:Toml} {filename:wrangler.toml}
39-
compatibility_flags = ["nodejs_als"]
40-
# compatibility_flags = ["nodejs_compat"]
41-
```
26+
<PlatformContent includePath="getting-started-config" />
4227

4328
Then create a `_middleware.js` file in your `functions` directory and add the following code:
4429

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

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: "Learn how to add Cloudflare instrumentation to your SvelteKit app.
55

66
If you're running your SvelteKit app on Cloudflare Pages, you need to configure the SDK a little differently to the default setup. This guide will show you how to set up the Sentry SvelteKit SDK for Cloudflare Pages.
77

8-
## 1. Install the SDK
8+
## Install
99

1010
First, install the Sentry SvelteKit SDK in your application. We recommend using the Sentry wizard to automatically install the SDK:
1111

@@ -21,28 +21,15 @@ If you installed the SDK before, make sure that `@sentry/sveltekit` version `9.2
2121

2222
</Alert>
2323

24-
## 2. Cloudflare configuration
24+
Now you can install the Sentry Cloudflare SDK. First, install the SDK with your package manager:
2525

26-
To use the SDK, you'll need to set either the `nodejs_als` or `nodejs_compat` compatibility flags in your `wrangler.jsonc`/`wrangler.toml` config. This is because the SDK
27-
needs access to the `AsyncLocalStorage` API to work correctly.
26+
<PlatformContent includePath="getting-started-install" />
2827

29-
```jsonc {tabTitle:JSON} {filename:wrangler.jsonc}
30-
{
31-
"compatibility_flags": [
32-
"nodejs_als",
33-
// "nodejs_compat"
34-
],
35-
}
36-
```
37-
38-
```toml {tabTitle:Toml} {filename:wrangler.toml}
39-
compatibility_flags = ["nodejs_als"]
40-
# compatibility_flags = ["nodejs_compat"]
41-
```
28+
## Setup
4229

43-
## 3. Update Your Server Hooks File
30+
<PlatformContent includePath="getting-started-config" />
4431

45-
To use this SDK, 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`.
32+
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`.
4633

4734
```typescript diff {filename:hooks.server.(ts|js)}
4835
-import { handleErrorWithSentry, sentryHandle } from "@sentry/sveltekit";

docs/platforms/javascript/guides/cloudflare/index.mdx

Lines changed: 44 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -9,110 +9,29 @@ categories:
99
- serverless
1010
---
1111

12-
## Install
13-
14-
<OnboardingOptionButtons
15-
options={["error-monitoring", "performance", "profiling"]}
16-
/>
17-
18-
In addition to capturing errors, you can monitor interactions between multiple services or applications by [enabling tracing](/concepts/key-terms/tracing/).
19-
20-
Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.
2112

22-
Sentry captures data by using an SDK within your application’s runtime.
23-
24-
```bash {tabTitle:npm}
25-
npm install @sentry/cloudflare --save
26-
```
27-
28-
```bash {tabTitle:yarn}
29-
yarn add @sentry/cloudflare
30-
```
31-
32-
```bash {tabTitle:pnpm}
33-
pnpm add @sentry/cloudflare
34-
```
35-
36-
## Configure
37-
38-
Configuration should happen as early as possible in your application's lifecycle.
39-
40-
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
41-
needs access to the `AsyncLocalStorage` API to work correctly.
42-
43-
```jsonc {tabTitle:JSON} {filename:wrangler.jsonc}
44-
{
45-
"compatibility_flags": [
46-
"nodejs_als",
47-
// "nodejs_compat"
48-
],
49-
}
50-
```
13+
You can use the Sentry Cloudflare SDK with popular frameworks running on Cloudflare:
5114

52-
```toml {tabTitle:Toml} {filename:wrangler.toml}
53-
compatibility_flags = ["nodejs_als"]
54-
# compatibility_flags = ["nodejs_compat"]
55-
```
15+
- **[Astro](framesworks/astro/)**
16+
- **[Hono](frameworks/hono/)**
17+
- **[Remix](framesworks/remix/)**
18+
- **[SvelteKit](framesworks/sveltekit/)**
5619

57-
Then you can install the SDK and add it to your project:
20+
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/).
5821

59-
You can either setup up the SDK for [Cloudflare Pages](#setup-cloudflare-pages) or [Cloudflare Workers](#setup-cloudflare-workers).
22+
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.
6023

61-
### Setup (Cloudflare Pages)
24+
## Install
6225

63-
To use this SDK, add the `sentryPagesPlugin` as [middleware to your Cloudflare Pages application](https://developers.cloudflare.com/pages/functions/middleware/).
26+
<PlatformContent includePath="getting-started-install" />
6427

65-
We recommend adding a `functions/_middleware.js` for the middleware setup so that Sentry is initialized for your entire
66-
app.
28+
## Setup
6729

68-
```javascript {filename:functions/_middleware.js}
69-
import * as Sentry from "@sentry/cloudflare";
70-
71-
export const onRequest = [
72-
// Make sure Sentry is the first middleware
73-
Sentry.sentryPagesPlugin((context) => ({
74-
dsn: "___PUBLIC_DSN___",
75-
76-
// Adds request headers and IP for users, for more info visit:
77-
// https://docs.sentry.io/platforms/javascript/guides/cloudflare/configuration/options/#sendDefaultPii
78-
sendDefaultPii: true,
79-
80-
// ___PRODUCT_OPTION_START___ performance
81-
// Set tracesSampleRate to 1.0 to capture 100% of spans for tracing.
82-
// Learn more at
83-
// https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
84-
tracesSampleRate: 1.0,
85-
// ___PRODUCT_OPTION_END___ performance
86-
})),
87-
// Add more middlewares here
88-
];
89-
```
30+
<PlatformContent includePath="getting-started-config" />
9031

9132
### Setup (Cloudflare Workers)
9233

93-
To use this SDK, wrap your handler with the `withSentry` function. This will initialize the SDK and hook into the
94-
environment. Note that you can turn off almost all side effects using the respective options.
95-
96-
```typescript {filename:index.ts}
97-
import * as Sentry from "@sentry/cloudflare";
98-
99-
export default Sentry.withSentry(
100-
(env) => ({
101-
dsn: "___PUBLIC_DSN___",
102-
// ___PRODUCT_OPTION_START___ performance
103-
// Set tracesSampleRate to 1.0 to capture 100% of spans for tracing.
104-
// Learn more at
105-
// https://docs.sentry.io/platforms/javascript/guides/cloudflare/configuration/options/#tracesSampleRate
106-
tracesSampleRate: 1.0,
107-
// ___PRODUCT_OPTION_END___ performance
108-
}),
109-
{
110-
async fetch(request, env, ctx) {
111-
return new Response("Hello World!");
112-
},
113-
} satisfies ExportedHandler<Env>
114-
);
115-
```
34+
<PlatformContent includePath="getting-started-config" platform="javascript.cloudflare.workers" />
11635

11736
If you do not have access to the `onRequest` middleware API, you can use the `wrapRequestHandler` API instead. For example:
11837

@@ -133,13 +52,41 @@ export const handle = ({ event, resolve }) => {
13352
};
13453
```
13554

136-
### Frameworks
55+
### Setup (Cloudflare Pages)
13756

138-
You can use the Sentry Cloudflare SDK with popular frameworks running on Cloudflare:
57+
To use this SDK, add the `sentryPagesPlugin` as [middleware to your Cloudflare Pages application](https://developers.cloudflare.com/pages/functions/middleware/).
13958

140-
- **[Hono](frameworks/hono/)** - A lightweight web framework for Cloudflare Workers
59+
We recommend adding a `functions/_middleware.js` for the middleware setup so that Sentry is initialized for your entire
60+
app.
14161

142-
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/).
62+
```javascript {filename:functions/_middleware.js}
63+
import * as Sentry from "@sentry/cloudflare";
64+
65+
export const onRequest = [
66+
// Make sure Sentry is the first middleware
67+
Sentry.sentryPagesPlugin((context) => {
68+
const { id: versionId } = env.CF_VERSION_METADATA;
69+
70+
return {
71+
dsn: "___PUBLIC_DSN___",
72+
73+
release: versionId,
74+
75+
// Adds request headers and IP for users, for more info visit:
76+
// https://docs.sentry.io/platforms/javascript/guides/cloudflare/configuration/options/#sendDefaultPii
77+
sendDefaultPii: true,
78+
79+
// ___PRODUCT_OPTION_START___ performance
80+
// Set tracesSampleRate to 1.0 to capture 100% of spans for tracing.
81+
// Learn more at
82+
// https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
83+
tracesSampleRate: 1.0,
84+
// ___PRODUCT_OPTION_END___ performance
85+
}
86+
}),
87+
// Add more middlewares here
88+
];
89+
```
14390

14491
### Cloudflare Durable Objects
14592

0 commit comments

Comments
 (0)