diff --git a/packages/node/src/integrations/http.ts b/packages/node/src/integrations/http.ts index b95faf58d848..4cdd58f7ee25 100644 --- a/packages/node/src/integrations/http.ts +++ b/packages/node/src/integrations/http.ts @@ -72,6 +72,7 @@ export class Http implements Integration { // Do not auto-instrument for other instrumenter if (clientOptions && clientOptions.instrumenter !== 'sentry') { + __DEBUG_BUILD__ && logger.log('HTTP Integration is skipped because of instrumenter configuration.'); return; } diff --git a/packages/node/test/integrations/http.test.ts b/packages/node/test/integrations/http.test.ts index 4f5205f0b596..6bf8a7117327 100644 --- a/packages/node/test/integrations/http.test.ts +++ b/packages/node/test/integrations/http.test.ts @@ -2,7 +2,7 @@ import * as sentryCore from '@sentry/core'; import { Hub } from '@sentry/core'; import { addExtensionMethods, Span, TRACEPARENT_REGEXP, Transaction } from '@sentry/tracing'; import { TransactionContext } from '@sentry/types'; -import { parseSemver } from '@sentry/utils'; +import { logger, parseSemver } from '@sentry/utils'; import * as http from 'http'; import * as https from 'https'; import * as HttpsProxyAgent from 'https-proxy-agent'; @@ -188,6 +188,28 @@ describe('tracing', () => { expect(transaction.metadata.propagations).toBe(2); }); + it("doesn't attach when using otel instrumenter", () => { + const loggerLogSpy = jest.spyOn(logger, 'log'); + + const options = getDefaultNodeClientOptions({ + dsn: 'https://dogsarebadatkeepingsecrets@squirrelchasers.ingest.sentry.io/12312012', + tracesSampleRate: 1.0, + integrations: [new HttpIntegration({ tracing: true })], + release: '1.0.0', + environment: 'production', + instrumenter: 'otel', + }); + const hub = new Hub(new NodeClient(options)); + + const integration = new HttpIntegration(); + integration.setupOnce( + () => {}, + () => hub, + ); + + expect(loggerLogSpy).toBeCalledWith('HTTP Integration is skipped because of instrumenter configuration.'); + }); + describe('tracePropagationTargets option', () => { beforeEach(() => { // hacky way of restoring monkey patched functions diff --git a/packages/tracing/test/integrations/apollo.test.ts b/packages/tracing/test/integrations/apollo.test.ts index 2f8e5c843d07..8b9946ba4a70 100644 --- a/packages/tracing/test/integrations/apollo.test.ts +++ b/packages/tracing/test/integrations/apollo.test.ts @@ -1,8 +1,10 @@ /* eslint-disable @typescript-eslint/unbound-method */ import { Hub, Scope } from '@sentry/core'; +import { logger } from '@sentry/utils'; import { Apollo } from '../../src/integrations/node/apollo'; import { Span } from '../../src/span'; +import { getTestClient } from '../testutils'; type ApolloResolverGroup = { [key: string]: () => any; @@ -100,4 +102,19 @@ describe('setupOnce', () => { }); expect(childSpan.finish).toBeCalled(); }); + + it("doesn't attach when using otel instrumenter", () => { + const loggerLogSpy = jest.spyOn(logger, 'log'); + + const client = getTestClient({ instrumenter: 'otel' }); + const hub = new Hub(client); + + const integration = new Apollo(); + integration.setupOnce( + () => {}, + () => hub, + ); + + expect(loggerLogSpy).toBeCalledWith('Apollo Integration is skipped because of instrumenter configuration.'); + }); }); diff --git a/packages/tracing/test/integrations/graphql.test.ts b/packages/tracing/test/integrations/graphql.test.ts index e074dfc602f8..265bbe0fb0d8 100644 --- a/packages/tracing/test/integrations/graphql.test.ts +++ b/packages/tracing/test/integrations/graphql.test.ts @@ -1,8 +1,10 @@ /* eslint-disable @typescript-eslint/unbound-method */ import { Hub, Scope } from '@sentry/core'; +import { logger } from '@sentry/utils'; import { GraphQL } from '../../src/integrations/node/graphql'; import { Span } from '../../src/span'; +import { getTestClient } from '../testutils'; const GQLExecute = { execute() { @@ -53,4 +55,19 @@ describe('setupOnce', () => { expect(childSpan.finish).toBeCalled(); expect(scope.setSpan).toHaveBeenCalledTimes(2); }); + + it("doesn't attach when using otel instrumenter", () => { + const loggerLogSpy = jest.spyOn(logger, 'log'); + + const client = getTestClient({ instrumenter: 'otel' }); + const hub = new Hub(client); + + const integration = new GraphQL(); + integration.setupOnce( + () => {}, + () => hub, + ); + + expect(loggerLogSpy).toBeCalledWith('GraphQL Integration is skipped because of instrumenter configuration.'); + }); }); diff --git a/packages/tracing/test/integrations/node/mongo.test.ts b/packages/tracing/test/integrations/node/mongo.test.ts index b7417a6ae9b2..e362db6f0c47 100644 --- a/packages/tracing/test/integrations/node/mongo.test.ts +++ b/packages/tracing/test/integrations/node/mongo.test.ts @@ -1,8 +1,10 @@ /* eslint-disable @typescript-eslint/unbound-method */ import { Hub, Scope } from '@sentry/core'; +import { logger } from '@sentry/utils'; import { Mongo } from '../../../src/integrations/node/mongo'; import { Span } from '../../../src/span'; +import { getTestClient } from '../../testutils'; class Collection { public collectionName: string = 'mockedCollectionName'; @@ -111,4 +113,19 @@ describe('patchOperation()', () => { }); expect(childSpan.finish).toBeCalled(); }); + + it("doesn't attach when using otel instrumenter", () => { + const loggerLogSpy = jest.spyOn(logger, 'log'); + + const client = getTestClient({ instrumenter: 'otel' }); + const hub = new Hub(client); + + const integration = new Mongo(); + integration.setupOnce( + () => {}, + () => hub, + ); + + expect(loggerLogSpy).toBeCalledWith('Mongo Integration is skipped because of instrumenter configuration.'); + }); }); diff --git a/packages/tracing/test/integrations/node/postgres.test.ts b/packages/tracing/test/integrations/node/postgres.test.ts index 4b6c23db41e6..2ef3754b28ef 100644 --- a/packages/tracing/test/integrations/node/postgres.test.ts +++ b/packages/tracing/test/integrations/node/postgres.test.ts @@ -1,8 +1,10 @@ /* eslint-disable @typescript-eslint/unbound-method */ import { Hub, Scope } from '@sentry/core'; +import { logger } from '@sentry/utils'; import { Postgres } from '../../../src/integrations/node/postgres'; import { Span } from '../../../src/span'; +import { getTestClient } from '../../testutils'; class PgClient { // https://node-postgres.com/api/client#clientquery @@ -94,4 +96,19 @@ describe('setupOnce', () => { expect(childSpan.finish).toBeCalled(); }); }); + + it("doesn't attach when using otel instrumenter", () => { + const loggerLogSpy = jest.spyOn(logger, 'log'); + + const client = getTestClient({ instrumenter: 'otel' }); + const hub = new Hub(client); + + const integration = new Postgres(); + integration.setupOnce( + () => {}, + () => hub, + ); + + expect(loggerLogSpy).toBeCalledWith('Postgres Integration is skipped because of instrumenter configuration.'); + }); }); diff --git a/packages/tracing/test/integrations/node/prisma.test.ts b/packages/tracing/test/integrations/node/prisma.test.ts index 3c088ac25834..d2adb685fc9d 100644 --- a/packages/tracing/test/integrations/node/prisma.test.ts +++ b/packages/tracing/test/integrations/node/prisma.test.ts @@ -1,8 +1,10 @@ /* eslint-disable @typescript-eslint/unbound-method */ import { Hub, Scope } from '@sentry/core'; +import { logger } from '@sentry/utils'; import { Prisma } from '../../../src/integrations/node/prisma'; import { Span } from '../../../src/span'; +import { getTestClient } from '../../testutils'; type PrismaMiddleware = (params: unknown, next: (params?: unknown) => Promise) => Promise; @@ -30,7 +32,6 @@ describe('setupOnce', function () { let childSpan: Span; beforeAll(() => { - // @ts-ignore, not to export PrismaClient types from integration source new Prisma({ client: Client }).setupOnce( () => undefined, () => new Hub(undefined, scope), @@ -58,4 +59,19 @@ describe('setupOnce', function () { done(); }); }); + + it("doesn't attach when using otel instrumenter", () => { + const loggerLogSpy = jest.spyOn(logger, 'log'); + + const client = getTestClient({ instrumenter: 'otel' }); + const hub = new Hub(client); + + const integration = new Prisma({ client: Client }); + integration.setupOnce( + () => {}, + () => hub, + ); + + expect(loggerLogSpy).toBeCalledWith('Prisma Integration is skipped because of instrumenter configuration.'); + }); }); diff --git a/packages/tracing/test/testutils.ts b/packages/tracing/test/testutils.ts index 474eb57846f4..4ddd042a1240 100644 --- a/packages/tracing/test/testutils.ts +++ b/packages/tracing/test/testutils.ts @@ -1,5 +1,5 @@ import { createTransport } from '@sentry/browser'; -import { ClientOptions } from '@sentry/types'; +import { Client, ClientOptions } from '@sentry/types'; import { GLOBAL_OBJ, resolvedSyncPromise } from '@sentry/utils'; import { JSDOM } from 'jsdom'; @@ -66,3 +66,19 @@ export function getDefaultBrowserClientOptions(options: Partial = ...options, }; } + +export function getTestClient(options: Partial): Client { + class TestClient { + _options: Partial; + + constructor(options: Partial) { + this._options = options; + } + + getOptions(): Partial { + return this._options; + } + } + + return new TestClient(options) as unknown as Client; +}