Skip to content

Commit 3ae3d4d

Browse files
authored
chore(test): Add tests for skipping of integrations for otel (#6143)
1 parent 312b948 commit 3ae3d4d

File tree

8 files changed

+126
-3
lines changed

8 files changed

+126
-3
lines changed

packages/node/src/integrations/http.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export class Http implements Integration {
7272

7373
// Do not auto-instrument for other instrumenter
7474
if (clientOptions && clientOptions.instrumenter !== 'sentry') {
75+
__DEBUG_BUILD__ && logger.log('HTTP Integration is skipped because of instrumenter configuration.');
7576
return;
7677
}
7778

packages/node/test/integrations/http.test.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as sentryCore from '@sentry/core';
22
import { Hub } from '@sentry/core';
33
import { addExtensionMethods, Span, TRACEPARENT_REGEXP, Transaction } from '@sentry/tracing';
44
import { TransactionContext } from '@sentry/types';
5-
import { parseSemver } from '@sentry/utils';
5+
import { logger, parseSemver } from '@sentry/utils';
66
import * as http from 'http';
77
import * as https from 'https';
88
import * as HttpsProxyAgent from 'https-proxy-agent';
@@ -188,6 +188,28 @@ describe('tracing', () => {
188188
expect(transaction.metadata.propagations).toBe(2);
189189
});
190190

191+
it("doesn't attach when using otel instrumenter", () => {
192+
const loggerLogSpy = jest.spyOn(logger, 'log');
193+
194+
const options = getDefaultNodeClientOptions({
195+
dsn: 'https://dogsarebadatkeepingsecrets@squirrelchasers.ingest.sentry.io/12312012',
196+
tracesSampleRate: 1.0,
197+
integrations: [new HttpIntegration({ tracing: true })],
198+
release: '1.0.0',
199+
environment: 'production',
200+
instrumenter: 'otel',
201+
});
202+
const hub = new Hub(new NodeClient(options));
203+
204+
const integration = new HttpIntegration();
205+
integration.setupOnce(
206+
() => {},
207+
() => hub,
208+
);
209+
210+
expect(loggerLogSpy).toBeCalledWith('HTTP Integration is skipped because of instrumenter configuration.');
211+
});
212+
191213
describe('tracePropagationTargets option', () => {
192214
beforeEach(() => {
193215
// hacky way of restoring monkey patched functions

packages/tracing/test/integrations/apollo.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/* eslint-disable @typescript-eslint/unbound-method */
22
import { Hub, Scope } from '@sentry/core';
3+
import { logger } from '@sentry/utils';
34

45
import { Apollo } from '../../src/integrations/node/apollo';
56
import { Span } from '../../src/span';
7+
import { getTestClient } from '../testutils';
68

79
type ApolloResolverGroup = {
810
[key: string]: () => any;
@@ -100,4 +102,19 @@ describe('setupOnce', () => {
100102
});
101103
expect(childSpan.finish).toBeCalled();
102104
});
105+
106+
it("doesn't attach when using otel instrumenter", () => {
107+
const loggerLogSpy = jest.spyOn(logger, 'log');
108+
109+
const client = getTestClient({ instrumenter: 'otel' });
110+
const hub = new Hub(client);
111+
112+
const integration = new Apollo();
113+
integration.setupOnce(
114+
() => {},
115+
() => hub,
116+
);
117+
118+
expect(loggerLogSpy).toBeCalledWith('Apollo Integration is skipped because of instrumenter configuration.');
119+
});
103120
});

packages/tracing/test/integrations/graphql.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/* eslint-disable @typescript-eslint/unbound-method */
22
import { Hub, Scope } from '@sentry/core';
3+
import { logger } from '@sentry/utils';
34

45
import { GraphQL } from '../../src/integrations/node/graphql';
56
import { Span } from '../../src/span';
7+
import { getTestClient } from '../testutils';
68

79
const GQLExecute = {
810
execute() {
@@ -53,4 +55,19 @@ describe('setupOnce', () => {
5355
expect(childSpan.finish).toBeCalled();
5456
expect(scope.setSpan).toHaveBeenCalledTimes(2);
5557
});
58+
59+
it("doesn't attach when using otel instrumenter", () => {
60+
const loggerLogSpy = jest.spyOn(logger, 'log');
61+
62+
const client = getTestClient({ instrumenter: 'otel' });
63+
const hub = new Hub(client);
64+
65+
const integration = new GraphQL();
66+
integration.setupOnce(
67+
() => {},
68+
() => hub,
69+
);
70+
71+
expect(loggerLogSpy).toBeCalledWith('GraphQL Integration is skipped because of instrumenter configuration.');
72+
});
5673
});

packages/tracing/test/integrations/node/mongo.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/* eslint-disable @typescript-eslint/unbound-method */
22
import { Hub, Scope } from '@sentry/core';
3+
import { logger } from '@sentry/utils';
34

45
import { Mongo } from '../../../src/integrations/node/mongo';
56
import { Span } from '../../../src/span';
7+
import { getTestClient } from '../../testutils';
68

79
class Collection {
810
public collectionName: string = 'mockedCollectionName';
@@ -111,4 +113,19 @@ describe('patchOperation()', () => {
111113
});
112114
expect(childSpan.finish).toBeCalled();
113115
});
116+
117+
it("doesn't attach when using otel instrumenter", () => {
118+
const loggerLogSpy = jest.spyOn(logger, 'log');
119+
120+
const client = getTestClient({ instrumenter: 'otel' });
121+
const hub = new Hub(client);
122+
123+
const integration = new Mongo();
124+
integration.setupOnce(
125+
() => {},
126+
() => hub,
127+
);
128+
129+
expect(loggerLogSpy).toBeCalledWith('Mongo Integration is skipped because of instrumenter configuration.');
130+
});
114131
});

packages/tracing/test/integrations/node/postgres.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/* eslint-disable @typescript-eslint/unbound-method */
22
import { Hub, Scope } from '@sentry/core';
3+
import { logger } from '@sentry/utils';
34

45
import { Postgres } from '../../../src/integrations/node/postgres';
56
import { Span } from '../../../src/span';
7+
import { getTestClient } from '../../testutils';
68

79
class PgClient {
810
// https://node-postgres.com/api/client#clientquery
@@ -94,4 +96,19 @@ describe('setupOnce', () => {
9496
expect(childSpan.finish).toBeCalled();
9597
});
9698
});
99+
100+
it("doesn't attach when using otel instrumenter", () => {
101+
const loggerLogSpy = jest.spyOn(logger, 'log');
102+
103+
const client = getTestClient({ instrumenter: 'otel' });
104+
const hub = new Hub(client);
105+
106+
const integration = new Postgres();
107+
integration.setupOnce(
108+
() => {},
109+
() => hub,
110+
);
111+
112+
expect(loggerLogSpy).toBeCalledWith('Postgres Integration is skipped because of instrumenter configuration.');
113+
});
97114
});

packages/tracing/test/integrations/node/prisma.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
/* eslint-disable @typescript-eslint/unbound-method */
22
import { Hub, Scope } from '@sentry/core';
3+
import { logger } from '@sentry/utils';
34

45
import { Prisma } from '../../../src/integrations/node/prisma';
56
import { Span } from '../../../src/span';
7+
import { getTestClient } from '../../testutils';
68

79
type PrismaMiddleware = (params: unknown, next: (params?: unknown) => Promise<unknown>) => Promise<unknown>;
810

@@ -30,7 +32,6 @@ describe('setupOnce', function () {
3032
let childSpan: Span;
3133

3234
beforeAll(() => {
33-
// @ts-ignore, not to export PrismaClient types from integration source
3435
new Prisma({ client: Client }).setupOnce(
3536
() => undefined,
3637
() => new Hub(undefined, scope),
@@ -58,4 +59,19 @@ describe('setupOnce', function () {
5859
done();
5960
});
6061
});
62+
63+
it("doesn't attach when using otel instrumenter", () => {
64+
const loggerLogSpy = jest.spyOn(logger, 'log');
65+
66+
const client = getTestClient({ instrumenter: 'otel' });
67+
const hub = new Hub(client);
68+
69+
const integration = new Prisma({ client: Client });
70+
integration.setupOnce(
71+
() => {},
72+
() => hub,
73+
);
74+
75+
expect(loggerLogSpy).toBeCalledWith('Prisma Integration is skipped because of instrumenter configuration.');
76+
});
6177
});

packages/tracing/test/testutils.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createTransport } from '@sentry/browser';
2-
import { ClientOptions } from '@sentry/types';
2+
import { Client, ClientOptions } from '@sentry/types';
33
import { GLOBAL_OBJ, resolvedSyncPromise } from '@sentry/utils';
44
import { JSDOM } from 'jsdom';
55

@@ -66,3 +66,19 @@ export function getDefaultBrowserClientOptions(options: Partial<ClientOptions> =
6666
...options,
6767
};
6868
}
69+
70+
export function getTestClient(options: Partial<ClientOptions>): Client {
71+
class TestClient {
72+
_options: Partial<ClientOptions>;
73+
74+
constructor(options: Partial<ClientOptions>) {
75+
this._options = options;
76+
}
77+
78+
getOptions(): Partial<ClientOptions> {
79+
return this._options;
80+
}
81+
}
82+
83+
return new TestClient(options) as unknown as Client;
84+
}

0 commit comments

Comments
 (0)