Skip to content

chore: Add span for measuring performance of consolidated api#37328

Merged
rajatagrawal merged 1 commit intoreleasefrom
chore/add-consolidated-api-span
Nov 12, 2024
Merged

chore: Add span for measuring performance of consolidated api#37328
rajatagrawal merged 1 commit intoreleasefrom
chore/add-consolidated-api-span

Conversation

@rajatagrawal
Copy link
Contributor

@rajatagrawal rajatagrawal commented Nov 12, 2024

This PR adds spans for fetching consolidated api from client perspective

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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 12, 2024

Walkthrough

The changes in this pull request primarily focus on enhancing the InitSagas.ts file's functionality related to API calls and error handling. Key modifications include the introduction of tracing spans for improved observability, validation of API responses, and refined error handling mechanisms. The getInitResponses and startAppEngine functions have been updated to better capture errors and monitor performance, ensuring a more robust interaction with the API.

Changes

File Path Change Summary
app/client/src/sagas/InitSagas.ts - Added tracing spans for API calls and app engine initialization.
- Updated getInitResponses to include response validation and improved error handling.
- Modified function signatures for getInitResponses and startAppEngine.

Possibly related PRs

Suggested labels

Task, skip-changelog, ok-to-test, Integrations Product, Integrations Pod General

Suggested reviewers

  • vsvamsi1
  • sneha122

🌟 In the land of code where functions play,
New spans are born to light the way.
With errors caught and responses checked,
Our API's journey is now well-protected!
So here's to the changes, robust and bright,
Making our code a true delight! 🎉


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Nov 12, 2024
shouldInitialiseUserDetails,
);

const rootSpan = startRootSpan("fetch-consolidated-api");
Copy link
Contributor

Choose a reason for hiding this comment

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

Will it better to add attribute for edit and view mode?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are added by default to all spans on frontend now

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d8d0d1a and f9047b1.

📒 Files selected for processing (1)
  • app/client/src/sagas/InitSagas.ts (1 hunks)

Comment on lines +243 to +250
const rootSpan = startRootSpan("fetch-consolidated-api");
const initConsolidatedApiResponse: ApiResponse<InitConsolidatedApi> =
yield mode === APP_MODE.EDIT
? ConsolidatedPageLoadApi.getConsolidatedPageLoadDataEdit(params)
: ConsolidatedPageLoadApi.getConsolidatedPageLoadDataView(params);

endSpan(rootSpan);

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

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 necessary

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

@rajatagrawal rajatagrawal enabled auto-merge (squash) November 12, 2024 05:21
@rajatagrawal rajatagrawal merged commit b24b66f into release Nov 12, 2024
@rajatagrawal rajatagrawal deleted the chore/add-consolidated-api-span branch November 12, 2024 05:37
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Nov 20, 2024
…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 -->
@coderabbitai coderabbitai bot mentioned this pull request Dec 5, 2024
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-changelog Adding this label to a PR prevents it from being listed in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants