Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend perf analytics metadata #50881

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1045,6 +1045,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 @@ -1159,6 +1163,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 @@ -1781,6 +1781,10 @@ function getCardIssuedMessage(reportAction: OnyxEntry<ReportAction>, shouldRende
}
}

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

export {
doesReportHaveVisibleActions,
extractLinksFromMessageHtml,
Expand Down Expand Up @@ -1892,6 +1896,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,
};
Loading