From 019a23c7ac5de92f4b2a97abd087f21fffbd81a4 Mon Sep 17 00:00:00 2001 From: Adam Horodyski Date: Wed, 16 Oct 2024 12:26:57 +0200 Subject: [PATCH 1/6] feat: add transactionViolationsLength to the attributes list --- src/libs/Firebase/index.native.ts | 3 +++ src/libs/Firebase/types.ts | 1 + src/libs/actions/Transaction.ts | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/src/libs/Firebase/index.native.ts b/src/libs/Firebase/index.native.ts index 0af52eefb58c..28fac163561e 100644 --- a/src/libs/Firebase/index.native.ts +++ b/src/libs/Firebase/index.native.ts @@ -1,6 +1,7 @@ /* eslint-disable no-unused-vars */ import crashlytics from '@react-native-firebase/crashlytics'; import perf from '@react-native-firebase/perf'; +import {getAllTransactionViolationsLength} from '@libs/actions/Transaction'; import * as Environment from '@libs/Environment/Environment'; import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils'; import * as ReportConnection from '@libs/ReportConnection'; @@ -65,11 +66,13 @@ function getAttributes(): FirebaseAttributes { const accountId = session?.accountID?.toString() ?? 'N/A'; const reportsLength = ReportConnection.getAllReportsLength().toString(); const personalDetailsLength = PersonalDetailsUtils.getPersonalDetailsLength().toString(); + const transactionViolationsLength = getAllTransactionViolationsLength(); return { accountId, reportsLength, personalDetailsLength, + transactionViolationsLength, }; } diff --git a/src/libs/Firebase/types.ts b/src/libs/Firebase/types.ts index bb212596b535..c47fd1cf1ca7 100644 --- a/src/libs/Firebase/types.ts +++ b/src/libs/Firebase/types.ts @@ -13,6 +13,7 @@ type FirebaseAttributes = { accountId: string; personalDetailsLength: string; reportsLength: string; + transactionViolationsLength: string; }; export type {StartTrace, StopTrace, TraceMap, Log, FirebaseAttributes}; diff --git a/src/libs/actions/Transaction.ts b/src/libs/actions/Transaction.ts index 2bfaf1aaba3d..53c8286cf69d 100644 --- a/src/libs/actions/Transaction.ts +++ b/src/libs/actions/Transaction.ts @@ -489,6 +489,10 @@ function getRecentWaypoints() { return recentWaypoints; } +function getAllTransactionViolationsLength() { + return allTransactionViolations.length; +} + export { addStop, createInitialWaypoints, @@ -504,4 +508,5 @@ export { openDraftDistanceExpense, getRecentWaypoints, sanitizeRecentWaypoints, + getAllTransactionViolationsLength, }; From 1c0f72959076de8818795c385005a02f26e76146 Mon Sep 17 00:00:00 2001 From: Adam Horodyski Date: Wed, 16 Oct 2024 12:33:39 +0200 Subject: [PATCH 2/6] chore: convert length to string --- src/libs/Firebase/index.native.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Firebase/index.native.ts b/src/libs/Firebase/index.native.ts index 28fac163561e..d6a30b2ec64c 100644 --- a/src/libs/Firebase/index.native.ts +++ b/src/libs/Firebase/index.native.ts @@ -66,7 +66,7 @@ function getAttributes(): FirebaseAttributes { const accountId = session?.accountID?.toString() ?? 'N/A'; const reportsLength = ReportConnection.getAllReportsLength().toString(); const personalDetailsLength = PersonalDetailsUtils.getPersonalDetailsLength().toString(); - const transactionViolationsLength = getAllTransactionViolationsLength(); + const transactionViolationsLength = getAllTransactionViolationsLength().toString(); return { accountId, From b552be36fcdff00959befe5dd93278558e93f6ec Mon Sep 17 00:00:00 2001 From: Adam Horodyski Date: Wed, 16 Oct 2024 12:40:05 +0200 Subject: [PATCH 3/6] feat: add reportActionsLength to the attributes list --- src/libs/Firebase/index.native.ts | 3 +++ src/libs/Firebase/types.ts | 1 + src/libs/ReportActionsUtils.ts | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/src/libs/Firebase/index.native.ts b/src/libs/Firebase/index.native.ts index d6a30b2ec64c..54d441bb8faf 100644 --- a/src/libs/Firebase/index.native.ts +++ b/src/libs/Firebase/index.native.ts @@ -4,6 +4,7 @@ import perf from '@react-native-firebase/perf'; import {getAllTransactionViolationsLength} from '@libs/actions/Transaction'; import * as Environment from '@libs/Environment/Environment'; import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils'; +import {getReportActionsLength} from '@libs/ReportActionsUtils'; import * as ReportConnection from '@libs/ReportConnection'; import * as SessionUtils from '@libs/SessionUtils'; import type {FirebaseAttributes, Log, StartTrace, StopTrace, TraceMap} from './types'; @@ -65,12 +66,14 @@ function getAttributes(): FirebaseAttributes { const accountId = session?.accountID?.toString() ?? 'N/A'; const reportsLength = ReportConnection.getAllReportsLength().toString(); + const reportActionsLength = getReportActionsLength().toString(); const personalDetailsLength = PersonalDetailsUtils.getPersonalDetailsLength().toString(); const transactionViolationsLength = getAllTransactionViolationsLength().toString(); return { accountId, reportsLength, + reportActionsLength, personalDetailsLength, transactionViolationsLength, }; diff --git a/src/libs/Firebase/types.ts b/src/libs/Firebase/types.ts index c47fd1cf1ca7..7ef3749c7a3b 100644 --- a/src/libs/Firebase/types.ts +++ b/src/libs/Firebase/types.ts @@ -13,6 +13,7 @@ type FirebaseAttributes = { accountId: string; personalDetailsLength: string; reportsLength: string; + reportActionsLength: string; transactionViolationsLength: string; }; diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index 3b5e0a8eeaa3..566987d0a426 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -1781,6 +1781,10 @@ function getCardIssuedMessage(reportAction: OnyxEntry, shouldRende } } +function getReportActionsLength() { + return Object.keys(allReportActions ?? {}).length; +} + export { doesReportHaveVisibleActions, extractLinksFromMessageHtml, @@ -1892,6 +1896,7 @@ export { getCardIssuedMessage, getRemovedConnectionMessage, getActionableJoinRequestPendingReportAction, + getReportActionsLength, }; export type {LastVisibleMessage}; From 70fd756bd82e8fb108b86be64472adbcd53b6848 Mon Sep 17 00:00:00 2001 From: Tomasz Lesniakiewicz Date: Wed, 16 Oct 2024 13:09:42 +0200 Subject: [PATCH 4/6] feat: add additional metadata to fb trace --- src/libs/Firebase/index.native.ts | 7 ++++++- src/libs/Firebase/types.ts | 2 ++ src/libs/PolicyUtils.ts | 5 +++++ src/libs/actions/Transaction.ts | 5 +++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/libs/Firebase/index.native.ts b/src/libs/Firebase/index.native.ts index 54d441bb8faf..f2d8463b344f 100644 --- a/src/libs/Firebase/index.native.ts +++ b/src/libs/Firebase/index.native.ts @@ -1,9 +1,10 @@ /* eslint-disable no-unused-vars */ import crashlytics from '@react-native-firebase/crashlytics'; import perf from '@react-native-firebase/perf'; -import {getAllTransactionViolationsLength} from '@libs/actions/Transaction'; +import {getAllTransactions, getAllTransactionViolationsLength} from '@libs/actions/Transaction'; import * as Environment from '@libs/Environment/Environment'; import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils'; +import {getAllPoliciesLength} from '@libs/PolicyUtils'; import {getReportActionsLength} from '@libs/ReportActionsUtils'; import * as ReportConnection from '@libs/ReportConnection'; import * as SessionUtils from '@libs/SessionUtils'; @@ -69,6 +70,8 @@ function getAttributes(): FirebaseAttributes { const reportActionsLength = getReportActionsLength().toString(); const personalDetailsLength = PersonalDetailsUtils.getPersonalDetailsLength().toString(); const transactionViolationsLength = getAllTransactionViolationsLength().toString(); + const policiesLength = getAllPoliciesLength().toString(); + const transactionsLength = getAllTransactions().toString(); return { accountId, @@ -76,6 +79,8 @@ function getAttributes(): FirebaseAttributes { reportActionsLength, personalDetailsLength, transactionViolationsLength, + policiesLength, + transactionsLength, }; } diff --git a/src/libs/Firebase/types.ts b/src/libs/Firebase/types.ts index 7ef3749c7a3b..cf17dd27e01c 100644 --- a/src/libs/Firebase/types.ts +++ b/src/libs/Firebase/types.ts @@ -15,6 +15,8 @@ type FirebaseAttributes = { reportsLength: string; reportActionsLength: string; transactionViolationsLength: string; + policiesLength: string; + transactionsLength: string; }; export type {StartTrace, StopTrace, TraceMap, Log, FirebaseAttributes}; diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 6a1a61afa05d..ecd025755a1b 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -1045,6 +1045,10 @@ function hasPolicyFeedsError(feeds: Record, feedToSkip?: s return Object.entries(feeds).filter(([feedName, feedData]) => feedName !== feedToSkip && !!feedData.errors).length > 0; } +function getAllPoliciesLength() { + return Object.keys(allPolicies ?? {}).length; +} + export { canEditTaxRate, extractPolicyIDFromPath, @@ -1159,6 +1163,7 @@ export { hasUnsupportedIntegration, getWorkflowApprovalsUnavailable, getNetSuiteImportCustomFieldLabel, + getAllPoliciesLength, }; export type {MemberEmailsToAccountIDs}; diff --git a/src/libs/actions/Transaction.ts b/src/libs/actions/Transaction.ts index 53c8286cf69d..4b4ef26d957e 100644 --- a/src/libs/actions/Transaction.ts +++ b/src/libs/actions/Transaction.ts @@ -493,6 +493,10 @@ function getAllTransactionViolationsLength() { return allTransactionViolations.length; } +function getAllTransactions() { + return Object.keys(allTransactions ?? {}).length; +} + export { addStop, createInitialWaypoints, @@ -509,4 +513,5 @@ export { getRecentWaypoints, sanitizeRecentWaypoints, getAllTransactionViolationsLength, + getAllTransactions, }; From 9535e7ead804660672968ce73bfb940aec2716a7 Mon Sep 17 00:00:00 2001 From: Tomasz Lesniakiewicz Date: Wed, 16 Oct 2024 13:16:31 +0200 Subject: [PATCH 5/6] feat: get additional metadata to fb traces on web --- src/libs/Firebase/index.web.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/libs/Firebase/index.web.ts b/src/libs/Firebase/index.web.ts index e63ea24b4a09..232494e2b10b 100644 --- a/src/libs/Firebase/index.web.ts +++ b/src/libs/Firebase/index.web.ts @@ -1,6 +1,9 @@ import {trace} from '@firebase/performance'; +import {getAllTransactions, getAllTransactionViolationsLength} from '@libs/actions/Transaction'; import * as Environment from '@libs/Environment/Environment'; import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils'; +import {getAllPoliciesLength} from '@libs/PolicyUtils'; +import {getReportActionsLength} from '@libs/ReportActionsUtils'; import * as ReportConnection from '@libs/ReportConnection'; import * as SessionUtils from '@libs/SessionUtils'; import {firebasePerfWeb} from './firebaseWebConfig'; @@ -60,12 +63,20 @@ function getAttributes(): FirebaseAttributes { const accountId = session?.accountID?.toString() ?? 'N/A'; const reportsLength = ReportConnection.getAllReportsLength().toString(); + const reportActionsLength = getReportActionsLength().toString(); const personalDetailsLength = PersonalDetailsUtils.getPersonalDetailsLength().toString(); + const transactionViolationsLength = getAllTransactionViolationsLength().toString(); + const policiesLength = getAllPoliciesLength().toString(); + const transactionsLength = getAllTransactions().toString(); return { accountId, reportsLength, + reportActionsLength, personalDetailsLength, + transactionViolationsLength, + policiesLength, + transactionsLength, }; } From ad2bcf90d1aeff3ef4c121d230df932b5c6e0e30 Mon Sep 17 00:00:00 2001 From: Tomasz Lesniakiewicz Date: Wed, 16 Oct 2024 13:45:42 +0200 Subject: [PATCH 6/6] chore: move getAttribute logic to utils --- src/libs/Firebase/index.native.ts | 33 +++---------------------------- src/libs/Firebase/index.web.ts | 33 +++---------------------------- src/libs/Firebase/utils.ts | 33 +++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 60 deletions(-) create mode 100644 src/libs/Firebase/utils.ts diff --git a/src/libs/Firebase/index.native.ts b/src/libs/Firebase/index.native.ts index f2d8463b344f..39a23440c77d 100644 --- a/src/libs/Firebase/index.native.ts +++ b/src/libs/Firebase/index.native.ts @@ -1,14 +1,9 @@ /* eslint-disable no-unused-vars */ import crashlytics from '@react-native-firebase/crashlytics'; import perf from '@react-native-firebase/perf'; -import {getAllTransactions, getAllTransactionViolationsLength} from '@libs/actions/Transaction'; import * as Environment from '@libs/Environment/Environment'; -import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils'; -import {getAllPoliciesLength} from '@libs/PolicyUtils'; -import {getReportActionsLength} from '@libs/ReportActionsUtils'; -import * as ReportConnection from '@libs/ReportConnection'; -import * as SessionUtils from '@libs/SessionUtils'; -import type {FirebaseAttributes, Log, StartTrace, StopTrace, TraceMap} from './types'; +import type {Log, StartTrace, StopTrace, TraceMap} from './types'; +import utils from './utils'; const traceMap: TraceMap = {}; @@ -22,7 +17,7 @@ const startTrace: StartTrace = (customEventName) => { return; } - const attributes = getAttributes(); + const attributes = utils.getAttributes(); perf() .startTrace(customEventName) @@ -62,28 +57,6 @@ const log: Log = (action: string) => { crashlytics().log(action); }; -function getAttributes(): FirebaseAttributes { - const session = SessionUtils.getSession(); - - const accountId = session?.accountID?.toString() ?? 'N/A'; - const reportsLength = ReportConnection.getAllReportsLength().toString(); - const reportActionsLength = getReportActionsLength().toString(); - const personalDetailsLength = PersonalDetailsUtils.getPersonalDetailsLength().toString(); - const transactionViolationsLength = getAllTransactionViolationsLength().toString(); - const policiesLength = getAllPoliciesLength().toString(); - const transactionsLength = getAllTransactions().toString(); - - return { - accountId, - reportsLength, - reportActionsLength, - personalDetailsLength, - transactionViolationsLength, - policiesLength, - transactionsLength, - }; -} - export default { startTrace, stopTrace, diff --git a/src/libs/Firebase/index.web.ts b/src/libs/Firebase/index.web.ts index 232494e2b10b..2d42154d3c26 100644 --- a/src/libs/Firebase/index.web.ts +++ b/src/libs/Firebase/index.web.ts @@ -1,13 +1,8 @@ import {trace} from '@firebase/performance'; -import {getAllTransactions, getAllTransactionViolationsLength} from '@libs/actions/Transaction'; import * as Environment from '@libs/Environment/Environment'; -import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils'; -import {getAllPoliciesLength} from '@libs/PolicyUtils'; -import {getReportActionsLength} from '@libs/ReportActionsUtils'; -import * as ReportConnection from '@libs/ReportConnection'; -import * as SessionUtils from '@libs/SessionUtils'; import {firebasePerfWeb} from './firebaseWebConfig'; -import type {FirebaseAttributes, Log, StartTrace, StopTrace, TraceMap} from './types'; +import type {Log, StartTrace, StopTrace, TraceMap} from './types'; +import utils from './utils'; const traceMap: TraceMap = {}; @@ -24,7 +19,7 @@ const startTrace: StartTrace = (customEventName) => { const perfTrace = trace(firebasePerfWeb, customEventName); - const attributes = getAttributes(); + const attributes = utils.getAttributes(); Object.entries(attributes).forEach(([name, value]) => { perfTrace.putAttribute(name, value); @@ -58,28 +53,6 @@ const log: Log = () => { // crashlytics is not supported on WEB }; -function getAttributes(): FirebaseAttributes { - const session = SessionUtils.getSession(); - - const accountId = session?.accountID?.toString() ?? 'N/A'; - const reportsLength = ReportConnection.getAllReportsLength().toString(); - const reportActionsLength = getReportActionsLength().toString(); - const personalDetailsLength = PersonalDetailsUtils.getPersonalDetailsLength().toString(); - const transactionViolationsLength = getAllTransactionViolationsLength().toString(); - const policiesLength = getAllPoliciesLength().toString(); - const transactionsLength = getAllTransactions().toString(); - - return { - accountId, - reportsLength, - reportActionsLength, - personalDetailsLength, - transactionViolationsLength, - policiesLength, - transactionsLength, - }; -} - export default { startTrace, stopTrace, diff --git a/src/libs/Firebase/utils.ts b/src/libs/Firebase/utils.ts new file mode 100644 index 000000000000..23e7c36ec36a --- /dev/null +++ b/src/libs/Firebase/utils.ts @@ -0,0 +1,33 @@ +import {getAllTransactions, getAllTransactionViolationsLength} from '@libs/actions/Transaction'; +import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils'; +import {getAllPoliciesLength} from '@libs/PolicyUtils'; +import {getReportActionsLength} from '@libs/ReportActionsUtils'; +import * as ReportConnection from '@libs/ReportConnection'; +import * as SessionUtils from '@libs/SessionUtils'; +import type {FirebaseAttributes} from './types'; + +function getAttributes(): FirebaseAttributes { + const session = SessionUtils.getSession(); + + const accountId = session?.accountID?.toString() ?? 'N/A'; + const reportsLength = ReportConnection.getAllReportsLength().toString(); + const reportActionsLength = getReportActionsLength().toString(); + const personalDetailsLength = PersonalDetailsUtils.getPersonalDetailsLength().toString(); + const transactionViolationsLength = getAllTransactionViolationsLength().toString(); + const policiesLength = getAllPoliciesLength().toString(); + const transactionsLength = getAllTransactions().toString(); + + return { + accountId, + reportsLength, + reportActionsLength, + personalDetailsLength, + transactionViolationsLength, + policiesLength, + transactionsLength, + }; +} + +export default { + getAttributes, +};