Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/hono/src/bun/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ import { LOW_QUALITY_TRANSACTION_PATTERNS } from '../shared/lowQualityTransactio
* When manually calling `init`, add the `honoIntegration` to the `integrations` array to set up the Hono integration.
*/
export function init(options: HonoBunOptions): Client | undefined {
if (getClient()) {
const existingClient = getClient();
if (existingClient) {
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.',
);
});
// Re-initializing would replace the client and drop anything buffered on it
return existingClient;
}

applySdkMetadata(options, 'hono', ['hono', 'bun']);
Expand Down
5 changes: 4 additions & 1 deletion packages/hono/src/deno/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ import { LOW_QUALITY_TRANSACTION_PATTERNS } from '../shared/lowQualityTransactio
* 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()) {
const existingClient = getClient();
if (existingClient) {
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.',
);
});
// Re-initializing would replace the client and drop anything buffered on it
return existingClient;
}

applySdkMetadata(options, 'hono', ['hono', 'deno']);
Expand Down
12 changes: 10 additions & 2 deletions packages/hono/test/bun/middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,22 @@ describe('Hono Bun Middleware', () => {
});

describe('double-init guard', () => {
it('still calls init even when Sentry is already initialized', () => {
it('does not re-initialize when Sentry is already initialized', () => {
const fakeClient = { getOptions: () => ({}) };
getClientMock.mockReturnValue(fakeClient as unknown as SentryCore.Client);

const app = new Hono();
sentry(app, { dsn: 'https://public@dsn.ingest.sentry.io/1337' });

expect(initBunMock).toHaveBeenCalledTimes(1);
expect(initBunMock).not.toHaveBeenCalled();
});

it('returns the existing client when Sentry is already initialized', () => {
const fakeClient = { getOptions: () => ({}) };
getClientMock.mockReturnValue(fakeClient as unknown as SentryCore.Client);

expect(init({ dsn: 'https://public@dsn.ingest.sentry.io/1337' })).toBe(fakeClient);
expect(initBunMock).not.toHaveBeenCalled();
});

it('emits a console.warn directing to remove the duplicate init call when Sentry is already initialized', () => {
Expand Down
12 changes: 10 additions & 2 deletions packages/hono/test/deno/middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,22 @@ describe('Hono Deno Middleware', () => {
});

describe('double-init guard', () => {
it('still calls init even when Sentry is already initialized', () => {
it('does not re-initialize when Sentry is already initialized', () => {
const fakeClient = { getOptions: () => ({}) };
getClientMock.mockReturnValue(fakeClient as unknown as SentryCore.Client);

const app = new Hono();
sentry(app, { dsn: 'https://public@dsn.ingest.sentry.io/1337' });

expect(initDenoMock).toHaveBeenCalledTimes(1);
expect(initDenoMock).not.toHaveBeenCalled();
});

it('returns the existing client when Sentry is already initialized', () => {
const fakeClient = { getOptions: () => ({}) };
getClientMock.mockReturnValue(fakeClient as unknown as SentryCore.Client);

expect(init({ dsn: 'https://public@dsn.ingest.sentry.io/1337' })).toBe(fakeClient);
expect(initDenoMock).not.toHaveBeenCalled();
});

it('emits a console.warn directing to remove the duplicate init call when Sentry is already initialized', () => {
Expand Down