Skip to content

Commit

Permalink
Merge pull request #46888 from callstack-internal/details-metadata-in…
Browse files Browse the repository at this point in the history
…-fb-trace

Add personalDetails and report length to fb trace metadata
  • Loading branch information
marcaaron authored Aug 12, 2024
2 parents 8969805 + 7b50958 commit d9990a4
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 6 deletions.
5 changes: 5 additions & 0 deletions jest/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,8 @@ jest.mock('react-native-reanimated', () => ({
}));

jest.mock('react-native-keyboard-controller', () => require<typeof RNKeyboardController>('react-native-keyboard-controller/jest'));

jest.mock('@src/libs/actions/Timing', () => ({
start: jest.fn(),
end: jest.fn(),
}));
24 changes: 21 additions & 3 deletions src/libs/Firebase/index.native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
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 {Log, StartTrace, StopTrace, TraceMap} from './types';
import type {FirebaseAttributes, Log, StartTrace, StopTrace, TraceMap} from './types';

const traceMap: TraceMap = {};

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

const session = SessionUtils.getSession();
const attributes = getAttributes();

perf()
.startTrace(customEventName)
.then((trace) => {
trace.putAttribute('accountID', session?.accountID?.toString() ?? 'N/A');
Object.entries(attributes).forEach(([name, value]) => {
trace.putAttribute(name, value);
});
traceMap[customEventName] = {
trace,
start,
Expand Down Expand Up @@ -55,6 +59,20 @@ 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
7 changes: 6 additions & 1 deletion src/libs/Firebase/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ type TraceMap = Record<string, Trace>;
type StartTrace = (customEventName: string) => void;
type StopTrace = (customEventName: string) => void;
type Log = (action: string) => void;
type FirebaseAttributes = {
accountId: string;
personalDetailsLength: string;
reportsLength: string;
};

export type {StartTrace, StopTrace, TraceMap, Log};
export type {StartTrace, StopTrace, TraceMap, Log, FirebaseAttributes};
5 changes: 5 additions & 0 deletions src/libs/PersonalDetailsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ function isPersonalDetailsEmpty() {
return !personalDetails.length;
}

function getPersonalDetailsLength() {
return personalDetails.length;
}

export {
isPersonalDetailsEmpty,
getDisplayNameOrDefault,
Expand All @@ -339,4 +343,5 @@ export {
createDisplayName,
extractFirstAndLastNameFromAvailableDetails,
getNewAccountIDsAndLogins,
getPersonalDetailsLength,
};
6 changes: 5 additions & 1 deletion src/libs/ReportConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,8 @@ function getAllReportsNameMap() {
return reportIDToNameMap;
}

export {getAllReports, getAllReportsNameMap};
function getAllReportsLength() {
return Object.keys(allReports ?? {}).length;
}

export {getAllReports, getAllReportsNameMap, getAllReportsLength};
2 changes: 1 addition & 1 deletion src/pages/home/sidebar/SidebarScreen/BaseSidebarScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function BaseSidebarScreen() {

useEffect(() => {
Performance.markStart(CONST.TIMING.SIDEBAR_LOADED);
Timing.start(CONST.TIMING.SIDEBAR_LOADED, true);
Timing.start(CONST.TIMING.SIDEBAR_LOADED);
}, []);

useEffect(() => {
Expand Down

0 comments on commit d9990a4

Please sign in to comment.