Hono on Cloudflare
Learn how to instrument your Hono app on Cloudflare Workers with Sentry.
Hono has its own dedicated SDK (@sentry/hono) with first-class support for Cloudflare Workers, Node.js, Bun, and Deno. It works as Hono middleware, so you can drop it into an existing app.
Install @sentry/hono together with @sentry/cloudflare. The runtime package is a peer dependency that you never import directly, but it must be present and its version must match @sentry/hono.
npm install @sentry/hono @sentry/cloudflare
npm install @sentry/hono @sentry/cloudflare
yarn add @sentry/hono @sentry/cloudflare
pnpm add @sentry/hono @sentry/cloudflare
The SDK needs AsyncLocalStorage, so set the nodejs_compat compatibility flag and a compatibility_date of 2024-09-23 or later in your Wrangler configuration:
wrangler.jsonc{
// Set this to today's date
"compatibility_date": "2026-10-10",
"compatibility_flags": ["nodejs_compat"],
}
{
// Set this to today's date
"compatibility_date": "2026-10-10",
"compatibility_flags": ["nodejs_compat"],
}
# Set this to today's date
compatibility_date = "2026-10-10"
compatibility_flags = ["nodejs_compat"]
Add the sentry() middleware as early as possible in your Hono app, before any route that you want covered:
index.tsimport { Hono } from "hono";
import { sentry } from "@sentry/hono/cloudflare";
const app = new Hono();
app.use(
sentry(app, {
dsn: "___PUBLIC_DSN___",
// Set tracesSampleRate to 1.0 to capture 100% of spans for tracing.
tracesSampleRate: 1.0,
}),
);
// Your routes here
export default app;
import { Hono } from "hono";
import { sentry } from "@sentry/hono/cloudflare";
const app = new Hono();
app.use(
sentry(app, {
dsn: "___PUBLIC_DSN___",
// Set tracesSampleRate to 1.0 to capture 100% of spans for tracing.
tracesSampleRate: 1.0,
}),
);
// Your routes here
export default app;
To read the DSN from a Worker binding, pass a callback instead of a plain options object. The callback receives the Worker env:
index.tsapp.use(sentry(app, (env) => ({ dsn: env.SENTRY_DSN })));
app.use(sentry(app, (env) => ({ dsn: env.SENTRY_DSN })));
For the full setup, including verification and the other runtimes, see the Hono Quick Start Guide.
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").