@@ -17,7 +17,10 @@ function captureFluid(
1717 const attr = obj [ key as keyof PrismaPromise < any > ] ;
1818 const actionKey = key . toString ( ) ;
1919
20- if ( ! prismaPromiseAttributes . has ( actionKey ) && typeof attr === 'function' )
20+ if (
21+ ! prismaPromiseAttributes . has ( actionKey ) &&
22+ typeof attr === 'function'
23+ ) {
2124 return ( ...args : any [ ] ) => {
2225 const res = attr . bind ( obj ) ( ...args ) ;
2326 const isPromise = isPrismaPromise ( res ) ;
@@ -48,6 +51,7 @@ function captureFluid(
4851 }
4952 return res ;
5053 } ;
54+ }
5155 callback ?.( ) ;
5256
5357 return attr ;
@@ -74,16 +78,20 @@ function captureActions(
7478) {
7579 return ( ...args : any [ ] ) : any => {
7680 let segment = baseSegment ;
77- let lastArg : Subsegment | null = args [ args . length - 1 ] ;
81+ const lastArg : Subsegment | null = args [ args . length - 1 ] ;
7882
79- if ( AWSXRay . isAutomaticMode ( ) ) segment = AWSXRay . getSegment ( ) ;
83+ if ( AWSXRay . isAutomaticMode ( ) ) {
84+ segment = AWSXRay . getSegment ( ) ;
85+ }
8086 if ( lastArg instanceof Segment || lastArg instanceof Subsegment ) {
8187 args = args . slice ( 0 , - 1 ) ;
8288 segment = lastArg ;
8389 }
8490
8591 const call = ( ) => attr . bind ( obj ) ( ...args ) ;
86- if ( ! segment ) return call ( ) ;
92+ if ( ! segment ) {
93+ return call ( ) ;
94+ }
8795
8896 const model = [ modelPrefix , modelKey ] . filter ( Boolean ) . join ( divider ) ;
8997 const actionSegment = segment . addNewSubsegment (
@@ -97,13 +105,9 @@ function captureActions(
97105 res . catch ( e => {
98106 actionSegment . addError ( e ) ;
99107 } ) ;
100- res . finally ( ( ) => {
101- actionSegment . close ( ) ;
102- } ) ;
103108 promises . push ( res ) ;
104- } else {
105- actionSegment . close ( ) ;
106109 }
110+
107111 const close = async ( ) => {
108112 if ( promises . length ) {
109113 for ( const promise of promises ) {
@@ -112,8 +116,9 @@ function captureActions(
112116 } ) ;
113117 }
114118 }
115- segment ?. close ( ) ;
119+ actionSegment ?. close ( ) ;
116120 } ;
121+
117122 if ( isPromise ) {
118123 const promiseFluid = captureFluid ( res , {
119124 callback : promise => {
@@ -138,14 +143,22 @@ function captureModels(
138143 modelKey : string ,
139144 { segment, ...rest } : CommonOpts
140145) {
141- if ( AWSXRay . isAutomaticMode ( ) ) segment = AWSXRay . resolveSegment ( segment ) ;
146+ if ( AWSXRay . isAutomaticMode ( ) ) {
147+ segment = AWSXRay . resolveSegment ( segment ) ;
148+ }
149+
150+ if ( ! attr || attr instanceof Function ) {
151+ return attr ;
152+ }
142153
143154 return new Proxy ( attr , {
144155 get ( obj , prop ) {
145156 const key = prop . toString ( ) ;
146157 const attr = obj [ key ] ;
147158 if ( isAction ( key ) ) {
148- if ( AWSXRay . isAutomaticMode ( ) && segment ) AWSXRay . setSegment ( segment ) ;
159+ if ( AWSXRay . isAutomaticMode ( ) && segment ) {
160+ AWSXRay . setSegment ( segment ) ;
161+ }
149162
150163 return captureActions ( attr , obj , {
151164 segment,
@@ -171,16 +184,22 @@ export function capturePrisma<T extends PrismaClient>(
171184 } catch {
172185 // ignore
173186 }
174- } else segment = baseSegment ;
187+ } else {
188+ segment = baseSegment ;
189+ }
175190 if ( AWSXRay . isAutomaticMode ( ) ) {
176191 const ns = AWSXRay . getNamespace ( ) ;
177192 return ns . runAndReturn ( ( ) => {
178- if ( segment ) AWSXRay . setSegment ( segment ) ;
193+ if ( segment ) {
194+ AWSXRay . setSegment ( segment ) ;
195+ }
179196 return new Proxy ( prisma , {
180197 get ( obj , modelKey ) : any {
181198 const attr = obj [ modelKey as keyof T ] ;
182199 return ns . runAndReturn ( ( ) => {
183- if ( segment ) AWSXRay . setSegment ( segment ) ;
200+ if ( segment ) {
201+ AWSXRay . setSegment ( segment ) ;
202+ }
184203 return captureModels ( attr , modelKey . toString ( ) , {
185204 segment,
186205 ...rest ,
0 commit comments