-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
docs(cloudflare): Add docs for honoIntegration
#15251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| --- | ||
| title: Hono | ||
| description: "Reports Hono errors to Sentry. (default)" | ||
| --- | ||
|
|
||
| _Import name: `Sentry.honoIntegration`_ | ||
|
|
||
| This integration is enabled by default. If you'd like to modify your default integrations, read [this](./../#modifying-default-integrations). | ||
|
|
||
| The `honoIntegration` automatically captures errors from Hono's `onError` function and sends them to Sentry. By default, the integration won't capture errors that have a 3xx or 4xx HTTP status code. | ||
|
|
||
| ## Options | ||
|
|
||
| You can configure the `honoIntegration` by passing an options object to the function. | ||
|
|
||
| ### `shouldHandleError` | ||
|
|
||
| This option allows you to provide a function that determines whether an error should be captured, giving you full control over which errors are sent to Sentry. | ||
|
|
||
| The function receives the error as an argument and should return `true` if the error should be reported, and `false` otherwise. | ||
|
|
||
| For example, to report all errors except for 404s, add this to the integrations array when initializing Sentry: | ||
|
|
||
| ```javascript | ||
| integrations: [ | ||
| honoIntegration({ | ||
| shouldHandleError(error) { | ||
| // return true // Would report all errors | ||
|
|
||
| if (error instanceof HTTPException && error.status === 404) { | ||
| // Don't report 404s | ||
| return false; | ||
| } | ||
| // Report all other errors | ||
| return true; | ||
| }, | ||
| }), | ||
| ] | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,14 @@ | ||
| ### Integrations | ||
|
|
||
| | | **Auto Enabled** | **Errors** | **Tracing** | **Cron** | **Additional Context** | | ||
| | ---------------------------------------------------- | :--------------: | :--------: | :---------: | :------: | :--------------------: | | ||
| | [`dedupeIntegration`](./dedupe) | ✓ | ✓ | | | | | ||
| | [`fetchIntegration`](./fetchIntegration) | ✓ | ✓ | ✓ | | | | ||
| | [`functionToStringIntegration`](./functiontostring) | ✓ | | | | | | ||
| | [`inboundFiltersIntegration`](./inboundfilters) | ✓ | ✓ | | | | | ||
| | [`linkedErrorsIntegration`](./linkederrors) | ✓ | ✓ | | | | | ||
| | [`requestDataIntegration`](./requestdata) | ✓ | | | | ✓ | | ||
| | [`captureConsoleIntegration`](./captureconsole) | | | | | ✓ | | ||
| | [`extraErrorDataIntegration`](./extraerrordata) | | | | | ✓ | | ||
| | [`rewriteFramesIntegration`](./rewriteframes) | | ✓ | | | | | ||
| | | **Auto Enabled** | **Errors** | **Tracing** | **Cron** | **Additional Context** | | ||
| |-----------------------------------------------------|:----------------:|:----------:|:-----------:|:--------:|:----------------------:| | ||
| | [`dedupeIntegration`](./dedupe) | ✓ | ✓ | | | | | ||
| | [`fetchIntegration`](./fetchIntegration) | ✓ | ✓ | ✓ | | | | ||
| | [`functionToStringIntegration`](./functiontostring) | ✓ | | | | | | ||
| | [`inboundFiltersIntegration`](./inboundfilters) | ✓ | ✓ | | | | | ||
| | [`linkedErrorsIntegration`](./linkederrors) | ✓ | ✓ | | | | | ||
| | [`requestDataIntegration`](./requestdata) | ✓ | | | | ✓ | | ||
| | [`captureConsoleIntegration`](./captureconsole) | | | | | ✓ | | ||
| | [`extraErrorDataIntegration`](./extraerrordata) | | | | | ✓ | | ||
| | [`rewriteFramesIntegration`](./rewriteframes) | | ✓ | | | | | ||
| | [`honoIntegration`](./hono) | ✓ | ✓ | | | | |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,34 +1,5 @@ | ||
| ### Report Unhandled Exceptions | ||
|
|
||
| Next, bind an `onError` hook to report unhandled exceptions to Sentry: | ||
| Sentry automatically reports exceptions reported by the `onError` function from Hono. In case the error comes with a status code, it captures all errors except for the ones with a 3xx or 4xx status code. | ||
|
||
|
|
||
| ```javascript | ||
| const app = new Hono() | ||
| // Add an onError hook to report unhandled exceptions to Sentry. | ||
| .onError((err, c) => { | ||
| // Report _all_ unhandled errors. | ||
| Sentry.captureException(err); | ||
| if (err instanceof HTTPException) { | ||
| return err.getResponse(); | ||
| } | ||
| // Or just report errors which are not instances of HTTPException | ||
| // Sentry.captureException(err); | ||
| return c.json({ error: "Internal server error" }, 500); | ||
| }) | ||
|
|
||
| // Bind global context via Hono middleware | ||
| .use((c, next) => { | ||
| Sentry.setUser({ | ||
| email: c.session.user.email, | ||
| }); | ||
|
|
||
| Sentry.setTag("project_id", c.session.projectId); | ||
|
|
||
| return next(); | ||
| }) | ||
|
|
||
| // Your routes... | ||
| .get("/", () => { | ||
| // ... | ||
| }); | ||
| ``` | ||
| To learn how to customize this behavior, see the [`honoIntegration` documentation](/platforms/javascript/guides/cloudflare/configuration/integrations/hono/). | ||
Uh oh!
There was an error while loading. Please reload this page.