Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(node): Do not warn for missing instrumentation if SDK is disabled #12041

Merged
merged 1 commit into from
May 15, 2024
Merged
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
6 changes: 6 additions & 0 deletions packages/core/src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ export function isInitialized(): boolean {
return !!getClient();
}

/** If the SDK is initialized & enabled. */
export function isEnabled(): boolean {
const client = getClient();
return !!client && client.getOptions().enabled !== false && !!client.getTransport();
}

/**
* Add an event processor.
* This will be added to the current isolation scope, ensuring any event that is processed in the current execution
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export {
setTags,
setUser,
isInitialized,
isEnabled,
startSession,
endSession,
captureSession,
Expand Down
4 changes: 2 additions & 2 deletions packages/node/src/integrations/tracing/connect.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isWrapped } from '@opentelemetry/core';
import { ConnectInstrumentation } from '@opentelemetry/instrumentation-connect';
import { captureException, defineIntegration } from '@sentry/core';
import { captureException, defineIntegration, isEnabled } from '@sentry/core';
import { addOpenTelemetryInstrumentation } from '@sentry/opentelemetry';
import type { IntegrationFn } from '@sentry/types';
import { consoleSandbox } from '@sentry/utils';
Expand Down Expand Up @@ -30,7 +30,7 @@ function connectErrorMiddleware(err: any, req: any, res: any, next: any): void {
export const setupConnectErrorHandler = (app: ConnectApp): void => {
app.use(connectErrorMiddleware);

if (!isWrapped(app.use)) {
if (!isWrapped(app.use) && isEnabled()) {
consoleSandbox(() => {
// eslint-disable-next-line no-console
console.warn(
Expand Down
4 changes: 2 additions & 2 deletions packages/node/src/integrations/tracing/express.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type * as http from 'http';
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';
import { defineIntegration, getDefaultIsolationScope } from '@sentry/core';
import { defineIntegration, getDefaultIsolationScope, isEnabled } from '@sentry/core';
import { captureException, getClient, getIsolationScope } from '@sentry/core';
import { addOpenTelemetryInstrumentation } from '@sentry/opentelemetry';
import type { IntegrationFn } from '@sentry/types';
Expand Down Expand Up @@ -119,7 +119,7 @@ export function expressErrorHandler(options?: {
export function setupExpressErrorHandler(app: { use: (middleware: ExpressMiddleware) => unknown }): void {
app.use(expressErrorHandler());

if (!isWrapped(app.use)) {
if (!isWrapped(app.use) && isEnabled()) {
consoleSandbox(() => {
// eslint-disable-next-line no-console
console.warn(
Expand Down
4 changes: 2 additions & 2 deletions packages/node/src/integrations/tracing/fastify.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isWrapped } from '@opentelemetry/core';
import { FastifyInstrumentation } from '@opentelemetry/instrumentation-fastify';
import { captureException, defineIntegration, getIsolationScope } from '@sentry/core';
import { captureException, defineIntegration, getIsolationScope, isEnabled } from '@sentry/core';
import { addOpenTelemetryInstrumentation } from '@sentry/opentelemetry';
import type { IntegrationFn } from '@sentry/types';
import { consoleSandbox } from '@sentry/utils';
Expand Down Expand Up @@ -84,7 +84,7 @@ export function setupFastifyErrorHandler(fastify: Fastify): void {

fastify.register(plugin);

if (!isWrapped(fastify.addHook)) {
if (!isWrapped(fastify.addHook) && isEnabled()) {
consoleSandbox(() => {
// eslint-disable-next-line no-console
console.warn(
Expand Down
3 changes: 2 additions & 1 deletion packages/node/src/integrations/tracing/hapi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getDefaultIsolationScope,
getIsolationScope,
getRootSpan,
isEnabled,
} from '@sentry/core';
import { addOpenTelemetryInstrumentation } from '@sentry/opentelemetry';
import type { IntegrationFn } from '@sentry/types';
Expand Down Expand Up @@ -95,7 +96,7 @@ export async function setupHapiErrorHandler(server: Server): Promise<void> {
await server.register(hapiErrorPlugin);

// eslint-disable-next-line @typescript-eslint/unbound-method
if (!isWrapped(server.register)) {
if (!isWrapped(server.register) && isEnabled()) {
consoleSandbox(() => {
// eslint-disable-next-line no-console
console.warn(
Expand Down
3 changes: 2 additions & 1 deletion packages/node/src/integrations/tracing/koa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
defineIntegration,
getDefaultIsolationScope,
getIsolationScope,
isEnabled,
spanToJSON,
} from '@sentry/core';
import { addOpenTelemetryInstrumentation } from '@sentry/opentelemetry';
Expand Down Expand Up @@ -50,7 +51,7 @@ export const setupKoaErrorHandler = (app: { use: (arg0: (ctx: any, next: any) =>
}
});

if (!isWrapped(app.use)) {
if (!isWrapped(app.use) && isEnabled()) {
consoleSandbox(() => {
// eslint-disable-next-line no-console
console.warn(
Expand Down
Loading