Skip to content

chore(test): Add tests for skipping of integrations for otel #6143

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

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
1 change: 1 addition & 0 deletions packages/node/src/integrations/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
24 changes: 23 additions & 1 deletion packages/node/test/integrations/http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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://[email protected]/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
Expand Down
17 changes: 17 additions & 0 deletions packages/tracing/test/integrations/apollo.test.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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.');
});
});
17 changes: 17 additions & 0 deletions packages/tracing/test/integrations/graphql.test.ts
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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.');
});
});
17 changes: 17 additions & 0 deletions packages/tracing/test/integrations/node/mongo.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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.');
});
});
17 changes: 17 additions & 0 deletions packages/tracing/test/integrations/node/postgres.test.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.');
});
});
18 changes: 17 additions & 1 deletion packages/tracing/test/integrations/node/prisma.test.ts
Original file line number Diff line number Diff line change
@@ -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<unknown>) => Promise<unknown>;

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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.');
});
});
18 changes: 17 additions & 1 deletion packages/tracing/test/testutils.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -66,3 +66,19 @@ export function getDefaultBrowserClientOptions(options: Partial<ClientOptions> =
...options,
};
}

export function getTestClient(options: Partial<ClientOptions>): Client {
class TestClient {
_options: Partial<ClientOptions>;

constructor(options: Partial<ClientOptions>) {
this._options = options;
}

getOptions(): Partial<ClientOptions> {
return this._options;
}
}

return new TestClient(options) as unknown as Client;
}