@@ -3,16 +3,23 @@ import type { InstrumentationConfig } from '@apm-js-collab/code-transformer';
33// firebase 9+ ships firestore as `@firebase/firestore` (matches the OTel integration's range). Only the
44// `lite` SDK exposes the free `addDoc`/`getDocs`/`setDoc`/`deleteDoc` functions we trace, and only the
55// two `node` entry points (CJS `require`, ESM `import`) are reachable from `@sentry/node`; the
6- // browser/react-native builds are irrelevant here. Each is a top-level `function <name>` declaration, so
7- // `functionName` matches. They return promises, so `Auto` settles the span on `asyncEnd`.
8- const FIRESTORE_VERSION_RANGE = '>=3.0.0 <5' ;
9- const FIRESTORE_FILES = [ 'dist/lite/index.node.cjs.js' , 'dist/lite/index.node.mjs' ] ;
6+ // browser/react-native builds are irrelevant here. They return promises, so `Auto` settles the span on
7+ // `asyncEnd`.
8+ //
9+ // Where those declarations live moves with the firestore version, so we register two disjoint ranges
10+ // below. Up to 4.10 they are top-level `function <name>` declarations in the `node` entry files. From 4.10
11+ // the lite build code-splits them into a single content-hashed shared chunk (`common-<hash>.node.*`) and
12+ // leaves the entry files re-export-only, so we match the chunk by a regex on its hashed name. The ranges
13+ // must not overlap: matching the re-export-only entry file would make orchestrion throw "failed to find
14+ // injection points". Regex `filePath` matching requires the code-transformer (orchestrion) >=0.17.0.
1015const FIRESTORE_OPERATIONS = [
1116 { functionName : 'addDoc' , channelName : 'add-doc' } ,
1217 { functionName : 'getDocs' , channelName : 'get-docs' } ,
1318 { functionName : 'setDoc' , channelName : 'set-doc' } ,
1419 { functionName : 'deleteDoc' , channelName : 'delete-doc' } ,
1520] as const ;
21+ const FIRESTORE_ENTRY_FILES = [ 'dist/lite/index.node.cjs.js' , 'dist/lite/index.node.mjs' ] ;
22+ const FIRESTORE_CHUNK_FILES = [ / ^ d i s t \/ l i t e \/ c o m m o n - [ ^ / ] + \. n o d e \. c j s \. j s $ / , / ^ d i s t \/ l i t e \/ c o m m o n - [ ^ / ] + \. n o d e \. m j s $ / ] ;
1623
1724// firebase-functions v2 (CJS-only). The `onX` provider functions *register* a handler and return a
1825// synchronous cloud function, so `Sync` is required — the span itself is opened later, when the handler
@@ -58,10 +65,19 @@ const FUNCTIONS_TRIGGERS = [
5865] as const ;
5966
6067export const firebaseConfig = [
61- ...FIRESTORE_FILES . flatMap ( filePath =>
68+ // v3.0.0 - v4.10.0
69+ ...FIRESTORE_ENTRY_FILES . flatMap ( filePath =>
6270 FIRESTORE_OPERATIONS . map ( ( { functionName, channelName } ) => ( {
6371 channelName,
64- module : { name : '@firebase/firestore' , versionRange : FIRESTORE_VERSION_RANGE , filePath } ,
72+ module : { name : '@firebase/firestore' , versionRange : '>=3.0.0 <4.10.0' , filePath } ,
73+ functionQuery : { functionName, kind : 'Auto' as const } ,
74+ } ) ) ,
75+ ) ,
76+ // v4.10.0 - v5
77+ ...FIRESTORE_CHUNK_FILES . flatMap ( filePath =>
78+ FIRESTORE_OPERATIONS . map ( ( { functionName, channelName } ) => ( {
79+ channelName,
80+ module : { name : '@firebase/firestore' , versionRange : '>=4.10.0 <5' , filePath } ,
6581 functionQuery : { functionName, kind : 'Auto' as const } ,
6682 } ) ) ,
6783 ) ,
0 commit comments