Skip to content

Commit

Permalink
Merge pull request Expensify#46284 from callstack-internal/perf/attac…
Browse files Browse the repository at this point in the history
…h-accountid-to-firebase-sessions

perf: attach accountID to Firebase Performance sessions
  • Loading branch information
marcaaron authored Jul 26, 2024
2 parents 1908bd1 + 85048a8 commit 9901ca3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/libs/Firebase/index.native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import crashlytics from '@react-native-firebase/crashlytics';
import perf from '@react-native-firebase/perf';
import * as Environment from '@libs/Environment/Environment';
import * as SessionUtils from '@libs/SessionUtils';
import type {Log, StartTrace, StopTrace, TraceMap} from './types';

const traceMap: TraceMap = {};
Expand All @@ -16,9 +17,12 @@ const startTrace: StartTrace = (customEventName) => {
return;
}

const session = SessionUtils.getSession();

perf()
.startTrace(customEventName)
.then((trace) => {
trace.putAttribute('accountID', session?.accountID?.toString() ?? 'N/A');
traceMap[customEventName] = {
trace,
start,
Expand Down
10 changes: 9 additions & 1 deletion src/libs/SessionUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Onyx from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import ONYXKEYS from '@src/ONYXKEYS';
import type * as OnyxTypes from '@src/types/onyx';

/**
* Determine if the transitioning user is logging in as a new user.
Expand All @@ -26,12 +28,14 @@ function isLoggingInAsNewUser(transitionURL?: string, sessionEmail?: string): bo
}

let loggedInDuringSession: boolean | undefined;
let currentSession: OnyxEntry<OnyxTypes.Session>;

// To tell if the user logged in during this session we will check the value of session.authToken once when the app's JS inits. When the user logs out
// we can reset this flag so that it can be updated again.
Onyx.connect({
key: ONYXKEYS.SESSION,
callback: (session) => {
currentSession = session;
if (loggedInDuringSession) {
return;
}
Expand All @@ -53,4 +57,8 @@ function didUserLogInDuringSession() {
return !!loggedInDuringSession;
}

export {isLoggingInAsNewUser, didUserLogInDuringSession, resetDidUserLogInDuringSession};
function getSession() {
return currentSession;
}

export {isLoggingInAsNewUser, didUserLogInDuringSession, resetDidUserLogInDuringSession, getSession};

0 comments on commit 9901ca3

Please sign in to comment.