feat(sentry): support latest Hono version (#57)

* feat(sentry): support latest Hono version

* changset
pull/58/head
Yusuke Wada 2023-03-02 15:14:11 +09:00 committed by GitHub
parent 7084477c2f
commit 8d57df889d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 17 additions and 30 deletions

View File

@ -0,0 +1,5 @@
---
'@hono/sentry': minor
---
feat: support latest Hono version

View File

@ -1,21 +1,13 @@
# Sentry middleware for Hono
## Information
Sentry Middleware `@honojs/sentry` is renamed to `@hono/sentry`.
`@honojs/sentry` is not maintained, please use `@hono/sentry`.
Also, for Deno, you can use import with `npm:` prefix like `npm:@hono/sentry`.
---
Sentry middleware for [Hono](https://github.com/honojs/hono).
This middleware sends captured exceptions to the specified Sentry data source name via [toucan-js](https://github.com/robertcepa/toucan-js).
## Usage
```ts
import { sentry } from '@hono/sentry'
import { Hono } from 'hono'
import { sentry } from '@hono/sentry'
const app = new Hono()

View File

@ -7,11 +7,6 @@ declare module 'https://deno.land/x/hono/mod.ts' {
}
}
interface Bindings {
SENTRY_DSN?: string
NEXT_PUBLIC_SENTRY_DSN?: string
}
class MockContext implements ExecutionContext {
passThroughOnException(): void {
throw new Error('Method not implemented.')
@ -37,7 +32,7 @@ export type Options = {
export const sentry = (
options?: Options,
callback?: (sentry: Toucan) => void
): MiddlewareHandler<string, { Bindings: Bindings }> => {
): MiddlewareHandler => {
return async (c, next) => {
let hasExecutionContext = true
try {
@ -49,7 +44,7 @@ export const sentry = (
dsn: c.env.SENTRY_DSN ?? c.env.NEXT_PUBLIC_SENTRY_DSN,
allowedHeaders: ['user-agent'],
allowedSearchParams: /(.*)/,
request: c.req,
request: c.req.raw,
context: hasExecutionContext ? c.executionCtx : new MockContext(),
...options,
})

View File

@ -33,7 +33,7 @@
"access": "public"
},
"peerDependencies": {
"hono": "^2.6.1"
"hono": "^3.0.2"
},
"dependencies": {
"toucan-js": "^2.6.1"
@ -52,7 +52,7 @@
"eslint-plugin-flowtype": "^8.0.3",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-node": "^11.1.0",
"hono": "^2.6.1",
"hono": "^3.0.2",
"jest": "^28.1.2",
"jest-environment-miniflare": "^2.6.0",
"np": "^7.6.2",

View File

@ -7,11 +7,6 @@ declare module 'hono' {
}
}
interface Bindings {
SENTRY_DSN?: string
NEXT_PUBLIC_SENTRY_DSN?: string
}
class MockContext implements ExecutionContext {
passThroughOnException(): void {
throw new Error('Method not implemented.')
@ -37,7 +32,7 @@ export type Options = {
export const sentry = (
options?: Options,
callback?: (sentry: Toucan) => void
): MiddlewareHandler<string, { Bindings: Bindings }> => {
): MiddlewareHandler => {
return async (c, next) => {
let hasExecutionContext = true
try {
@ -49,7 +44,7 @@ export const sentry = (
dsn: c.env.SENTRY_DSN ?? c.env.NEXT_PUBLIC_SENTRY_DSN,
allowedHeaders: ['user-agent'],
allowedSearchParams: /(.*)/,
request: c.req,
request: c.req.raw,
context: hasExecutionContext ? c.executionCtx : new MockContext(),
...options,
})

View File

@ -5217,11 +5217,6 @@ hono@3.0.0-rc.4:
resolved "https://registry.yarnpkg.com/hono/-/hono-3.0.0-rc.4.tgz#7bfe8c89d4b004ff90d587c8ba45279a175fbce7"
integrity sha512-76R3mb8kPeuD9TOmQ1WZi59w4QbpaUOlyX3wC7zQpt7IM7iFVBTxj2fpv++6ROPtd5iUBMCrmH/65ZrNXYYgmg==
hono@^2.6.1:
version "2.7.5"
resolved "https://registry.yarnpkg.com/hono/-/hono-2.7.5.tgz#2b0c39d39a057575962a7025373be4304dedca9c"
integrity sha512-UYrhUT1Xtalh7Xw/YGXee25wlWMiVIRfr0FbAJMEMyRpX9TFZ/6JKmVdCK7ioRnhAw7PfWBasjSBhdNXQ8/okQ==
hono@^2.7.2:
version "2.7.2"
resolved "https://registry.yarnpkg.com/hono/-/hono-2.7.2.tgz#09796d79a2f220c353efaf4aeb82434062ceb911"
@ -5232,6 +5227,11 @@ hono@^3.0.0:
resolved "https://registry.yarnpkg.com/hono/-/hono-3.0.0.tgz#f81e49e7540603203b9b576c81b289fa7daf0446"
integrity sha512-OBWEvcRydCOLdOiazqOmKy8PXciR8uIyUM9HpmXot7UmwNBGOdEJvTrVRIgjV603w+go6cTXBOvFiQClSABT6Q==
hono@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/hono/-/hono-3.0.2.tgz#807a1b0514c6563917d8c278e6da7101bdac1d19"
integrity sha512-jhb0eCiUTOzbOXZyXQCOk1gf3MKjV4ZXY3PRT6lzma0XPsnnHuDOHYF7RCMHYe7jhl4Y0IAzrmWXneXhOMHypA==
hosted-git-info@^2.1.4:
version "2.8.9"
resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.8.9.tgz#dffc0bf9a21c02209090f2aa69429e1414daf3f9"