Skip to content

Commit cd73831

Browse files
mydeaclaude
andcommitted
fix(hono): expose shared helpers from the Node-free server-utils entry
The Cloudflare and Deno Hono adapters imported applyHonoPatches, earlyPatchHono and createHonoRequestMiddleware from the main @sentry/server-utils entry, whose barrel also loads node:diagnostics_channel and other Node-only modules — which can fail at import/bundle time on Cloudflare Workers and Deno. Export the runtime-agnostic helpers from `exports.ts` (shared by both entries), sourced directly from their modules rather than the ./integrations/hono barrel, so they are available from @sentry/server-utils/no-diagnostic-channels without pulling in diagnostics-channel. Point the Cloudflare and Deno adapters at that Node-free entry. Also move the applyHonoPatches wrapper out of the barrel into the Node-free applyPatches module. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 6e8a7e4 commit cd73831

8 files changed

Lines changed: 34 additions & 23 deletions

File tree

‎packages/hono/src/cloudflare/middleware.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { withSentry } from '@sentry/cloudflare';
22
import { applySdkMetadata, type BaseTransportOptions, debug, type Options } from '@sentry/core';
33
import { getConnInfo } from 'hono/cloudflare-workers';
4-
import { applyHonoPatches, createHonoRequestMiddleware, type SentryHonoMiddlewareOptions } from '@sentry/server-utils';
4+
import {
5+
applyHonoPatches,
6+
createHonoRequestMiddleware,
7+
type SentryHonoMiddlewareOptions,
8+
} from '@sentry/server-utils/no-diagnostic-channels';
59
import type { Env, Hono, MiddlewareHandler } from 'hono';
610
import { buildFilteredIntegrations } from '../shared/buildFilteredIntegrations';
711
import { LOW_QUALITY_TRANSACTION_PATTERNS } from '../shared/lowQualityTransactionPatterns';

‎packages/hono/src/deno/middleware.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { type BaseTransportOptions, debug, type Options } from '@sentry/core';
22
import { init } from './sdk';
33
import { getConnInfo } from 'hono/deno';
4-
import { applyHonoPatches, createHonoRequestMiddleware, type SentryHonoMiddlewareOptions } from '@sentry/server-utils';
4+
import {
5+
applyHonoPatches,
6+
createHonoRequestMiddleware,
7+
type SentryHonoMiddlewareOptions,
8+
} from '@sentry/server-utils/no-diagnostic-channels';
59
import type { Env, Hono, MiddlewareHandler } from 'hono';
610

711
export interface HonoDenoOptions extends Options<BaseTransportOptions>, SentryHonoMiddlewareOptions {}

‎packages/hono/src/index.cloudflare.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { earlyPatchHono } from '@sentry/server-utils';
1+
import { earlyPatchHono } from '@sentry/server-utils/no-diagnostic-channels';
22
import { Hono } from 'hono';
33

44
earlyPatchHono(Hono);

‎packages/hono/src/index.deno.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { earlyPatchHono } from '@sentry/server-utils';
1+
import { earlyPatchHono } from '@sentry/server-utils/no-diagnostic-channels';
22
import { Hono } from 'hono';
33

44
earlyPatchHono(Hono);

‎packages/server-utils/src/exports.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,12 @@ export { getSqlQuerySummary, sanitizeSqlQuery, sanitizeSqlQueryWithSummary } fro
77
export type { SqlDialect } from './utils/sql';
88
export { instrumentPostgresJsSql } from './integrations/postgresjs';
99
export type { PostgresConnectionContext } from './integrations/postgresjs';
10+
11+
// Shared, runtime-agnostic Hono instrumentation re-used by the `@sentry/hono` SDK across all runtimes.
12+
// Sourced directly from their modules (not the `./integrations/hono` barrel, which also exports the
13+
// diagnostics-channel-based `honoIntegration`) so the non-Node adapters can import them from the
14+
// Node-free `@sentry/server-utils/no-diagnostic-channels` entry.
15+
export { applyHonoPatches, earlyPatchHono } from './integrations/hono/applyPatches';
16+
export { createHonoRequestMiddleware } from './integrations/hono/createHonoMiddleware';
17+
export type { CreateHonoRequestMiddlewareOptions } from './integrations/hono/createHonoMiddleware';
18+
export type { SentryHonoMiddlewareOptions } from './integrations/hono/types';

‎packages/server-utils/src/index.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ export { genericPoolIntegration } from './integrations/generic-pool';
4040
export { googleGenAIIntegration } from './integrations/google-genai';
4141
export { graphqlIntegration } from './integrations/graphql';
4242
export { hapiIntegration } from './integrations/hapi';
43-
// Shared, runtime-agnostic Hono instrumentation re-used by the `@sentry/hono` SDK.
44-
export { applyHonoPatches, earlyPatchHono, createHonoRequestMiddleware } from './integrations/hono';
45-
export type { CreateHonoRequestMiddlewareOptions, SentryHonoMiddlewareOptions } from './integrations/hono';
4643
export { koaIntegration } from './integrations/koa';
4744
export { redisIntegration } from './integrations/redis';
4845
export { kafkaIntegration } from './integrations/kafkajs';

‎packages/server-utils/src/integrations/hono/applyPatches.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,13 @@ export function applyPatches<E extends Env>(app: Hono<E>): void {
5959

6060
pendingSubApps.clear();
6161
}
62+
63+
/**
64+
* Applies Sentry's Hono span patches to an app instance.
65+
*
66+
* Typed loosely (`object`) so the real `hono` `Hono<E, S, P>` type used by the `@sentry/hono` SDK is
67+
* accepted without a cast; internally it is treated as the vendored {@link Hono} shape.
68+
*/
69+
export function applyHonoPatches(app: object): void {
70+
applyPatches(app as Hono);
71+
}
Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
1-
import { applyPatches } from './applyPatches';
2-
import type { Hono } from './honoTypes';
3-
41
// Shared, runtime-agnostic Hono instrumentation, re-used by the `@sentry/hono` SDK across all of its
5-
// runtimes (Node, Bun, Cloudflare, Deno). None of these modules import `hono` (at runtime or type
6-
// level), so they stay safe to load in every server SDK — including apps that do not use Hono.
7-
export { earlyPatchHono } from './applyPatches';
2+
// runtimes (Node, Bun, Cloudflare, Deno). None of these modules import `hono` or `node:diagnostics_channel`,
3+
// so they stay safe to load in every server SDK — including the Node-free (`no-diagnostic-channels`) entry.
4+
export { applyHonoPatches, earlyPatchHono } from './applyPatches';
85
export { createHonoRequestMiddleware } from './createHonoMiddleware';
96
export type { CreateHonoRequestMiddlewareOptions } from './createHonoMiddleware';
107
export type { SentryHonoMiddlewareOptions } from './types';
11-
12-
/**
13-
* Applies Sentry's Hono span patches to an app instance.
14-
*
15-
* Typed loosely (`object`) so the real `hono` `Hono<E, S, P>` type used by the `@sentry/hono` SDK is
16-
* accepted without a cast; internally it is treated as the vendored {@link Hono} shape.
17-
*/
18-
export function applyHonoPatches(app: object): void {
19-
applyPatches(app as Hono);
20-
}

0 commit comments

Comments
 (0)