Hono
Learn how to set up Hono with Sentry.
This guide explains how to set up Sentry in your Hono application.
If you don't already have an account and a Sentry project established, sign up for Sentry for free, then return to this page.
In addition to capturing errors, you can monitor interactions between multiple services or applications by enabling tracing. You can also collect and analyze performance profiles from real users with profiling. Note that profiling currently only works in the Node.js runtime.
Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.
Since Hono is a framework designed to run in all kinds of JavaScript runtimes, different setups for different platforms are outlined below.
npm install @sentry/cloudflare --save
To use the SDK, you'll need to set either the nodejs_compat
or nodejs_als
compatibility flags in your wrangler.toml
/wrangler.json
. This is because the SDK needs access to the AsyncLocalStorage
API to work correctly.
wrangler.toml
compatibility_flags = ["nodejs_compat"]
# compatibility_flags = ["nodejs_als"]
Next, wrap your handler with the withSentry
function. This will initialize the SDK and hook into the environment. Note that you can turn off almost all side effects using the respective options.
index.ts
import { Hono } from "hono";
import * as Sentry from "@sentry/cloudflare";
const app = new Hono();
// Your routes...
app.get("/", () => {
// ...
});
export default Sentry.withSentry(
(env) => ({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
// Set tracesSampleRate to 1.0 to capture 100% of spans for tracing.
// Learn more at
// https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
tracesSampleRate: 1.0,
}),
app
);
npm install @sentry/cloudflare --save
To use the SDK, you'll need to set either the nodejs_compat
or nodejs_als
compatibility flags in your wrangler.toml
/wrangler.json
. This is because the SDK needs access to the AsyncLocalStorage
API to work correctly.
wrangler.toml
compatibility_flags = ["nodejs_compat"]
# compatibility_flags = ["nodejs_als"]
Next, add the sentryPagesPlugin
as middleware to your Cloudflare Pages application.
We recommend adding a functions/_middleware.js
for the middleware setup so that Sentry is initialized for your entire app.
functions/_middleware.js
import * as Sentry from "@sentry/cloudflare";
export const onRequest = [
// Make sure Sentry is the first middleware
Sentry.sentryPagesPlugin((context) => ({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
// Set tracesSampleRate to 1.0 to capture 100% of spans for tracing.
// Learn more at
// https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
tracesSampleRate: 1.0,
})),
// Add more middlewares here
];
We currently limit support for Hono to Cloudflare. If you need support for other runtimes reach out on GitHub with a feature request.
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").