Skip to content

Commit f3c5ca3

Browse files
committed
Simplify patch logic
1 parent a2bf706 commit f3c5ca3

File tree

1 file changed

+8
-9
lines changed
  • packages/node/src/integrations/tracing/firebase/otel/patches

1 file changed

+8
-9
lines changed

packages/node/src/integrations/tracing/firebase/otel/patches/firestore.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ export function patchFirestore(
5050
unwrap: typeof shimmerUnwrap,
5151
config: FirebaseInstrumentationConfig,
5252
): InstrumentationNodeModuleDefinition {
53-
// Setting an empty function as a default
5453
// eslint-disable-next-line @typescript-eslint/no-empty-function
55-
let firestoreSpanCreationHook: FirestoreSpanCreationHook = () => {};
54+
const defaultFirestoreSpanCreationHook: FirestoreSpanCreationHook = () => {};
55+
56+
let firestoreSpanCreationHook: FirestoreSpanCreationHook = defaultFirestoreSpanCreationHook;
5657
const configFirestoreSpanCreationHook = config.firestoreSpanCreationHook;
5758

5859
if (typeof configFirestoreSpanCreationHook === 'function') {
@@ -63,7 +64,7 @@ export function patchFirestore(
6364
if (!error) {
6465
return;
6566
}
66-
diag.error('Firebase Firestore span creation hook failed', error?.message);
67+
diag.error(error?.message);
6768
},
6869
true,
6970
);
@@ -151,14 +152,12 @@ function patchAddDoc<AppModelType, DbModelType extends DocumentData>(
151152
data: WithFieldValue<AppModelType>,
152153
) => Promise<DocumentReference<AppModelType, DbModelType>> {
153154
return function addDoc(original: AddDocType<AppModelType, DbModelType>) {
154-
return function patchAddDoc(
155+
return function (
155156
reference: CollectionReference<AppModelType, DbModelType>,
156157
data: WithFieldValue<AppModelType>,
157158
): Promise<DocumentReference<AppModelType, DbModelType>> {
158159
const span = startDBSpan(tracer, 'addDoc', reference);
159-
160160
firestoreSpanCreationHook(span);
161-
162161
return executeContextWithSpan<Promise<DocumentReference<AppModelType, DbModelType>>>(span, () => {
163162
return original(reference, data);
164163
});
@@ -173,7 +172,7 @@ function patchDeleteDoc<AppModelType, DbModelType extends DocumentData>(
173172
original: DeleteDocType<AppModelType, DbModelType>,
174173
) => (this: FirebaseInstrumentation, reference: DocumentReference<AppModelType, DbModelType>) => Promise<void> {
175174
return function deleteDoc(original: DeleteDocType<AppModelType, DbModelType>) {
176-
return function patchDeleteDoc(reference: DocumentReference<AppModelType, DbModelType>): Promise<void> {
175+
return function (reference: DocumentReference<AppModelType, DbModelType>): Promise<void> {
177176
const span = startDBSpan(tracer, 'deleteDoc', reference.parent || reference);
178177
firestoreSpanCreationHook(span);
179178
return executeContextWithSpan<Promise<void>>(span, () => {
@@ -193,7 +192,7 @@ function patchGetDocs<AppModelType, DbModelType extends DocumentData>(
193192
reference: CollectionReference<AppModelType, DbModelType>,
194193
) => Promise<QuerySnapshot<AppModelType, DbModelType>> {
195194
return function getDocs(original: GetDocsType<AppModelType, DbModelType>) {
196-
return function patchGetDocs(
195+
return function (
197196
reference: CollectionReference<AppModelType, DbModelType>,
198197
): Promise<QuerySnapshot<AppModelType, DbModelType>> {
199198
const span = startDBSpan(tracer, 'getDocs', reference);
@@ -217,7 +216,7 @@ function patchSetDoc<AppModelType, DbModelType extends DocumentData>(
217216
options?: SetOptions,
218217
) => Promise<void> {
219218
return function setDoc(original: SetDocType<AppModelType, DbModelType>) {
220-
return function patchSetDoc(
219+
return function (
221220
reference: DocumentReference<AppModelType, DbModelType>,
222221
data: WithFieldValue<AppModelType> & PartialWithFieldValue<AppModelType>,
223222
options?: SetOptions,

0 commit comments

Comments
 (0)