SDKs
Cloudflare Workers
Bugzor works with the open-source @sentry/cloudflare SDK. Tested with version 11.12 and Wrangler 4 (our demo Worker).
Install#
npm install @sentry/cloudflareTurn on Node.js compatibility#
The SDK needs AsyncLocalStorage, so enable the nodejs_compat flag with a recent compatibility date:
{
"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#
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:
npx wrangler secret put SENTRY_DSN
# paste: https://<public-key>@www.bugzor.com/<project-id>For local development, put it in .dev.vars:
SENTRY_DSN=https://<public-key>@www.bugzor.com/<project-id>Capture errors and messages#
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#
npx wrangler dev
curl http://localhost:8787/boomThe error appears under Issues within a few seconds.
Something unclear or out of date? Tell us.