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
28 changes: 10 additions & 18 deletions app/client/src/ce/sagas/userSagas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import {
import AnalyticsUtil from "ee/utils/AnalyticsUtil";
import { INVITE_USERS_TO_WORKSPACE_FORM } from "ee/constants/forms";
import type { User } from "constants/userConstants";
import { ANONYMOUS_USERNAME } from "constants/userConstants";
import {
flushErrorsAndRedirect,
safeCrashAppRequest,
Expand Down Expand Up @@ -190,9 +189,15 @@ export function* getCurrentUserSaga(action?: {
}
}

function* intializeSmartLook(currentUser: User) {
if (!currentUser.isAnonymous && currentUser.username !== ANONYMOUS_USERNAME) {
yield AnalyticsUtil.identifyUser(currentUser);
function* initTrackers(currentUser: User) {
const initializeSentry = initializeAnalyticsAndTrackers(currentUser);

const sentryInitialized: boolean = yield initializeSentry;

if (sentryInitialized) {
yield put(segmentInitSuccess());
} else {
yield put(segmentInitUncertain());
}
Comment on lines +192 to 201
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling and improve type safety.

The function should handle potential initialization errors and have proper type checking:

-function* initTrackers(currentUser: User) {
+function* initTrackers(currentUser: User) {
+  try {
     const initializeSentry = initializeAnalyticsAndTrackers(currentUser);
-    const sentryInitialized: boolean = yield initializeSentry;
+    const sentryInitialized: boolean = yield Promise.resolve(initializeSentry);
 
     if (sentryInitialized) {
       yield put(segmentInitSuccess());
     } else {
       yield put(segmentInitUncertain());
     }
+  } catch (error) {
+    yield put(segmentInitUncertain());
+    Sentry.captureException("Analytics initialization failed", {
+      level: Severity.Error,
+      extra: { error },
+    });
+  }
 }

Also, consider renaming the function to better reflect its responsibility (e.g., initSentryAnalytics).

Committable suggestion skipped: line range outside the PR's diff.

}

Expand All @@ -202,20 +207,7 @@ export function* runUserSideEffectsSaga() {
const isAirgappedInstance = isAirgapped();

if (enableTelemetry) {
// parallelize sentry and smart look initialization

yield fork(intializeSmartLook, currentUser);
const initializeSentry = initializeAnalyticsAndTrackers();

if (initializeSentry instanceof Promise) {
const sentryInialized: boolean = yield initializeSentry;

if (sentryInialized) {
yield put(segmentInitSuccess());
} else {
yield put(segmentInitUncertain());
}
}
yield fork(initTrackers, currentUser);
}

const isFFFetched: boolean = yield select(getFeatureFlagsFetched);
Expand Down
8 changes: 7 additions & 1 deletion app/client/src/utils/AppsmithUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import type { JSCollectionData } from "ee/reducers/entityReducers/jsActionsReduc
import AnalyticsUtil from "ee/utils/AnalyticsUtil";
import type { CreateNewActionKeyInterface } from "ee/entities/Engine/actionHelpers";
import { CreateNewActionKey } from "ee/entities/Engine/actionHelpers";
import { ANONYMOUS_USERNAME } from "../constants/userConstants";
import type { User } from "constants/userConstants";

export const initializeAnalyticsAndTrackers = async () => {
export const initializeAnalyticsAndTrackers = async (currentUser: User) => {
const appsmithConfigs = getAppsmithConfigs();

try {
Expand Down Expand Up @@ -106,6 +108,10 @@ export const initializeAnalyticsAndTrackers = async () => {
Sentry.captureException(e);
log.error(e);
}

if (!currentUser.isAnonymous && currentUser.username !== ANONYMOUS_USERNAME) {
await AnalyticsUtil.identifyUser(currentUser);
}
};

export const mapToPropList = (map: Record<string, string>): Property[] => {
Expand Down