Skip to content

Commit 5ed0a41

Browse files
nicohrubecclaude
andcommitted
fix(server-utils): Match firestore lite across firebase build layouts
firebase >=12.8 (firestore >=4.10) moved addDoc/getDocs/setDoc/deleteDoc into a hash-named shared chunk, so orchestrion's exact-path filePath match no longer hit them and no firestore spans were emitted. Use a RegExp filePath matching both the old `index.node.*` and new `common-<hash>.node.*` chunks. Also align the functions span op assertion with `function.firebase`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 785badf commit 5ed0a41

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

packages/server-utils/src/orchestrion/config/firebase.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ import type { InstrumentationConfig } from '..';
22

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
5-
// 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`.
5+
// `node` entry points (CJS `require`, ESM `import`) are reachable from `@sentry/node`; the
6+
// browser/react-native builds are irrelevant here. `addDoc` & co. are top-level `function <name>`
7+
// declarations, so `functionName` matches; they return promises, so `Auto` settles the span on
8+
// `asyncEnd`. firebase <12.8 declares them in `index.node.{cjs.js,mjs}`; firebase >=12.8 (firestore
9+
// >=4.10) moved them into a hash-named shared chunk `common-<hash>.node.{cjs.js,mjs}` — the RegExp
10+
// matches both, so injection keeps working across the version range without pinning a build hash.
811
const FIRESTORE_VERSION_RANGE = '>=3.0.0 <5';
9-
const FIRESTORE_FILES = ['dist/lite/index.node.cjs.js', 'dist/lite/index.node.mjs'];
12+
const FIRESTORE_FILE = /dist\/lite\/(index|common-[^/]+)\.node\.(cjs\.js|mjs)$/;
1013
const FIRESTORE_OPERATIONS = [
1114
{ functionName: 'addDoc', channelName: 'add-doc' },
1215
{ functionName: 'getDocs', channelName: 'get-docs' },
@@ -58,13 +61,11 @@ const FUNCTIONS_TRIGGERS = [
5861
] as const;
5962

6063
export const firebaseConfig = [
61-
...FIRESTORE_FILES.flatMap(filePath =>
62-
FIRESTORE_OPERATIONS.map(({ functionName, channelName }) => ({
63-
channelName,
64-
module: { name: '@firebase/firestore', versionRange: FIRESTORE_VERSION_RANGE, filePath },
65-
functionQuery: { functionName, kind: 'Auto' as const },
66-
})),
67-
),
64+
...FIRESTORE_OPERATIONS.map(({ functionName, channelName }) => ({
65+
channelName,
66+
module: { name: '@firebase/firestore', versionRange: FIRESTORE_VERSION_RANGE, filePath: FIRESTORE_FILE },
67+
functionQuery: { functionName, kind: 'Auto' as const },
68+
})),
6869
...FUNCTIONS_TRIGGERS.map(({ file, functionName, channelName }) => ({
6970
channelName,
7071
module: { name: 'firebase-functions', versionRange: FUNCTIONS_VERSION_RANGE, filePath: file },

packages/server-utils/test/orchestrion/firebase.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ describe('firebaseChannelIntegration', () => {
232232
expect(startSpanManualSpy).toHaveBeenCalledWith(
233233
expect.objectContaining({
234234
name: 'firebase.function.http.request',
235-
op: 'http.request',
235+
op: 'function.firebase',
236236
attributes: expect.objectContaining({
237237
'sentry.origin': 'auto.firebase.orchestrion.functions',
238238
'faas.trigger': 'http.request',

0 commit comments

Comments
 (0)