Skip to content

Commit

Permalink
Merge pull request #50881 from callstack-internal/feat/extended-perf-…
Browse files Browse the repository at this point in the history
…analytics-metadata

Extend perf analytics metadata
  • Loading branch information
mountiny authored Oct 17, 2024
2 parents b773e57 + ad2bcf9 commit 83d8ed4
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 38 deletions.
22 changes: 3 additions & 19 deletions src/libs/Firebase/index.native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
import crashlytics from '@react-native-firebase/crashlytics';
import perf from '@react-native-firebase/perf';
import * as Environment from '@libs/Environment/Environment';
import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';
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 = {};

Expand All @@ -19,7 +17,7 @@ const startTrace: StartTrace = (customEventName) => {
return;
}

const attributes = getAttributes();
const attributes = utils.getAttributes();

perf()
.startTrace(customEventName)
Expand Down Expand Up @@ -59,20 +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 personalDetailsLength = PersonalDetailsUtils.getPersonalDetailsLength().toString();

return {
accountId,
reportsLength,
personalDetailsLength,
};
}

export default {
startTrace,
stopTrace,
Expand Down
22 changes: 3 additions & 19 deletions src/libs/Firebase/index.web.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import {trace} from '@firebase/performance';
import * as Environment from '@libs/Environment/Environment';
import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';
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 = {};

Expand All @@ -21,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);
Expand Down Expand Up @@ -55,20 +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 personalDetailsLength = PersonalDetailsUtils.getPersonalDetailsLength().toString();

return {
accountId,
reportsLength,
personalDetailsLength,
};
}

export default {
startTrace,
stopTrace,
Expand Down
4 changes: 4 additions & 0 deletions src/libs/Firebase/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ type FirebaseAttributes = {
accountId: string;
personalDetailsLength: string;
reportsLength: string;
reportActionsLength: string;
transactionViolationsLength: string;
policiesLength: string;
transactionsLength: string;
};

export type {StartTrace, StopTrace, TraceMap, Log, FirebaseAttributes};
33 changes: 33 additions & 0 deletions src/libs/Firebase/utils.ts
Original file line number Diff line number Diff line change
@@ -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,
};
5 changes: 5 additions & 0 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1050,6 +1050,10 @@ function hasPolicyFeedsError(feeds: Record<string, CardFeedData>, 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,
Expand Down Expand Up @@ -1165,6 +1169,7 @@ export {
hasUnsupportedIntegration,
getWorkflowApprovalsUnavailable,
getNetSuiteImportCustomFieldLabel,
getAllPoliciesLength,
};

export type {MemberEmailsToAccountIDs};
5 changes: 5 additions & 0 deletions src/libs/ReportActionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1769,6 +1769,10 @@ function getCardIssuedMessage(reportAction: OnyxEntry<ReportAction>, shouldRende
}
}

function getReportActionsLength() {
return Object.keys(allReportActions ?? {}).length;
}

export {
doesReportHaveVisibleActions,
extractLinksFromMessageHtml,
Expand Down Expand Up @@ -1878,6 +1882,7 @@ export {
getCardIssuedMessage,
getRemovedConnectionMessage,
getActionableJoinRequestPendingReportAction,
getReportActionsLength,
};

export type {LastVisibleMessage};
10 changes: 10 additions & 0 deletions src/libs/actions/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,14 @@ function getRecentWaypoints() {
return recentWaypoints;
}

function getAllTransactionViolationsLength() {
return allTransactionViolations.length;
}

function getAllTransactions() {
return Object.keys(allTransactions ?? {}).length;
}

export {
addStop,
createInitialWaypoints,
Expand All @@ -504,4 +512,6 @@ export {
openDraftDistanceExpense,
getRecentWaypoints,
sanitizeRecentWaypoints,
getAllTransactionViolationsLength,
getAllTransactions,
};

0 comments on commit 83d8ed4

Please sign in to comment.