@@ -66,42 +66,24 @@ export function patchFunctions(
6666 }
6767
6868 const moduleFunctionsCJS = new InstrumentationNodeModuleDefinition ( 'firebase-functions' , functionsSupportedVersions ) ;
69-
70- moduleFunctionsCJS . files . push (
71- new InstrumentationNodeModuleFile (
72- 'firebase-functions/lib/v2/providers/https.js' ,
73- functionsSupportedVersions ,
74- moduleExports => wrapCommonFunctions ( moduleExports , wrap , unwrap , tracer , functionsSpanCreationHook , 'function' ) ,
75- moduleExports => unwrapCommonFunctions ( moduleExports , unwrap ) ,
76- ) ,
77- ) ;
78-
79- moduleFunctionsCJS . files . push (
80- new InstrumentationNodeModuleFile (
81- 'firebase-functions/lib/v2/providers/firestore.js' ,
82- functionsSupportedVersions ,
83- moduleExports => wrapCommonFunctions ( moduleExports , wrap , unwrap , tracer , functionsSpanCreationHook , 'firestore' ) ,
84- moduleExports => unwrapCommonFunctions ( moduleExports , unwrap ) ,
85- ) ,
86- ) ;
87-
88- moduleFunctionsCJS . files . push (
89- new InstrumentationNodeModuleFile (
90- 'firebase-functions/lib/v2/providers/scheduler.js' ,
91- functionsSupportedVersions ,
92- moduleExports => wrapCommonFunctions ( moduleExports , wrap , unwrap , tracer , functionsSpanCreationHook , 'scheduler' ) ,
93- moduleExports => unwrapCommonFunctions ( moduleExports , unwrap ) ,
94- ) ,
95- ) ;
96-
97- moduleFunctionsCJS . files . push (
98- new InstrumentationNodeModuleFile (
99- 'firebase-functions/lib/v2/storage.js' ,
100- functionsSupportedVersions ,
101- moduleExports => wrapCommonFunctions ( moduleExports , wrap , unwrap , tracer , functionsSpanCreationHook , 'storage' ) ,
102- moduleExports => unwrapCommonFunctions ( moduleExports , unwrap ) ,
103- ) ,
104- ) ;
69+ const modulesToInstrument = [
70+ { name : 'firebase-functions/lib/v2/providers/https.js' , triggerType : 'function' } ,
71+ { name : 'firebase-functions/lib/v2/providers/firestore.js' , triggerType : 'firestore' } ,
72+ { name : 'firebase-functions/lib/v2/providers/scheduler.js' , triggerType : 'scheduler' } ,
73+ { name : 'firebase-functions/lib/v2/storage.js' , triggerType : 'storage' } ,
74+ ] as const ;
75+
76+ modulesToInstrument . forEach ( ( { name, triggerType } ) => {
77+ moduleFunctionsCJS . files . push (
78+ new InstrumentationNodeModuleFile (
79+ name ,
80+ functionsSupportedVersions ,
81+ moduleExports =>
82+ wrapCommonFunctions ( moduleExports , wrap , unwrap , tracer , functionsSpanCreationHook , triggerType ) ,
83+ moduleExports => unwrapCommonFunctions ( moduleExports , unwrap ) ,
84+ ) ,
85+ ) ;
86+ } ) ;
10587
10688 return moduleFunctionsCJS ;
10789}
@@ -190,7 +172,7 @@ export function patchV2Functions<T extends FirebaseFunctions = FirebaseFunctions
190172 safeExecuteInTheMiddleAsync (
191173 ( ) => handler . apply ( this , handlerArgs ) ,
192174 err => {
193- if ( err instanceof Error ) {
175+ if ( err ) {
194176 span . recordException ( err ) ;
195177 }
196178
0 commit comments