diff --git a/docs/platforms/javascript/guides/cloudflare/index.mdx b/docs/platforms/javascript/guides/cloudflare/index.mdx index 46d8ff82bcf8b..c10be92bbc02d 100644 --- a/docs/platforms/javascript/guides/cloudflare/index.mdx +++ b/docs/platforms/javascript/guides/cloudflare/index.mdx @@ -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 ]; ``` diff --git a/platform-includes/getting-started-config/javascript.cloudflare.hono.mdx b/platform-includes/getting-started-config/javascript.cloudflare.hono.mdx index c027e06802e60..f3edfd7b3d4f3 100644 --- a/platform-includes/getting-started-config/javascript.cloudflare.hono.mdx +++ b/platform-includes/getting-started-config/javascript.cloudflare.hono.mdx @@ -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 ); ``` diff --git a/platform-includes/getting-started-config/javascript.cloudflare.mdx b/platform-includes/getting-started-config/javascript.cloudflare.mdx index 4face285b2492..d6a543aa9c4ed 100644 --- a/platform-includes/getting-started-config/javascript.cloudflare.mdx +++ b/platform-includes/getting-started-config/javascript.cloudflare.mdx @@ -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/): + + + +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, + }), + // ... +); +``` + + ```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" ``` diff --git a/platform-includes/getting-started-config/javascript.cloudflare.workers.mdx b/platform-includes/getting-started-config/javascript.cloudflare.workers.mdx index 8f5d20a26f5af..9c794743eda9d 100644 --- a/platform-includes/getting-started-config/javascript.cloudflare.workers.mdx +++ b/platform-includes/getting-started-config/javascript.cloudflare.workers.mdx @@ -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