forked from appsmithorg/appsmith
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Improve js execution instrumentation (appsmithorg#24994)
###Description This PR enriches the data logged for the EXECUTE_ACTION event on trigger fields. Example schema <img width="500" alt="Screenshot 2023-07-05 at 10 03 32" src="https://github.com/appsmithorg/appsmith/assets/46670083/13b3ab48-6c19-453a-8eb8-c87129e8c8d5"> Fixes appsmithorg#24706 #### Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video > > #### Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) - Breaking change (fix or feature that would cause existing functionality to not work as expected) - Chore (housekeeping or task changes that don't impact user perception) - This change requires a documentation update > > > ## Testing > #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [ ] Manual - [ ] Jest - [ ] Cypress > > #### Test Plan > Add Testsmith test cases links that relate to this PR > > #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) > > > ## Checklist: #### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
- Loading branch information
1 parent
f24ecc2
commit a7f818d
Showing
7 changed files
with
308 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,224 @@ | ||
import { getCurrentUser } from "selectors/usersSelectors"; | ||
import { getInstanceId } from "@appsmith/selectors/tenantSelectors"; | ||
import { getAppsmithConfigs } from "@appsmith/configs"; | ||
import { call, select } from "redux-saga/effects"; | ||
import type { APP_MODE } from "entities/App"; | ||
import { | ||
getCurrentApplication, | ||
getCurrentPageId, | ||
} from "selectors/editorSelectors"; | ||
import type { TriggerMeta } from "@appsmith/sagas/ActionExecution/ActionExecutionSagas"; | ||
import type { TriggerSource } from "constants/AppsmithActionConstants/ActionConstants"; | ||
import { TriggerKind } from "constants/AppsmithActionConstants/ActionConstants"; | ||
import { isArray } from "lodash"; | ||
import AnalyticsUtil from "utils/AnalyticsUtil"; | ||
import { getEntityNameAndPropertyPath } from "@appsmith/workers/Evaluation/evaluationUtils"; | ||
import { getAppMode, getJSActionFromName } from "selectors/entitiesSelector"; | ||
import type { AppState } from "@appsmith/reducers"; | ||
import { getWidget } from "./selectors"; | ||
|
||
export interface UserAndAppDetails { | ||
pageId: string; | ||
appId: string; | ||
appMode: APP_MODE | undefined; | ||
appName: string; | ||
isExampleApp: boolean; | ||
userId: string; | ||
email: string; | ||
source: string; | ||
instanceId: string; | ||
} | ||
|
||
export function* getUserAndAppDetails() { | ||
const appMode: ReturnType<typeof getAppMode> = yield select(getAppMode); | ||
const currentApp: ReturnType<typeof getCurrentApplication> = yield select( | ||
getCurrentApplication, | ||
); | ||
const user: ReturnType<typeof getCurrentUser> = yield select(getCurrentUser); | ||
const instanceId: ReturnType<typeof getInstanceId> = yield select( | ||
getInstanceId, | ||
); | ||
const { cloudHosting } = getAppsmithConfigs(); | ||
const source = cloudHosting ? "cloud" : "ce"; | ||
const pageId: ReturnType<typeof getCurrentPageId> = yield select( | ||
getCurrentPageId, | ||
); | ||
const userAndAppDetails: UserAndAppDetails = { | ||
pageId, | ||
appId: currentApp?.id || "", | ||
appMode, | ||
appName: currentApp?.name || "", | ||
isExampleApp: currentApp?.appIsExample || false, | ||
userId: user?.username || "", | ||
email: user?.email || "", | ||
source, | ||
instanceId: instanceId, | ||
}; | ||
|
||
return userAndAppDetails; | ||
} | ||
export function* logDynamicTriggerExecution({ | ||
dynamicTrigger, | ||
errors, | ||
triggerMeta, | ||
}: { | ||
dynamicTrigger: string; | ||
errors: unknown; | ||
triggerMeta: TriggerMeta; | ||
}) { | ||
if (triggerMeta.triggerKind !== TriggerKind.EVENT_EXECUTION) return; | ||
const isUnsuccessfulExecution = isArray(errors) && errors.length > 0; | ||
const { | ||
appId, | ||
appMode, | ||
appName, | ||
email, | ||
instanceId, | ||
isExampleApp, | ||
pageId, | ||
source, | ||
userId, | ||
}: UserAndAppDetails = yield call(getUserAndAppDetails); | ||
const widget: ReturnType<typeof getWidget> | undefined = yield select( | ||
(state: AppState) => getWidget(state, triggerMeta.source?.id || ""), | ||
); | ||
|
||
const dynamicPropertyPathList = widget?.dynamicPropertyPathList; | ||
const isJSToggled = !!dynamicPropertyPathList?.find( | ||
(property) => property.key === triggerMeta.triggerPropertyName, | ||
); | ||
AnalyticsUtil.logEvent("EXECUTE_ACTION", { | ||
type: "JS_EXPRESSION", | ||
unevalValue: dynamicTrigger, | ||
pageId, | ||
appId, | ||
appMode, | ||
appName, | ||
isExampleApp, | ||
userData: { | ||
userId, | ||
email, | ||
appId, | ||
source, | ||
}, | ||
widgetName: widget?.widgetName, | ||
widgetType: widget?.type, | ||
propertyName: triggerMeta.triggerPropertyName, | ||
instanceId, | ||
isJSToggled, | ||
}); | ||
|
||
AnalyticsUtil.logEvent( | ||
isUnsuccessfulExecution | ||
? "EXECUTE_ACTION_FAILURE" | ||
: "EXECUTE_ACTION_SUCCESS", | ||
{ | ||
type: "JS_EXPRESSION", | ||
unevalValue: dynamicTrigger, | ||
pageId, | ||
appId, | ||
appMode, | ||
appName, | ||
isExampleApp, | ||
userData: { | ||
userId, | ||
email, | ||
appId, | ||
source, | ||
}, | ||
widgetName: widget?.widgetName, | ||
widgetType: widget?.type, | ||
propertyName: triggerMeta.triggerPropertyName, | ||
instanceId, | ||
isJSToggled, | ||
}, | ||
); | ||
} | ||
|
||
export function* logJSActionExecution( | ||
executionData: { | ||
jsFnFullName: string; | ||
isSuccess: boolean; | ||
triggerMeta: { | ||
source: TriggerSource; | ||
triggerPropertyName: string | undefined; | ||
triggerKind: TriggerKind | undefined; | ||
}; | ||
}[], | ||
) { | ||
const { | ||
appId, | ||
appMode, | ||
appName, | ||
email, | ||
instanceId, | ||
isExampleApp, | ||
pageId, | ||
source, | ||
userId, | ||
}: UserAndAppDetails = yield call(getUserAndAppDetails); | ||
for (const { isSuccess, jsFnFullName, triggerMeta } of executionData) { | ||
const { entityName: JSObjectName, propertyPath: functionName } = | ||
getEntityNameAndPropertyPath(jsFnFullName); | ||
const jsAction: ReturnType<typeof getJSActionFromName> = yield select( | ||
(state: AppState) => | ||
getJSActionFromName(state, JSObjectName, functionName), | ||
); | ||
const triggeredWidget: ReturnType<typeof getWidget> | undefined = | ||
yield select((state: AppState) => | ||
getWidget(state, triggerMeta.source?.id || ""), | ||
); | ||
const dynamicPropertyPathList = triggeredWidget?.dynamicPropertyPathList; | ||
const isJSToggled = !!dynamicPropertyPathList?.find( | ||
(property) => property.key === triggerMeta.triggerPropertyName, | ||
); | ||
AnalyticsUtil.logEvent("EXECUTE_ACTION", { | ||
type: "JS", | ||
name: functionName, | ||
JSObjectName, | ||
pageId, | ||
appId, | ||
appMode, | ||
appName, | ||
isExampleApp, | ||
actionId: jsAction?.id, | ||
userData: { | ||
userId, | ||
email, | ||
appId, | ||
source, | ||
}, | ||
widgetName: triggeredWidget?.widgetName, | ||
widgetType: triggeredWidget?.type, | ||
propertyName: triggerMeta.triggerPropertyName, | ||
isJSToggled, | ||
instanceId, | ||
}); | ||
|
||
AnalyticsUtil.logEvent( | ||
isSuccess ? "EXECUTE_ACTION_SUCCESS" : "EXECUTE_ACTION_FAILURE", | ||
{ | ||
type: "JS", | ||
name: functionName, | ||
JSObjectName, | ||
pageId, | ||
appId, | ||
appMode, | ||
appName, | ||
isExampleApp, | ||
actionId: jsAction?.id, | ||
userData: { | ||
userId, | ||
email, | ||
appId, | ||
source, | ||
}, | ||
widgetName: triggeredWidget?.widgetName, | ||
widgetType: triggeredWidget?.type, | ||
propertyName: triggerMeta.triggerPropertyName, | ||
isJSToggled, | ||
instanceId, | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.