Skip to content
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
2 changes: 2 additions & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,8 @@ const CONST = {
},
TELEMETRY: {
CONTEXT_FULLSTORY: 'Fullstory',
CONTEXT_POLICIES: 'Policies',
TAG_ACTIVE_POLICY: 'active_policy_id',
},
PRIORITY_MODE: {
GSD: 'gsd',
Expand Down
2 changes: 2 additions & 0 deletions src/Expensify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ import './libs/registerPaginationConfig';
import setCrashlyticsUserId from './libs/setCrashlyticsUserId';
import StartupTimer from './libs/StartupTimer';
// This lib needs to be imported, but it has nothing to export since all it contains is an Onyx connection
import './libs/TelemetrySynchronizer';
// This lib needs to be imported, but it has nothing to export since all it contains is an Onyx connection
import './libs/UnreadIndicatorUpdater';
import Visibility from './libs/Visibility';
import ONYXKEYS from './ONYXKEYS';
Expand Down
62 changes: 62 additions & 0 deletions src/libs/TelemetrySynchronizer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* This file contains the logic for sending additional data to Sentry.
*
* It uses Onyx.connectWithoutView as nothing here is related to the UI. We only send data to the external provider and want to keep this outside of the render loop.
*/
import * as Sentry from '@sentry/react-native';
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {Policy, Session} from '@src/types/onyx';
import {getActivePolicies} from './PolicyUtils';

/**
* Connect to Onyx to retrieve information about the user's active policies.
*/
let session: OnyxEntry<Session>;
let activePolicyID: OnyxEntry<string>;
let policies: OnyxCollection<Policy>;

Onyx.connectWithoutView({
key: ONYXKEYS.NVP_ACTIVE_POLICY_ID,
callback: (value) => {
if (!value) {
return;
}
activePolicyID = value;
sendPoliciesContext();
},
});

Onyx.connectWithoutView({
key: ONYXKEYS.SESSION,
callback: (value) => {
if (!value?.email) {
return;
}
session = value;
sendPoliciesContext();
},
});

Onyx.connectWithoutView({
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (value) => {
if (!value) {
return;
}
policies = value;
sendPoliciesContext();
},
});

function sendPoliciesContext() {
if (!policies || !session?.email || !activePolicyID) {
return;
}
const activePolicies = getActivePolicies(policies, session.email).map((policy) => policy.id);
Sentry.setTag(CONST.TELEMETRY.TAG_ACTIVE_POLICY, activePolicyID);
Sentry.setContext(CONST.TELEMETRY.CONTEXT_POLICIES, {activePolicyID, activePolicies});
}
Loading