Skip to content

Commit 4b014ce

Browse files
committed
fix default integrations case
1 parent 4f0e13f commit 4b014ce

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

packages/hono/src/cloudflare/middleware.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ export const sentry = (app: Hono, options: HonoOptions | undefined = {}): Middle
2323
// Always filter out the Hono integration from user-provided integrations (or when nothing is specified).
2424
// The Hono integration is already set up by withSentry, so adding it again would cause double-capturing (and non-parametrized URLs).
2525
integrations: Array.isArray(userIntegrations)
26-
? userIntegrations.filter(filterHonoIntegration)
26+
? defaults => [...defaults.filter(filterHonoIntegration), ...userIntegrations.filter(filterHonoIntegration)]
2727
: typeof userIntegrations === 'function'
28-
? (defaults: Integration[]) => userIntegrations(defaults).filter(filterHonoIntegration)
29-
: (defaults: Integration[]) => defaults.filter(filterHonoIntegration),
28+
? defaults => userIntegrations(defaults).filter(filterHonoIntegration)
29+
: defaults => defaults.filter(filterHonoIntegration),
3030
}),
3131
app,
3232
);

packages/hono/test/cloudflare/middleware.test.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ describe('Hono Cloudflare Middleware', () => {
130130
const honoIntegration = { name: 'Hono' } as SentryCore.Integration;
131131
const otherIntegration = { name: 'Other' } as SentryCore.Integration;
132132

133-
const getIntegrationsResult = (): SentryCore.Integration[] => {
133+
const getIntegrationsResult = () => {
134134
const optionsCallback = withSentryMock.mock.calls[0]?.[0];
135135
return optionsCallback().integrations;
136136
};
@@ -143,7 +143,18 @@ describe('Hono Cloudflare Middleware', () => {
143143
const app = new Hono();
144144
sentry(app, { integrations: input });
145145

146-
expect(getIntegrationsResult()).toEqual(expected);
146+
const integrationsFn = getIntegrationsResult() as (defaults: SentryCore.Integration[]) => SentryCore.Integration[];
147+
expect(integrationsFn([])).toEqual(expected);
148+
});
149+
150+
it('filters Hono from defaults when user provides an array', () => {
151+
const app = new Hono();
152+
sentry(app, { integrations: [otherIntegration] });
153+
154+
const integrationsFn = getIntegrationsResult() as (defaults: SentryCore.Integration[]) => SentryCore.Integration[];
155+
// Simulates getIntegrationsToSetup: defaults (from Cloudflare) include Hono; result must exclude it
156+
const defaultsWithHono = [honoIntegration, otherIntegration];
157+
expect(integrationsFn(defaultsWithHono)).toEqual([otherIntegration, otherIntegration]);
147158
});
148159

149160
it('filters Hono integration out of a function result', () => {

0 commit comments

Comments
 (0)