Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 19 additions & 25 deletions docs/platforms/javascript/guides/cloudflare/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -61,31 +61,25 @@ import * as Sentry from "@sentry/cloudflare";

export const onRequest = [
// Make sure Sentry is the first middleware
Sentry.sentryPagesPlugin((context) => {
const { id: versionId } = env.CF_VERSION_METADATA;

return {
dsn: "___PUBLIC_DSN___",

release: versionId,

// 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.
// Learn more at
// https://docs.sentry.io/platforms/javascript/guides/cloudflare/configuration/options/#tracesSampleRate
tracesSampleRate: 1.0,
// ___PRODUCT_OPTION_END___ performance
};
}),
Sentry.sentryPagesPlugin((context) => ({
dsn: "___PUBLIC_DSN___",

// 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.
// Learn more at
// https://docs.sentry.io/platforms/javascript/guides/cloudflare/configuration/options/#tracesSampleRate
tracesSampleRate: 1.0,
// ___PRODUCT_OPTION_END___ performance
})),
// Add more middlewares here
];
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,25 @@ const app = new Hono();
// app.get('/your-route', (c) => c.text('Hello!'));

export default Sentry.withSentry(
(env: Env) => {
const { id: versionId } = env.CF_VERSION_METADATA;

return {
dsn: "___PUBLIC_DSN___",

release: versionId,

// 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.
// Learn more at
// https://docs.sentry.io/platforms/javascript/guides/cloudflare/configuration/options/#tracesSampleRate
tracesSampleRate: 1.0,
// ___PRODUCT_OPTION_END___ performance
};
},
(env: Env) => ({
dsn: "___PUBLIC_DSN___",

// 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.
// Learn more at
// https://docs.sentry.io/platforms/javascript/guides/cloudflare/configuration/options/#tracesSampleRate
tracesSampleRate: 1.0,
// ___PRODUCT_OPTION_END___ performance
}),
app
);
```
Expand Down
32 changes: 28 additions & 4 deletions platform-includes/getting-started-config/javascript.cloudflare.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,41 @@ compatibility_flags = ["nodejs_als"]
# compatibility_flags = ["nodejs_compat"]
```

Additionally, add the `CF_VERSION_METADATA` binding in the same file:
### Release Configuration (Optional)

If you don't set the `release` option manually, the SDK automatically detects it from these sources (in order of priority):

1. The `SENTRY_RELEASE` environment variable
2. The `CF_VERSION_METADATA.id` binding (if configured)

To enable automatic release detection via Cloudflare's version metadata, add the `CF_VERSION_METADATA` binding in your wrangler configuration. This provides access to the [Cloudflare version metadata](https://developers.cloudflare.com/workers/runtime-apis/bindings/version-metadata/):

<Expandable title="Using an SDK version before 10.35.0?">

In earlier versions, you need to manually extract `CF_VERSION_METADATA.id` and pass it as the `release` option:

```javascript
Sentry.withSentry(
(env) => ({
dsn: "___PUBLIC_DSN___",
release: env.CF_VERSION_METADATA?.id,
}),
// ...
);
```

</Expandable>

```jsonc {tabTitle:JSON} {filename:wrangler.jsonc}
{
// ...
"version_metadata": {
"binding": "CF_VERSION_METADATA",
},
"binding": "CF_VERSION_METADATA"
}
}
```

```toml {tabTitle:Toml} {filename:wrangler.toml}
version_metadata = { binding = "CF_VERSION_METADATA" }
[version_metadata]
binding = "CF_VERSION_METADATA"
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,25 @@ Wrap your worker handler with the `withSentry` function, for example, in your `i
import * as Sentry from "@sentry/cloudflare";

export default Sentry.withSentry(
(env: Env) => {
const { id: versionId } = env.CF_VERSION_METADATA;
(env: Env) => ({
dsn: "___PUBLIC_DSN___",

return {
dsn: "___PUBLIC_DSN___",
// 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

release: versionId,
// Enable logs to be sent to Sentry
enableLogs: true,
// ___PRODUCT_OPTION_END___ logs
// ___PRODUCT_OPTION_START___ performance

// 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.
// Learn more at
// https://docs.sentry.io/platforms/javascript/guides/cloudflare/configuration/options/#tracesSampleRate
tracesSampleRate: 1.0,
// ___PRODUCT_OPTION_END___ performance
};
},
// Set tracesSampleRate to 1.0 to capture 100% of spans for tracing.
// Learn more at
// https://docs.sentry.io/platforms/javascript/guides/cloudflare/configuration/options/#tracesSampleRate
tracesSampleRate: 1.0,
// ___PRODUCT_OPTION_END___ performance
}),
{
async fetch(request, env, ctx) {
// Your worker logic here
Expand Down