-
-
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
Open
s1gr1d
wants to merge
2
commits into
master
Choose a base branch
from
sig/cloudflare-honoIntegration
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+53
−42
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
docs/platforms/javascript/guides/cloudflare/configuration/integrations/hono.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}), | ||
] | ||
``` |
23 changes: 12 additions & 11 deletions
23
platform-includes/configuration/integrations/javascript.cloudflare.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ✓ | ✓ | | | | |
33 changes: 2 additions & 31 deletions
33
platform-includes/getting-started-capture-errors/javascript.hono.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/). |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l: maybe it is worth to mention that this is only true, unless it gets overwritten by
shouldHandleError
. Or the other way around to write insideshouldHandleError
that this will overwrite the auto reports from SentryThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'll just add a "By default, " at the beginning of the sentence, since I am referring to customizing the behavior below.