Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(hono): Add support for the Deno runtime#21450
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
c9b5c1d924791be2d2621880d457f77a1f9c2039c743e6b9dFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "imports": { | ||
| "@sentry/hono": "npm:@sentry/hono", | ||
| "@sentry/hono/deno": "npm:@sentry/hono/deno", | ||
| "@sentry/deno": "npm:@sentry/deno", | ||
| "@sentry/core": "npm:@sentry/core", | ||
| "@opentelemetry/api": "npm:@opentelemetry/api@^1.9.0", | ||
| "hono": "npm:hono@^4.12.14" | ||
| }, | ||
| "nodeModulesDir": "manual" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { Hono } from 'hono'; | ||
| import { sentry } from '@sentry/hono/deno'; | ||
| import { addRoutes } from './routes'; | ||
| const app = new Hono(); | ||
| app.use( | ||
| sentry(app, { | ||
| dsn: Deno.env.get('E2E_TEST_DSN'), | ||
| environment: 'qa', | ||
| dataCollection: {}, | ||
| tracesSampleRate: 1.0, | ||
| tunnel: 'http://localhost:3031/', | ||
| }), | ||
| ); | ||
| addRoutes(app); | ||
| const port = Number(Deno.env.get('PORT') || 38787); | ||
| Deno.serve({ port }, app.fetch); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| export type Runtime = 'cloudflare' | 'node' | 'bun'; | ||
| export type Runtime = 'cloudflare' | 'node' | 'bun' | 'deno'; | ||
| export const RUNTIME = (process.env.RUNTIME || 'cloudflare') as Runtime; | ||
| export const RUNTIME = (process.env.RUNTIME || 'deno') as Runtime; | ||
| export const APP_NAME = 'hono-4'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { type BaseTransportOptions, debug, type Options } from '@sentry/core'; | ||
| import { init } from './sdk'; | ||
| import type { Env, Hono, MiddlewareHandler } from 'hono'; | ||
| import { getConnInfo } from 'hono/deno'; | ||
| import { requestHandler, responseHandler } from '../shared/middlewareHandlers'; | ||
| import { applyPatches } from '../shared/applyPatches'; | ||
| import type { SentryHonoMiddlewareOptions } from '../shared/types'; | ||
| export interface HonoDenoOptions extends Options<BaseTransportOptions>, SentryHonoMiddlewareOptions {} | ||
| /** | ||
| * Sentry middleware for Hono running in a Deno runtime environment. | ||
| */ | ||
| export const sentry = <E extends Env>(app: Hono<E>, options: HonoDenoOptions): MiddlewareHandler => { | ||
| options.debug && debug.log('Initialized Sentry Hono middleware (Deno)'); | ||
| init(options); | ||
| applyPatches(app); | ||
| return async (context, next) => { | ||
| requestHandler(context, getConnInfo); | ||
| await next(); // Handler runs in between Request above ⤴ and Response below ⤵ | ||
| responseHandler(context, options.shouldHandleError); | ||
| }; | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import type { Client } from '@sentry/core'; | ||
| import { applySdkMetadata, consoleSandbox, getClient } from '@sentry/core'; | ||
| import { init as initDeno } from '@sentry/deno'; | ||
| import type { HonoDenoOptions } from './middleware'; | ||
| import { buildFilteredIntegrations } from '../shared/buildFilteredIntegrations'; | ||
| import { LOW_QUALITY_TRANSACTION_PATTERNS } from '../shared/lowQualityTransactionPatterns'; | ||
| /** | ||
| * Initializes Sentry for Hono running in a Deno runtime environment. | ||
| * | ||
| * In general, it is recommended to initialize Sentry via the `sentry()` middleware, as it sets up everything by default and calls `init` internally. | ||
| * | ||
| * When manually calling `init`, add the `honoIntegration` to the `integrations` array to set up the Hono integration. | ||
| */ | ||
| export function init(options: HonoDenoOptions): Client | undefined { | ||
| if (getClient()) { | ||
| consoleSandbox(() => { | ||
| // eslint-disable-next-line no-console | ||
| console.warn( | ||
| '[Sentry] Sentry is already initialized. Sentry should only be initialized once, through the `sentry()` middleware. Remove the `Sentry.init()` call, if one exists.', | ||
| ); | ||
| }); | ||
| } | ||
| applySdkMetadata(options, 'hono', ['hono', 'deno']); | ||
| const filteredOptions: HonoDenoOptions = { | ||
| ...options, | ||
| ignoreSpans: [...(options.ignoreSpans || []), ...LOW_QUALITY_TRANSACTION_PATTERNS], | ||
| // Remove Hono from the SDK defaults to prevent double instrumentation: @sentry/deno | ||
| integrations: buildFilteredIntegrations(options.integrations, false), | ||
| }; | ||
| return initDeno(filteredOptions); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { earlyPatchHono } from './shared/applyPatches'; | ||
| earlyPatchHono(); | ||
| export { sentry } from './deno/middleware'; | ||
s1gr1d marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| export * from '@sentry/deno'; | ||
| export { init } from './deno/sdk'; | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.