chore: Add span for measuring performance of consolidated api#37328
chore: Add span for measuring performance of consolidated api#37328rajatagrawal merged 1 commit intoreleasefrom
Conversation
WalkthroughThe changes in this pull request primarily focus on enhancing the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
| shouldInitialiseUserDetails, | ||
| ); | ||
|
|
||
| const rootSpan = startRootSpan("fetch-consolidated-api"); |
There was a problem hiding this comment.
Will it better to add attribute for edit and view mode?
There was a problem hiding this comment.
They are added by default to all spans on frontend now
| const rootSpan = startRootSpan("fetch-consolidated-api"); | ||
| const initConsolidatedApiResponse: ApiResponse<InitConsolidatedApi> = | ||
| yield mode === APP_MODE.EDIT | ||
| ? ConsolidatedPageLoadApi.getConsolidatedPageLoadDataEdit(params) | ||
| : ConsolidatedPageLoadApi.getConsolidatedPageLoadDataView(params); | ||
|
|
||
| endSpan(rootSpan); | ||
|
|
There was a problem hiding this comment.
🛠️ Refactor suggestion
Move endSpan(rootSpan) to the finally block to ensure spans are always ended.
Currently, endSpan(rootSpan) is called after the API call, but if an error occurs before this point, the span may not be properly ended. Placing endSpan(rootSpan) in the finally block ensures it executes regardless of exceptions.
Apply this diff to fix the issue:
export function* getInitResponses({ applicationId, basePageId, mode, shouldInitialiseUserDetails }: { applicationId?: string; basePageId?: string; mode?: APP_MODE; shouldInitialiseUserDetails?: boolean; }): any {
const params = pickBy(
{
applicationId,
defaultPageId: basePageId,
},
identity,
);
let response: InitConsolidatedApi | undefined;
+ const rootSpan = startRootSpan("fetch-consolidated-api");
try {
- const rootSpan = startRootSpan("fetch-consolidated-api");
yield call(
executeActionDuringUserDetailsInitialisation,
ReduxActionTypes.START_CONSOLIDATED_PAGE_LOAD,
shouldInitialiseUserDetails,
);
const initConsolidatedApiResponse: ApiResponse<InitConsolidatedApi> =
yield mode === APP_MODE.EDIT
? ConsolidatedPageLoadApi.getConsolidatedPageLoadDataEdit(params)
: ConsolidatedPageLoadApi.getConsolidatedPageLoadDataView(params);
- endSpan(rootSpan);
const isValidResponse: boolean = yield validateResponse(
initConsolidatedApiResponse,
);
response = initConsolidatedApiResponse.data;
if (!isValidResponse) {
// its only invalid when there is a axios related error
throw new Error("Error occured " + AXIOS_CONNECTION_ABORTED_CODE);
}
} catch (e: any) {
// when the user is an anonymous user we embed the url with the attempted route
// this is taken care in ce code repo but not on ee
if (e?.response?.status === 401) {
embedRedirectURL();
}
yield call(
executeActionDuringUserDetailsInitialisation,
ReduxActionTypes.END_CONSOLIDATED_PAGE_LOAD,
shouldInitialiseUserDetails,
);
Sentry.captureMessage(
`consolidated api failure for ${JSON.stringify(
params,
)} errored message response ${e}`,
);
throw new PageNotFoundError(`Cannot find page with base id: ${basePageId}`);
+ } finally {
+ endSpan(rootSpan);
}
const { featureFlags, productAlert, tenantConfig, userProfile, ...rest } =
response || {};
//actions originating from INITIALIZE_CURRENT_PAGE should update user details
//other actions are not necessaryCommittable suggestion skipped: line range outside the PR's diff.
…thorg#37328) This PR adds spans for fetching consolidated api from client perspective <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Enhanced API call functionality with improved error handling and response validation. - Added tracing for better observability during API interactions. - **Bug Fixes** - Refined error handling for specific scenarios, including unauthorized access. - **Documentation** - Updated function signatures for better clarity on API response handling. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This PR adds spans for fetching consolidated api from client perspective
Summary by CodeRabbit
New Features
Bug Fixes
Documentation