Skip to content

Commit 29e89e1

Browse files
authored
feat(fastify): Warn if fastify is not instrumented (#11917)
When using `setupFastifyErrorHandler(app)` we can check if the app was correctly instrumented. Not sure how to best test this - I tested this manually in a test app and could verify that the log was printed when requiring fastify before calling init!
1 parent 3138695 commit 29e89e1

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { isWrapped } from '@opentelemetry/core';
12
import { FastifyInstrumentation } from '@opentelemetry/instrumentation-fastify';
23
import { captureException, defineIntegration, getIsolationScope } from '@sentry/core';
34
import { addOpenTelemetryInstrumentation } from '@sentry/opentelemetry';
45
import type { IntegrationFn } from '@sentry/types';
6+
import { consoleSandbox } from '@sentry/utils';
57

68
import { addOriginToSpan } from '../../utils/addOriginToSpan';
79

@@ -81,4 +83,13 @@ export function setupFastifyErrorHandler(fastify: Fastify): void {
8183
);
8284

8385
fastify.register(plugin);
86+
87+
if (!isWrapped(fastify.addHook)) {
88+
consoleSandbox(() => {
89+
// eslint-disable-next-line no-console
90+
console.warn(
91+
'[Sentry] Fastify is not instrumented. This is likely because you required/imported fastify before calling `Sentry.init()`.',
92+
);
93+
});
94+
}
8495
}

0 commit comments

Comments
 (0)