File tree Expand file tree Collapse file tree 15 files changed +163
-1
lines changed Expand file tree Collapse file tree 15 files changed +163
-1
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,11 @@ export class Http implements Integration {
38
38
*/
39
39
public name : string = Http . id ;
40
40
41
+ /**
42
+ * If the integration was skipped due to internal checks.
43
+ */
44
+ public _wasSkipped : boolean = false ;
45
+
41
46
/**
42
47
* @inheritDoc
43
48
*/
@@ -65,13 +70,15 @@ export class Http implements Integration {
65
70
) : void {
66
71
// No need to instrument if we don't want to track anything
67
72
if ( ! this . _breadcrumbs && ! this . _tracing ) {
73
+ this . _wasSkipped = true ;
68
74
return ;
69
75
}
70
76
71
77
const clientOptions = setupOnceGetCurrentHub ( ) . getClient < NodeClient > ( ) ?. getOptions ( ) ;
72
78
73
79
// Do not auto-instrument for other instrumenter
74
80
if ( clientOptions && clientOptions . instrumenter !== 'sentry' ) {
81
+ this . _wasSkipped = true ;
75
82
return ;
76
83
}
77
84
Original file line number Diff line number Diff line change @@ -188,6 +188,26 @@ describe('tracing', () => {
188
188
expect ( transaction . metadata . propagations ) . toBe ( 2 ) ;
189
189
} ) ;
190
190
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
+
191
211
describe ( 'tracePropagationTargets option' , ( ) => {
192
212
beforeEach ( ( ) => {
193
213
// hacky way of restoring monkey patched functions
Original file line number Diff line number Diff line change @@ -24,6 +24,11 @@ export class Apollo implements Integration {
24
24
*/
25
25
public name : string = Apollo . id ;
26
26
27
+ /**
28
+ * If the integration was skipped due to internal checks.
29
+ */
30
+ public _wasSkipped : boolean = false ;
31
+
27
32
/**
28
33
* @inheritDoc
29
34
*/
@@ -38,11 +43,13 @@ export class Apollo implements Integration {
38
43
39
44
if ( ! pkg ) {
40
45
__DEBUG_BUILD__ && logger . error ( 'Apollo Integration was unable to require apollo-server-core package.' ) ;
46
+ this . _wasSkipped = true ;
41
47
return ;
42
48
}
43
49
44
50
if ( shouldDisableAutoInstrumentation ( getCurrentHub ) ) {
45
51
__DEBUG_BUILD__ && logger . log ( 'Apollo Integration is skipped because of instrumenter configuration.' ) ;
52
+ this . _wasSkipped = true ;
46
53
return ;
47
54
}
48
55
Original file line number Diff line number Diff line change @@ -90,6 +90,11 @@ export class Express implements Integration {
90
90
*/
91
91
public name : string = Express . id ;
92
92
93
+ /**
94
+ * If the integration was skipped due to internal checks.
95
+ */
96
+ public _wasSkipped : boolean = false ;
97
+
93
98
/**
94
99
* Express App instance
95
100
*/
@@ -110,11 +115,13 @@ export class Express implements Integration {
110
115
public setupOnce ( _ : unknown , getCurrentHub : ( ) => Hub ) : void {
111
116
if ( ! this . _router ) {
112
117
__DEBUG_BUILD__ && logger . error ( 'ExpressIntegration is missing an Express instance' ) ;
118
+ this . _wasSkipped = true ;
113
119
return ;
114
120
}
115
121
116
122
if ( shouldDisableAutoInstrumentation ( getCurrentHub ) ) {
117
123
__DEBUG_BUILD__ && logger . log ( 'Express Integration is skipped because of instrumenter configuration.' ) ;
124
+ this . _wasSkipped = true ;
118
125
return ;
119
126
}
120
127
Original file line number Diff line number Diff line change @@ -16,6 +16,11 @@ export class GraphQL implements Integration {
16
16
*/
17
17
public name : string = GraphQL . id ;
18
18
19
+ /**
20
+ * If the integration was skipped due to internal checks.
21
+ */
22
+ public _wasSkipped : boolean = false ;
23
+
19
24
/**
20
25
* @inheritDoc
21
26
*/
@@ -26,11 +31,13 @@ export class GraphQL implements Integration {
26
31
27
32
if ( ! pkg ) {
28
33
__DEBUG_BUILD__ && logger . error ( 'GraphQL Integration was unable to require graphql/execution package.' ) ;
34
+ this . _wasSkipped = true ;
29
35
return ;
30
36
}
31
37
32
38
if ( shouldDisableAutoInstrumentation ( getCurrentHub ) ) {
33
39
__DEBUG_BUILD__ && logger . log ( 'GraphQL Integration is skipped because of instrumenter configuration.' ) ;
40
+ this . _wasSkipped = true ;
34
41
return ;
35
42
}
36
43
Original file line number Diff line number Diff line change @@ -102,6 +102,11 @@ export class Mongo implements Integration {
102
102
*/
103
103
public name : string = Mongo . id ;
104
104
105
+ /**
106
+ * If the integration was skipped due to internal checks.
107
+ */
108
+ public _wasSkipped : boolean = false ;
109
+
105
110
private _operations : Operation [ ] ;
106
111
private _describeOperations ?: boolean | Operation [ ] ;
107
112
private _useMongoose : boolean ;
@@ -124,11 +129,13 @@ export class Mongo implements Integration {
124
129
125
130
if ( ! pkg ) {
126
131
__DEBUG_BUILD__ && logger . error ( `Mongo Integration was unable to require \`${ moduleName } \` package.` ) ;
132
+ this . _wasSkipped = true ;
127
133
return ;
128
134
}
129
135
130
136
if ( shouldDisableAutoInstrumentation ( getCurrentHub ) ) {
131
137
__DEBUG_BUILD__ && logger . log ( 'Mongo Integration is skipped because of instrumenter configuration.' ) ;
138
+ this . _wasSkipped = true ;
132
139
return ;
133
140
}
134
141
Original file line number Diff line number Diff line change @@ -20,6 +20,11 @@ export class Mysql implements Integration {
20
20
*/
21
21
public name : string = Mysql . id ;
22
22
23
+ /**
24
+ * If the integration was skipped due to internal checks.
25
+ */
26
+ public _wasSkipped : boolean = false ;
27
+
23
28
/**
24
29
* @inheritDoc
25
30
*/
@@ -28,11 +33,13 @@ export class Mysql implements Integration {
28
33
29
34
if ( ! pkg ) {
30
35
__DEBUG_BUILD__ && logger . error ( 'Mysql Integration was unable to require `mysql` package.' ) ;
36
+ this . _wasSkipped = true ;
31
37
return ;
32
38
}
33
39
34
40
if ( shouldDisableAutoInstrumentation ( getCurrentHub ) ) {
35
41
__DEBUG_BUILD__ && logger . log ( 'Mysql Integration is skipped because of instrumenter configuration.' ) ;
42
+ this . _wasSkipped = true ;
36
43
return ;
37
44
}
38
45
Original file line number Diff line number Diff line change @@ -26,6 +26,11 @@ export class Postgres implements Integration {
26
26
*/
27
27
public name : string = Postgres . id ;
28
28
29
+ /**
30
+ * If the integration was skipped due to internal checks.
31
+ */
32
+ public _wasSkipped : boolean = false ;
33
+
29
34
private _usePgNative : boolean ;
30
35
31
36
public constructor ( options : PgOptions = { } ) {
@@ -40,11 +45,13 @@ export class Postgres implements Integration {
40
45
41
46
if ( ! pkg ) {
42
47
__DEBUG_BUILD__ && logger . error ( 'Postgres Integration was unable to require `pg` package.' ) ;
48
+ this . _wasSkipped = true ;
43
49
return ;
44
50
}
45
51
46
52
if ( shouldDisableAutoInstrumentation ( getCurrentHub ) ) {
47
53
__DEBUG_BUILD__ && logger . log ( 'Postgres Integration is skipped because of instrumenter configuration.' ) ;
54
+ this . _wasSkipped = true ;
48
55
return ;
49
56
}
50
57
Original file line number Diff line number Diff line change @@ -54,6 +54,11 @@ export class Prisma implements Integration {
54
54
*/
55
55
public name : string = Prisma . id ;
56
56
57
+ /**
58
+ * If the integration was skipped due to internal checks.
59
+ */
60
+ public _wasSkipped : boolean = false ;
61
+
57
62
/**
58
63
* Prisma ORM Client Instance
59
64
*/
@@ -79,11 +84,13 @@ export class Prisma implements Integration {
79
84
public setupOnce ( _ : ( callback : EventProcessor ) => void , getCurrentHub : ( ) => Hub ) : void {
80
85
if ( ! this . _client ) {
81
86
__DEBUG_BUILD__ && logger . error ( 'PrismaIntegration is missing a Prisma Client Instance' ) ;
87
+ this . _wasSkipped = true ;
82
88
return ;
83
89
}
84
90
85
91
if ( shouldDisableAutoInstrumentation ( getCurrentHub ) ) {
86
92
__DEBUG_BUILD__ && logger . log ( 'Prisma Integration is skipped because of instrumenter configuration.' ) ;
93
+ this . _wasSkipped = true ;
87
94
return ;
88
95
}
89
96
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { Hub, Scope } from '@sentry/core';
3
3
4
4
import { Apollo } from '../../src/integrations/node/apollo' ;
5
5
import { Span } from '../../src/span' ;
6
+ import { getTestClient } from '../testutils' ;
6
7
7
8
type ApolloResolverGroup = {
8
9
[ key : string ] : ( ) => any ;
@@ -100,4 +101,17 @@ describe('setupOnce', () => {
100
101
} ) ;
101
102
expect ( childSpan . finish ) . toBeCalled ( ) ;
102
103
} ) ;
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
+ } ) ;
103
117
} ) ;
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { Hub, Scope } from '@sentry/core';
3
3
4
4
import { GraphQL } from '../../src/integrations/node/graphql' ;
5
5
import { Span } from '../../src/span' ;
6
+ import { getTestClient } from '../testutils' ;
6
7
7
8
const GQLExecute = {
8
9
execute ( ) {
@@ -53,4 +54,17 @@ describe('setupOnce', () => {
53
54
expect ( childSpan . finish ) . toBeCalled ( ) ;
54
55
expect ( scope . setSpan ) . toHaveBeenCalledTimes ( 2 ) ;
55
56
} ) ;
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
+ } ) ;
56
70
} ) ;
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { Hub, Scope } from '@sentry/core';
3
3
4
4
import { Mongo } from '../../../src/integrations/node/mongo' ;
5
5
import { Span } from '../../../src/span' ;
6
+ import { getTestClient } from '../../testutils' ;
6
7
7
8
class Collection {
8
9
public collectionName : string = 'mockedCollectionName' ;
@@ -111,4 +112,17 @@ describe('patchOperation()', () => {
111
112
} ) ;
112
113
expect ( childSpan . finish ) . toBeCalled ( ) ;
113
114
} ) ;
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
+ } ) ;
114
128
} ) ;
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { Hub, Scope } from '@sentry/core';
3
3
4
4
import { Postgres } from '../../../src/integrations/node/postgres' ;
5
5
import { Span } from '../../../src/span' ;
6
+ import { getTestClient } from '../../testutils' ;
6
7
7
8
class PgClient {
8
9
// https://node-postgres.com/api/client#clientquery
@@ -94,4 +95,17 @@ describe('setupOnce', () => {
94
95
expect ( childSpan . finish ) . toBeCalled ( ) ;
95
96
} ) ;
96
97
} ) ;
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
+ } ) ;
97
111
} ) ;
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { Hub, Scope } from '@sentry/core';
3
3
4
4
import { Prisma } from '../../../src/integrations/node/prisma' ;
5
5
import { Span } from '../../../src/span' ;
6
+ import { getTestClient } from '../../testutils' ;
6
7
7
8
type PrismaMiddleware = ( params : unknown , next : ( params ?: unknown ) => Promise < unknown > ) => Promise < unknown > ;
8
9
@@ -58,4 +59,17 @@ describe('setupOnce', function () {
58
59
done ( ) ;
59
60
} ) ;
60
61
} ) ;
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
+ } ) ;
61
75
} ) ;
Original file line number Diff line number Diff line change 1
1
import { createTransport } from '@sentry/browser' ;
2
- import { ClientOptions } from '@sentry/types' ;
2
+ import { Client , ClientOptions } from '@sentry/types' ;
3
3
import { GLOBAL_OBJ , resolvedSyncPromise } from '@sentry/utils' ;
4
4
import { JSDOM } from 'jsdom' ;
5
5
@@ -66,3 +66,19 @@ export function getDefaultBrowserClientOptions(options: Partial<ClientOptions> =
66
66
...options ,
67
67
} ;
68
68
}
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
+ }
You can’t perform that action at this time.
0 commit comments