honojs-middleware/packages/sentry
Jonathan Haines 5ea7fb5d09
chore: Migrate workspaces that use `jest` to `vitest` (#998)
* docs(contributing): add section on testing

Fixes #994

* test(clerk-auth): replace jest with vitest

* test(graphql-server): replace jest with vitest

* test(medley-router): replace jest with vitest

* test(oauth-providers): replace jest with vitest

* test(oidc-auth): replace jest with vitest

* test(sentry): replace jest with vitest

* test(trpc-server): replace jest with vitest

* test(typebox-validator): replace jest with vitest

* test(typia-validator): replace jest with vitest

* test(valibot-validator): replace jest with vitest

* chore: cleanup remaining references to jest

* chore: fix lint errors

* test(typia-validator): fix exclude directory

* test(oauth-providers): use vitest environment miniflare

* chore: update `yarn.lock`

* chore(zod-openapi): pin zod-validator to 0.4.2

* test(graphql-server): remove console filtering

---------

Co-authored-by: Yusuke Wada <yusuke@kamawada.com>
2025-03-04 22:00:28 +09:00
..
src chore: Migrate workspaces that use `jest` to `vitest` (#998) 2025-03-04 22:00:28 +09:00
CHANGELOG.md Version Packages (#621) 2024-07-07 08:08:38 +09:00
README.md feat(sentry): bump up `toucan-js` to v3 (#137) 2023-08-24 11:21:16 +09:00
package.json chore: Migrate workspaces that use `jest` to `vitest` (#998) 2025-03-04 22:00:28 +09:00
tsconfig.json chore: Migrate workspaces that use `jest` to `vitest` (#998) 2025-03-04 22:00:28 +09:00
vitest.config.ts chore: Migrate workspaces that use `jest` to `vitest` (#998) 2025-03-04 22:00:28 +09:00

README.md

Sentry Middleware for Hono

This middleware integrates Hono with Sentry. It captures exceptions and sends them to the specified Sentry data source name (DSN) using toucan-js.

Installation

npm i hono @hono/sentry

Configuration

If you're running your application on Cloudflare Workers, set a binding value named SENTRY_DSN, which will be used as the DSN. For instance, during development, you can specify this in .dev.vars:

SENTRY_DSN=<Your DSN>

On other platforms, you can directly provide the DSN by passing it as an option:

sentry({
  dsn: `<Your DSN>`,
})

How to Use

import { Hono } from 'hono'
import { sentry } from '@hono/sentry'

const app = new Hono()

app.use('*', sentry())
app.get('/', (c) => c.text('foo'))

export default app

Options:

import type { Options as ToucanOptions } from 'toucan-js'
type Options = Omit<ToucanOptions, 'request' | 'context'>

For Deno Users

import { serve } from 'https://deno.land/std/http/server.ts'
import { sentry } from 'npm:@hono/sentry'
import { Hono } from 'https://deno.land/x/hono/mod.ts'

const app = new Hono()

app.use('*', sentry({ dsn: 'https://xxxxxx@xxx.ingest.sentry.io/xxxxxx' }))
app.get('/', (c) => c.text('foo'))

serve(app.fetch)

Accessing an instance of Sentry

You can retrieve an instance of Sentry using c.get('sentry').

app.onError((e, c) => {
  c.get('sentry').setContext('character', {
    name: 'Mighty Fighter',
    age: 19,
    attack_type: 'melee',
  })
  c.get('sentry').captureException(e)
  return c.text('Internal Server Error', 500)
})

Authors

License

MIT