Skip to content

Commit d8ae163

Browse files
committed
chore(test): Add tests for skipping of integrations for otel
1 parent 71492a8 commit d8ae163

File tree

15 files changed

+163
-1
lines changed

15 files changed

+163
-1
lines changed

packages/node/src/integrations/http.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ export class Http implements Integration {
3838
*/
3939
public name: string = Http.id;
4040

41+
/**
42+
* If the integration was skipped due to internal checks.
43+
*/
44+
public _wasSkipped: boolean = false;
45+
4146
/**
4247
* @inheritDoc
4348
*/
@@ -65,13 +70,15 @@ export class Http implements Integration {
6570
): void {
6671
// No need to instrument if we don't want to track anything
6772
if (!this._breadcrumbs && !this._tracing) {
73+
this._wasSkipped = true;
6874
return;
6975
}
7076

7177
const clientOptions = setupOnceGetCurrentHub().getClient<NodeClient>()?.getOptions();
7278

7379
// Do not auto-instrument for other instrumenter
7480
if (clientOptions && clientOptions.instrumenter !== 'sentry') {
81+
this._wasSkipped = true;
7582
return;
7683
}
7784

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,26 @@ describe('tracing', () => {
188188
expect(transaction.metadata.propagations).toBe(2);
189189
});
190190

191+
it("doesn't attach when using otel instrumenter", () => {
192+
const options = getDefaultNodeClientOptions({
193+
dsn: 'https://dogsarebadatkeepingsecrets@squirrelchasers.ingest.sentry.io/12312012',
194+
tracesSampleRate: 1.0,
195+
integrations: [new HttpIntegration({ tracing: true })],
196+
release: '1.0.0',
197+
environment: 'production',
198+
instrumenter: 'otel',
199+
});
200+
const hub = new Hub(new NodeClient(options));
201+
202+
const integration = new HttpIntegration() as HttpIntegration & { _wasSkipped: boolean };
203+
integration.setupOnce(
204+
() => {},
205+
() => hub,
206+
);
207+
208+
expect(integration._wasSkipped).toBe(true);
209+
});
210+
191211
describe('tracePropagationTargets option', () => {
192212
beforeEach(() => {
193213
// hacky way of restoring monkey patched functions

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ export class Apollo implements Integration {
2424
*/
2525
public name: string = Apollo.id;
2626

27+
/**
28+
* If the integration was skipped due to internal checks.
29+
*/
30+
public _wasSkipped: boolean = false;
31+
2732
/**
2833
* @inheritDoc
2934
*/
@@ -38,11 +43,13 @@ export class Apollo implements Integration {
3843

3944
if (!pkg) {
4045
__DEBUG_BUILD__ && logger.error('Apollo Integration was unable to require apollo-server-core package.');
46+
this._wasSkipped = true;
4147
return;
4248
}
4349

4450
if (shouldDisableAutoInstrumentation(getCurrentHub)) {
4551
__DEBUG_BUILD__ && logger.log('Apollo Integration is skipped because of instrumenter configuration.');
52+
this._wasSkipped = true;
4653
return;
4754
}
4855

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ export class Express implements Integration {
9090
*/
9191
public name: string = Express.id;
9292

93+
/**
94+
* If the integration was skipped due to internal checks.
95+
*/
96+
public _wasSkipped: boolean = false;
97+
9398
/**
9499
* Express App instance
95100
*/
@@ -110,11 +115,13 @@ export class Express implements Integration {
110115
public setupOnce(_: unknown, getCurrentHub: () => Hub): void {
111116
if (!this._router) {
112117
__DEBUG_BUILD__ && logger.error('ExpressIntegration is missing an Express instance');
118+
this._wasSkipped = true;
113119
return;
114120
}
115121

116122
if (shouldDisableAutoInstrumentation(getCurrentHub)) {
117123
__DEBUG_BUILD__ && logger.log('Express Integration is skipped because of instrumenter configuration.');
124+
this._wasSkipped = true;
118125
return;
119126
}
120127

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ export class GraphQL implements Integration {
1616
*/
1717
public name: string = GraphQL.id;
1818

19+
/**
20+
* If the integration was skipped due to internal checks.
21+
*/
22+
public _wasSkipped: boolean = false;
23+
1924
/**
2025
* @inheritDoc
2126
*/
@@ -26,11 +31,13 @@ export class GraphQL implements Integration {
2631

2732
if (!pkg) {
2833
__DEBUG_BUILD__ && logger.error('GraphQL Integration was unable to require graphql/execution package.');
34+
this._wasSkipped = true;
2935
return;
3036
}
3137

3238
if (shouldDisableAutoInstrumentation(getCurrentHub)) {
3339
__DEBUG_BUILD__ && logger.log('GraphQL Integration is skipped because of instrumenter configuration.');
40+
this._wasSkipped = true;
3441
return;
3542
}
3643

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ export class Mongo implements Integration {
102102
*/
103103
public name: string = Mongo.id;
104104

105+
/**
106+
* If the integration was skipped due to internal checks.
107+
*/
108+
public _wasSkipped: boolean = false;
109+
105110
private _operations: Operation[];
106111
private _describeOperations?: boolean | Operation[];
107112
private _useMongoose: boolean;
@@ -124,11 +129,13 @@ export class Mongo implements Integration {
124129

125130
if (!pkg) {
126131
__DEBUG_BUILD__ && logger.error(`Mongo Integration was unable to require \`${moduleName}\` package.`);
132+
this._wasSkipped = true;
127133
return;
128134
}
129135

130136
if (shouldDisableAutoInstrumentation(getCurrentHub)) {
131137
__DEBUG_BUILD__ && logger.log('Mongo Integration is skipped because of instrumenter configuration.');
138+
this._wasSkipped = true;
132139
return;
133140
}
134141

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ export class Mysql implements Integration {
2020
*/
2121
public name: string = Mysql.id;
2222

23+
/**
24+
* If the integration was skipped due to internal checks.
25+
*/
26+
public _wasSkipped: boolean = false;
27+
2328
/**
2429
* @inheritDoc
2530
*/
@@ -28,11 +33,13 @@ export class Mysql implements Integration {
2833

2934
if (!pkg) {
3035
__DEBUG_BUILD__ && logger.error('Mysql Integration was unable to require `mysql` package.');
36+
this._wasSkipped = true;
3137
return;
3238
}
3339

3440
if (shouldDisableAutoInstrumentation(getCurrentHub)) {
3541
__DEBUG_BUILD__ && logger.log('Mysql Integration is skipped because of instrumenter configuration.');
42+
this._wasSkipped = true;
3643
return;
3744
}
3845

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ export class Postgres implements Integration {
2626
*/
2727
public name: string = Postgres.id;
2828

29+
/**
30+
* If the integration was skipped due to internal checks.
31+
*/
32+
public _wasSkipped: boolean = false;
33+
2934
private _usePgNative: boolean;
3035

3136
public constructor(options: PgOptions = {}) {
@@ -40,11 +45,13 @@ export class Postgres implements Integration {
4045

4146
if (!pkg) {
4247
__DEBUG_BUILD__ && logger.error('Postgres Integration was unable to require `pg` package.');
48+
this._wasSkipped = true;
4349
return;
4450
}
4551

4652
if (shouldDisableAutoInstrumentation(getCurrentHub)) {
4753
__DEBUG_BUILD__ && logger.log('Postgres Integration is skipped because of instrumenter configuration.');
54+
this._wasSkipped = true;
4855
return;
4956
}
5057

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ export class Prisma implements Integration {
5454
*/
5555
public name: string = Prisma.id;
5656

57+
/**
58+
* If the integration was skipped due to internal checks.
59+
*/
60+
public _wasSkipped: boolean = false;
61+
5762
/**
5863
* Prisma ORM Client Instance
5964
*/
@@ -79,11 +84,13 @@ export class Prisma implements Integration {
7984
public setupOnce(_: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {
8085
if (!this._client) {
8186
__DEBUG_BUILD__ && logger.error('PrismaIntegration is missing a Prisma Client Instance');
87+
this._wasSkipped = true;
8288
return;
8389
}
8490

8591
if (shouldDisableAutoInstrumentation(getCurrentHub)) {
8692
__DEBUG_BUILD__ && logger.log('Prisma Integration is skipped because of instrumenter configuration.');
93+
this._wasSkipped = true;
8794
return;
8895
}
8996

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Hub, Scope } from '@sentry/core';
33

44
import { Apollo } from '../../src/integrations/node/apollo';
55
import { Span } from '../../src/span';
6+
import { getTestClient } from '../testutils';
67

78
type ApolloResolverGroup = {
89
[key: string]: () => any;
@@ -100,4 +101,17 @@ describe('setupOnce', () => {
100101
});
101102
expect(childSpan.finish).toBeCalled();
102103
});
104+
105+
it("doesn't attach when using otel instrumenter", () => {
106+
const client = getTestClient({ instrumenter: 'otel' });
107+
const hub = new Hub(client);
108+
109+
const integration = new Apollo() as Apollo & { _wasSkipped: boolean };
110+
integration.setupOnce(
111+
() => {},
112+
() => hub,
113+
);
114+
115+
expect(integration._wasSkipped).toBe(true);
116+
});
103117
});

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Hub, Scope } from '@sentry/core';
33

44
import { GraphQL } from '../../src/integrations/node/graphql';
55
import { Span } from '../../src/span';
6+
import { getTestClient } from '../testutils';
67

78
const GQLExecute = {
89
execute() {
@@ -53,4 +54,17 @@ describe('setupOnce', () => {
5354
expect(childSpan.finish).toBeCalled();
5455
expect(scope.setSpan).toHaveBeenCalledTimes(2);
5556
});
57+
58+
it("doesn't attach when using otel instrumenter", () => {
59+
const client = getTestClient({ instrumenter: 'otel' });
60+
const hub = new Hub(client);
61+
62+
const integration = new GraphQL() as GraphQL & { _wasSkipped: boolean };
63+
integration.setupOnce(
64+
() => {},
65+
() => hub,
66+
);
67+
68+
expect(integration._wasSkipped).toBe(true);
69+
});
5670
});

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Hub, Scope } from '@sentry/core';
33

44
import { Mongo } from '../../../src/integrations/node/mongo';
55
import { Span } from '../../../src/span';
6+
import { getTestClient } from '../../testutils';
67

78
class Collection {
89
public collectionName: string = 'mockedCollectionName';
@@ -111,4 +112,17 @@ describe('patchOperation()', () => {
111112
});
112113
expect(childSpan.finish).toBeCalled();
113114
});
115+
116+
it("doesn't attach when using otel instrumenter", () => {
117+
const client = getTestClient({ instrumenter: 'otel' });
118+
const hub = new Hub(client);
119+
120+
const integration = new Mongo() as Mongo & { _wasSkipped: boolean };
121+
integration.setupOnce(
122+
() => {},
123+
() => hub,
124+
);
125+
126+
expect(integration._wasSkipped).toBe(true);
127+
});
114128
});

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Hub, Scope } from '@sentry/core';
33

44
import { Postgres } from '../../../src/integrations/node/postgres';
55
import { Span } from '../../../src/span';
6+
import { getTestClient } from '../../testutils';
67

78
class PgClient {
89
// https://node-postgres.com/api/client#clientquery
@@ -94,4 +95,17 @@ describe('setupOnce', () => {
9495
expect(childSpan.finish).toBeCalled();
9596
});
9697
});
98+
99+
it("doesn't attach when using otel instrumenter", () => {
100+
const client = getTestClient({ instrumenter: 'otel' });
101+
const hub = new Hub(client);
102+
103+
const integration = new Postgres() as Postgres & { _wasSkipped: boolean };
104+
integration.setupOnce(
105+
() => {},
106+
() => hub,
107+
);
108+
109+
expect(integration._wasSkipped).toBe(true);
110+
});
97111
});

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Hub, Scope } from '@sentry/core';
33

44
import { Prisma } from '../../../src/integrations/node/prisma';
55
import { Span } from '../../../src/span';
6+
import { getTestClient } from '../../testutils';
67

78
type PrismaMiddleware = (params: unknown, next: (params?: unknown) => Promise<unknown>) => Promise<unknown>;
89

@@ -58,4 +59,17 @@ describe('setupOnce', function () {
5859
done();
5960
});
6061
});
62+
63+
it("doesn't attach when using otel instrumenter", () => {
64+
const client = getTestClient({ instrumenter: 'otel' });
65+
const hub = new Hub(client);
66+
67+
const integration = new Prisma() as Prisma & { _wasSkipped: boolean };
68+
integration.setupOnce(
69+
() => {},
70+
() => hub,
71+
);
72+
73+
expect(integration._wasSkipped).toBe(true);
74+
});
6175
});

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)