Skip to content

chore: Add organizationId in MDC logs to ease debugging in multi-org setup #40211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 11, 2025

Conversation

abhvsn
Copy link
Contributor

@abhvsn abhvsn commented Apr 10, 2025

Description

Sample log:

[2025-04-10 18:19:30,460] [nioEventLoopGroup-3-4] requestId= userEmail=anonymousUser orgId=67e293c5428efb42aed44e11 traceId=6141b52a410b60168b68a6ce72e4d601 spanId=45c1771528e79d6d - Going to fetch consolidatedAPI response for applicationId: null, defaultPageId: null, branch: null, mode: PUBLISHED

/test Sanity

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/14387773115
Commit: e345a8d
Cypress dashboard.
Tags: @tag.Sanity
Spec:


Thu, 10 Apr 2025 19:11:45 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features
    • Enhanced logging output now includes an organization identifier alongside request and user details, improving traceability and contextual insight for server events.
    • Server-side processes now capture additional organization context with each request, providing richer and more informative log entries.

Copy link
Contributor

coderabbitai bot commented Apr 10, 2025

Walkthrough

The changes update the MDCFilter to include a dependency on UserOrganizationHelper for retrieving the current user's organization ID. The filter method is modified to combine the principal with the organization ID using zipWith, and the context-building method now accepts an additional organization ID parameter. Simultaneously, the logging pattern in the properties file is updated to include the organization ID, enhancing the logging context.

Changes

File(s) Change Summary
app/server/appsmith-server/.../MDCFilter.java Added a constructor accepting UserOrganizationHelper, modified the filter method to combine principal and organization ID using zipWith, and updated the addRequestHeadersToContext method signature to include the organization ID.
app/server/appsmith-server/.../application-ce.properties Updated the logging.pattern.console property to include orgId=%X{organizationId}, enhancing the logging output with organization context.

Sequence Diagram(s)

sequenceDiagram
  participant Request
  participant MDCFilter
  participant UserOrgHelper as UserOrganizationHelper
  participant MDCContext as MDC Logging Context

  Request->>MDCFilter: Incoming HTTP Request
  MDCFilter->>UserOrgHelper: getCurrentUserOrganizationId()
  UserOrgHelper-->>MDCFilter: organizationId
  MDCFilter->>MDCFilter: Combine principal & organizationId (zipWith)
  MDCFilter->>MDCContext: addRequestHeadersToContext(request, context, user, organizationId)
  MDCContext-->>MDCFilter: Updated logging context
  MDCFilter->>Request: Continue filter chain
Loading

Suggested reviewers

  • sharat87

Poem

In code's embrace, a twist so fine,
Org IDs merge with logs in line.
A helper lends its guiding hand,
Together they log across the land.
Huzzah to progress—let our system shine!


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 8cbb798 and e345a8d.

📒 Files selected for processing (1)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/filters/MDCFilter.java (5 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
app/server/appsmith-server/src/main/java/com/appsmith/server/filters/MDCFilter.java (1)
app/server/appsmith-server/src/main/java/com/appsmith/server/constants/ce/FieldNameCE.java (1)
  • FieldNameCE (3-212)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: server-unit-tests / server-unit-tests
  • GitHub Check: server-spotless / spotless-check
🔇 Additional comments (6)
app/server/appsmith-server/src/main/java/com/appsmith/server/filters/MDCFilter.java (6)

5-5: Appropriate import statements added

The new imports for UserOrganizationHelper and ORGANIZATION_ID constant are correctly added to support the organization ID logging feature.

Also applies to: 21-21


32-32: Properly implemented dependency injection

The UserOrganizationHelper dependency is correctly declared as a final field and initialized through constructor injection, following Spring's best practices.

Also applies to: 44-46


53-59: Correctly handles empty organization ID case

The implementation properly uses zipWith to combine the principal with the organization ID, and correctly handles the case when no organization ID is available by using defaultIfEmpty(""). This ensures the filter chain continues even when no organization ID is found.


62-62: Method signature updated correctly

The method call to addRequestHeadersToContext is updated to pass the organization ID parameter, maintaining consistency with the method signature change.


70-70: Method signature updated consistently

The addRequestHeadersToContext method signature is updated to include the organization ID parameter, aligning with the changes in the filter method.


79-81: Properly adds organization ID to context

The code correctly checks if the organization ID has content before adding it to the context map, preventing empty values from being added to the MDC context.


🪧 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 plan to trigger planning for file edits and PR creation.
  • @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 Apr 10, 2025
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
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5a6479c and 8cbb798.

📒 Files selected for processing (2)
  • app/server/appsmith-server/src/main/java/com/appsmith/server/filters/MDCFilter.java (5 hunks)
  • app/server/appsmith-server/src/main/resources/application-ce.properties (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
app/server/appsmith-server/src/main/java/com/appsmith/server/filters/MDCFilter.java (1)
app/server/appsmith-server/src/main/java/com/appsmith/server/constants/ce/FieldNameCE.java (1)
  • FieldNameCE (3-212)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: server-spotless / spotless-check
  • GitHub Check: server-unit-tests / server-unit-tests
🔇 Additional comments (6)
app/server/appsmith-server/src/main/resources/application-ce.properties (1)

35-35: Logging pattern updated to include organization ID

The update adds the organization ID to the logging pattern, which will enhance debugging in multi-organization environments. This change aligns well with the PR objectives.

app/server/appsmith-server/src/main/java/com/appsmith/server/filters/MDCFilter.java (5)

5-5: Added UserOrganizationHelper dependency

This import is necessary for retrieving the organization ID.


21-21: Added ORGANIZATION_ID constant import

Appropriate use of a constant for the organization ID field name from FieldNameCE.


32-32: Added constructor injection for UserOrganizationHelper

The dependency is properly injected via constructor, following Spring best practices.

Also applies to: 44-46


68-68: Method signature updated to include organizationId

The method signature has been properly updated to accept the organization ID parameter.


77-79: Added organization ID to context map

The organization ID is correctly added to the context map with null check.

@abhvsn abhvsn added the ok-to-test Required label for CI label Apr 10, 2025
@appsmithorg appsmithorg deleted a comment from github-actions bot Apr 10, 2025
@appsmithorg appsmithorg deleted a comment from github-actions bot Apr 10, 2025
@abhvsn abhvsn merged commit 953a716 into release Apr 11, 2025
50 checks passed
@abhvsn abhvsn deleted the feat/add-org-name-in-mdc-context branch April 11, 2025 05:21
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Apr 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test Required label for CI 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.

2 participants