Skip to content

Commit d755a90

Browse files
committed
always warn if not initialized
1 parent aa6df95 commit d755a90

2 files changed

Lines changed: 14 additions & 13 deletions

File tree

packages/hono/src/node/middleware.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ export interface HonoNodeOptions extends Options<BaseTransportOptions> {}
1717
export const sentry = <E extends Env>(app: Hono<E>, options?: SentryHonoMiddlewareOptions): MiddlewareHandler => {
1818
const sentryClient = getClient();
1919
if (sentryClient === undefined) {
20-
debug.warn(
21-
'Sentry is not initialized. Call `init()` from @sentry/hono/node in an `instrument.ts` file loaded via `--import` to set up Sentry for your application.',
22-
);
20+
consoleSandbox(() => {
21+
// eslint-disable-next-line no-console
22+
console.warn(
23+
'[@sentry/hono] Sentry is not initialized. Call `init()` from `@sentry/hono/node` in an `instrument.ts` file loaded via `--import` to set up Sentry for your application.',
24+
);
25+
});
2326
} else {
2427
const isInitializedWithHonoSdk = sentryClient.getOptions()._metadata?.sdk?.name === 'sentry.javascript.hono';
2528

packages/hono/test/node/middleware.test.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,18 @@ describe('Hono Node Middleware', () => {
6262
expect(middleware.constructor.name).toBe('AsyncFunction');
6363
});
6464

65-
it('emits a warning when Sentry is not initialized', () => {
66-
const warnSpy = vi.spyOn(SentryCore.debug, 'warn');
65+
it('emits a console.warn when Sentry is not initialized', () => {
66+
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
6767
vi.spyOn(SentryCore, 'getClient').mockReturnValue(undefined);
6868

6969
const app = new Hono();
7070
sentry(app);
7171

72-
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('Sentry is not initialized'));
72+
expect(consoleWarnSpy).toHaveBeenCalledWith(expect.stringContaining('Sentry is not initialized'));
73+
consoleWarnSpy.mockRestore();
7374
});
7475

7576
it('does not emit a warning when Sentry is already initialized with @sentry/hono/node', () => {
76-
const warnSpy = vi.spyOn(SentryCore.debug, 'warn');
7777
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
7878
const fakeClient = {
7979
getOptions: () => ({
@@ -86,7 +86,6 @@ describe('Hono Node Middleware', () => {
8686
const app = new Hono();
8787
sentry(app);
8888

89-
expect(warnSpy).not.toHaveBeenCalled();
9089
expect(consoleWarnSpy).not.toHaveBeenCalled();
9190
consoleWarnSpy.mockRestore();
9291
});
@@ -172,18 +171,18 @@ describe('Hono Node Middleware', () => {
172171
expect(middleware.constructor.name).toBe('AsyncFunction');
173172
});
174173

175-
it('emits a warning when Sentry is not initialized', () => {
176-
const warnSpy = vi.spyOn(SentryCore.debug, 'warn');
174+
it('emits a console.warn when Sentry is not initialized', () => {
175+
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
177176
vi.spyOn(SentryCore, 'getClient').mockReturnValue(undefined);
178177

179178
const app = new Hono();
180179
sentry(app);
181180

182-
expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('Sentry is not initialized'));
181+
expect(consoleWarnSpy).toHaveBeenCalledWith(expect.stringContaining('Sentry is not initialized'));
182+
consoleWarnSpy.mockRestore();
183183
});
184184

185185
it('does not emit a warning when Sentry is already initialized with @sentry/hono/node', () => {
186-
const warnSpy = vi.spyOn(SentryCore.debug, 'warn');
187186
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
188187
const fakeClient = {
189188
getOptions: () => ({
@@ -196,7 +195,6 @@ describe('Hono Node Middleware', () => {
196195
const app = new Hono();
197196
const middleware = sentry(app);
198197

199-
expect(warnSpy).not.toHaveBeenCalled();
200198
expect(consoleWarnSpy).not.toHaveBeenCalled();
201199
expect(middleware.constructor.name).toBe('AsyncFunction');
202200
consoleWarnSpy.mockRestore();

0 commit comments

Comments
 (0)