Skip to content

Commit 43bc507

Browse files
mydeaandreiborza
authored andcommitted
fix(node): Do not warn for missing instrumentation if SDK is disabled (#12041)
Closes #12040
1 parent 762d3c6 commit 43bc507

File tree

7 files changed

+17
-8
lines changed

7 files changed

+17
-8
lines changed

packages/core/src/exports.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,12 @@ export function isInitialized(): boolean {
242242
return !!getClient();
243243
}
244244

245+
/** If the SDK is initialized & enabled. */
246+
export function isEnabled(): boolean {
247+
const client = getClient();
248+
return !!client && client.getOptions().enabled !== false && !!client.getTransport();
249+
}
250+
245251
/**
246252
* Add an event processor.
247253
* This will be added to the current isolation scope, ensuring any event that is processed in the current execution

packages/core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export {
2525
setTags,
2626
setUser,
2727
isInitialized,
28+
isEnabled,
2829
startSession,
2930
endSession,
3031
captureSession,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { isWrapped } from '@opentelemetry/core';
22
import { ConnectInstrumentation } from '@opentelemetry/instrumentation-connect';
3-
import { captureException, defineIntegration } from '@sentry/core';
3+
import { captureException, defineIntegration, isEnabled } from '@sentry/core';
44
import { addOpenTelemetryInstrumentation } from '@sentry/opentelemetry';
55
import type { IntegrationFn } from '@sentry/types';
66
import { consoleSandbox } from '@sentry/utils';
@@ -30,7 +30,7 @@ function connectErrorMiddleware(err: any, req: any, res: any, next: any): void {
3030
export const setupConnectErrorHandler = (app: ConnectApp): void => {
3131
app.use(connectErrorMiddleware);
3232

33-
if (!isWrapped(app.use)) {
33+
if (!isWrapped(app.use) && isEnabled()) {
3434
consoleSandbox(() => {
3535
// eslint-disable-next-line no-console
3636
console.warn(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type * as http from 'http';
22
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';
3-
import { defineIntegration, getDefaultIsolationScope } from '@sentry/core';
3+
import { defineIntegration, getDefaultIsolationScope, isEnabled } from '@sentry/core';
44
import { captureException, getClient, getIsolationScope } from '@sentry/core';
55
import { addOpenTelemetryInstrumentation } from '@sentry/opentelemetry';
66
import type { IntegrationFn } from '@sentry/types';
@@ -119,7 +119,7 @@ export function expressErrorHandler(options?: {
119119
export function setupExpressErrorHandler(app: { use: (middleware: ExpressMiddleware) => unknown }): void {
120120
app.use(expressErrorHandler());
121121

122-
if (!isWrapped(app.use)) {
122+
if (!isWrapped(app.use) && isEnabled()) {
123123
consoleSandbox(() => {
124124
// eslint-disable-next-line no-console
125125
console.warn(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { isWrapped } from '@opentelemetry/core';
22
import { FastifyInstrumentation } from '@opentelemetry/instrumentation-fastify';
3-
import { captureException, defineIntegration, getIsolationScope } from '@sentry/core';
3+
import { captureException, defineIntegration, getIsolationScope, isEnabled } from '@sentry/core';
44
import { addOpenTelemetryInstrumentation } from '@sentry/opentelemetry';
55
import type { IntegrationFn } from '@sentry/types';
66
import { consoleSandbox } from '@sentry/utils';
@@ -84,7 +84,7 @@ export function setupFastifyErrorHandler(fastify: Fastify): void {
8484

8585
fastify.register(plugin);
8686

87-
if (!isWrapped(fastify.addHook)) {
87+
if (!isWrapped(fastify.addHook) && isEnabled()) {
8888
consoleSandbox(() => {
8989
// eslint-disable-next-line no-console
9090
console.warn(

packages/node/src/integrations/tracing/hapi/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
getDefaultIsolationScope,
1010
getIsolationScope,
1111
getRootSpan,
12+
isEnabled,
1213
} from '@sentry/core';
1314
import { addOpenTelemetryInstrumentation } from '@sentry/opentelemetry';
1415
import type { IntegrationFn } from '@sentry/types';
@@ -95,7 +96,7 @@ export async function setupHapiErrorHandler(server: Server): Promise<void> {
9596
await server.register(hapiErrorPlugin);
9697

9798
// eslint-disable-next-line @typescript-eslint/unbound-method
98-
if (!isWrapped(server.register)) {
99+
if (!isWrapped(server.register) && isEnabled()) {
99100
consoleSandbox(() => {
100101
// eslint-disable-next-line no-console
101102
console.warn(

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
defineIntegration,
77
getDefaultIsolationScope,
88
getIsolationScope,
9+
isEnabled,
910
spanToJSON,
1011
} from '@sentry/core';
1112
import { addOpenTelemetryInstrumentation } from '@sentry/opentelemetry';
@@ -50,7 +51,7 @@ export const setupKoaErrorHandler = (app: { use: (arg0: (ctx: any, next: any) =>
5051
}
5152
});
5253

53-
if (!isWrapped(app.use)) {
54+
if (!isWrapped(app.use) && isEnabled()) {
5455
consoleSandbox(() => {
5556
// eslint-disable-next-line no-console
5657
console.warn(

0 commit comments

Comments
 (0)