Docs · Cloudflare Workers

SDKs

Cloudflare Workers

Bugzor works with the open-source @sentry/cloudflare SDK. Tested with version 11.12 and Wrangler 4 (our demo Worker).

Install#

Terminal
npm install @sentry/cloudflare

Turn on Node.js compatibility#

The SDK needs AsyncLocalStorage, so enable the nodejs_compat flag with a recent compatibility date:

wrangler.jsonc
{
  "name": "my-worker",
  "main": "src/index.ts",
  "compatibility_date": "2026-11-01",
  "compatibility_flags": ["nodejs_compat"],
  // Lets the SDK pick up the deployed version as the release.
  "version_metadata": { "binding": "CF_VERSION_METADATA" }
}

Wrap your handler#

src/index.ts
import * as Sentry from "@sentry/cloudflare";

interface Env {
  SENTRY_DSN: string;
}

export default Sentry.withSentry(
  (env: Env) => ({
    dsn: env.SENTRY_DSN,
    environment: "production",
    // Traces land in Rich Trace Logs; sample to stay within your plan's storage.
    tracesSampleRate: 0.1,
  }),
  {
    async fetch(request, env, ctx) {
      const url = new URL(request.url);
      if (url.pathname === "/boom") throw new Error("Something broke");
      return new Response("ok");
    },
  } satisfies ExportedHandler<Env>,
);

withSentry reports uncaught errors from fetch, scheduled, queue and email handlers, with the request as context. It sends with ctx.waitUntil, so responses aren’t delayed.

Set the DSN#

Store the DSN as a secret:

Terminal
npx wrangler secret put SENTRY_DSN
# paste: https://<public-key>@www.bugzor.com/<project-id>

For local development, put it in .dev.vars:

.dev.vars
SENTRY_DSN=https://<public-key>@www.bugzor.com/<project-id>

Capture errors and messages#

TypeScript
Sentry.captureException(new Error("upstream returned 502"));
Sentry.captureMessage("Cache miss storm", "warning");

Sentry.setUser({ id: "42" });
Sentry.setTag("colo", request.cf?.colo as string);

Test it#

Terminal
npx wrangler dev
curl http://localhost:8787/boom

The error appears under Issues within a few seconds.

Something unclear or out of date? Tell us.