Skip to content

Commit d7cfc95

Browse files
authored
feat(koa): Warn if koa is not instrumented (#11931)
This prints a warning if we detect that the koa app passed to setupKoaErrorHandler is not instrumented. This happens if you import koa before calling Sentry.init.
1 parent 19b5eb3 commit d7cfc95

File tree

1 file changed

+11
-1
lines changed
  • packages/node/src/integrations/tracing

1 file changed

+11
-1
lines changed

packages/node/src/integrations/tracing/koa.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isWrapped } from '@opentelemetry/core';
12
import { KoaInstrumentation } from '@opentelemetry/instrumentation-koa';
23
import { SEMATTRS_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';
34
import {
@@ -9,7 +10,7 @@ import {
910
} from '@sentry/core';
1011
import { addOpenTelemetryInstrumentation } from '@sentry/opentelemetry';
1112
import type { IntegrationFn } from '@sentry/types';
12-
import { logger } from '@sentry/utils';
13+
import { consoleSandbox, logger } from '@sentry/utils';
1314
import { DEBUG_BUILD } from '../../debug-build';
1415

1516
const _koaIntegration = (() => {
@@ -48,4 +49,13 @@ export const setupKoaErrorHandler = (app: { use: (arg0: (ctx: any, next: any) =>
4849
captureException(error);
4950
}
5051
});
52+
53+
if (!isWrapped(app.use)) {
54+
consoleSandbox(() => {
55+
// eslint-disable-next-line no-console
56+
console.warn(
57+
'[Sentry] Koa is not instrumented. This is likely because you required/imported koa before calling `Sentry.init()`.',
58+
);
59+
});
60+
}
5161
};

0 commit comments

Comments
 (0)