1
+ import { isWrapped } from '@opentelemetry/core' ;
2
+ import type { InstrumentationConfig } from '@opentelemetry/instrumentation' ;
3
+ import {
4
+ InstrumentationBase ,
5
+ InstrumentationNodeModuleDefinition ,
6
+ InstrumentationNodeModuleFile ,
7
+ } from '@opentelemetry/instrumentation' ;
1
8
import { NestInstrumentation } from '@opentelemetry/instrumentation-nestjs-core' ;
2
9
import {
3
10
SEMANTIC_ATTRIBUTE_SENTRY_OP ,
@@ -12,12 +19,6 @@ import {
12
19
import type { IntegrationFn , Span } from '@sentry/types' ;
13
20
import { logger } from '@sentry/utils' ;
14
21
import { generateInstrumentOnce } from '../../otel/instrument' ;
15
- import type { InstrumentationConfig } from '@opentelemetry/instrumentation' ;
16
- import {
17
- InstrumentationBase ,
18
- InstrumentationNodeModuleDefinition , InstrumentationNodeModuleFile
19
- } from '@opentelemetry/instrumentation' ;
20
- import { isWrapped } from '@opentelemetry/core' ;
21
22
22
23
interface MinimalNestJsExecutionContext {
23
24
getType : ( ) => string ;
@@ -68,23 +69,17 @@ export class SentryNestInstrumentation extends InstrumentationBase {
68
69
/**
69
70
*
70
71
*/
71
- public init ( ) : void {
72
- logger . log ( 'init!' ) ;
73
- const module = new InstrumentationNodeModuleDefinition (
74
- SentryNestInstrumentation . COMPONENT ,
75
- supportedVersions
76
- )
77
-
78
- module . files . push (
79
- this . _getInjectableFileInstrumentation ( supportedVersions )
80
- )
72
+ public init ( ) : InstrumentationNodeModuleDefinition {
73
+ const moduleDef = new InstrumentationNodeModuleDefinition ( SentryNestInstrumentation . COMPONENT , supportedVersions ) ;
74
+
75
+ moduleDef . files . push ( this . _getInjectableFileInstrumentation ( supportedVersions ) ) ;
76
+ return moduleDef ;
81
77
}
82
78
83
79
/**
84
80
*
85
81
*/
86
82
private _getInjectableFileInstrumentation ( versions : string [ ] ) : InstrumentationNodeModuleFile {
87
- logger . log ( 'create instrumentation node module file' ) ;
88
83
return new InstrumentationNodeModuleFile (
89
84
'@nestjs/common/decorators/core/injectable.decorator.js' ,
90
85
versions ,
@@ -98,8 +93,8 @@ export class SentryNestInstrumentation extends InstrumentationBase {
98
93
} ,
99
94
( moduleExports : any ) => {
100
95
this . _unwrap ( moduleExports , 'Injectable' ) ;
101
- }
102
- )
96
+ } ,
97
+ ) ;
103
98
}
104
99
105
100
/**
@@ -109,11 +104,18 @@ export class SentryNestInstrumentation extends InstrumentationBase {
109
104
return function wrapInjectable ( original : any ) {
110
105
return function wrappedInjectable ( options ?: any ) {
111
106
return function ( target : any ) {
112
- logger . log ( 'Injectable target:' , target ) ;
113
-
107
+ // TODO: Check if the class was already patched à la
108
+ // if (target[sentryPatchedSymbol]) {
109
+ // return original(options)(target);
110
+ // } else {
111
+ // addNonEnumerableProperty(target, sentryPatchedSymbol, true);
112
+ // }
113
+
114
+ // TODO: proper typing
114
115
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
115
116
if ( typeof target . prototype . use === 'function' ) {
116
- logger . log ( 'middleware!' ) ;
117
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, no-console
118
+ console . log ( 'middleware!' ) ;
117
119
}
118
120
119
121
return original ( options ) ( target ) ;
@@ -124,12 +126,10 @@ export class SentryNestInstrumentation extends InstrumentationBase {
124
126
}
125
127
126
128
const instrumentNestCore = generateInstrumentOnce ( 'Nest-Core' , ( ) => {
127
- logger . log ( 'init nest core instrumentation' ) ;
128
129
return new NestInstrumentation ( ) ;
129
130
} ) ;
130
131
131
132
const instrumentMiddleware = generateInstrumentOnce ( 'Nest-Middleware' , ( ) => {
132
- logger . log ( 'init nest middleware instrumentation' ) ;
133
133
return new SentryNestInstrumentation ( ) ;
134
134
} ) ;
135
135
0 commit comments