Skip to content

chore: Use json logs for production#37272

Closed
nidhi-nair wants to merge 1 commit intoreleasefrom
chore/structured-logs-server
Closed

chore: Use json logs for production#37272
nidhi-nair wants to merge 1 commit intoreleasefrom
chore/structured-logs-server

Conversation

@nidhi-nair
Copy link
Contributor

@nidhi-nair nidhi-nair commented Nov 7, 2024

Description

Added configurations to enable json logging for server that allows use to have structured labels for all logs coming out of server

Automation

/ok-to-test tags=""

🔍 Cypress test results

Caution

If you modify the content in this section, you are likely to disrupt the CI result for your PR.

Communication

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

  • Yes
  • No

Summary by CodeRabbit

  • New Features
    • Introduced a new logging configuration file to enhance logging capabilities with support for different formats based on the environment (development, testing, production).
  • Bug Fixes
    • Removed outdated logging properties to streamline configuration management.
  • Chores
    • Added a new dependency for improved logging functionality.

@nidhi-nair nidhi-nair requested a review from sharat87 as a code owner November 7, 2024 06:58
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 7, 2024

Walkthrough

The changes introduced in this pull request include the addition of a new logging dependency in the pom.xml file, the removal of several logging configuration properties from the application.properties file, and the introduction of a new logging configuration file, logback-spring.xml. These modifications collectively indicate a shift in the logging framework and configuration strategy used within the application.

Changes

File Path Change Summary
app/server/appsmith-interfaces/pom.xml Added dependency: logstash-logback-encoder (Group ID: net.logstash.logback, Version: 8.0).
app/server/appsmith-server/src/main/resources/application.properties Removed logging properties: logging.level.root, logging.level.com.appsmith, logging.level.com.external.plugins, logging.pattern.console.
app/server/appsmith-server/src/main/resources/logback-spring.xml Added new logging configuration file defining settings for different Spring profiles (dev, test, production).

Possibly related PRs

Suggested labels

skip-changelog, ok-to-test

Suggested reviewers

  • ApekshaBhosale
  • sharat87

🎉 In the code where logs now flow,
A new encoder makes its show.
Properties gone, a fresh config's here,
With structured logs, let’s give a cheer!
In dev and prod, the formats shine,
Logging’s now a grand design! 🌟


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.

@nidhi-nair
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

@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 7, 2024
@github-actions
Copy link

github-actions bot commented Nov 7, 2024

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/11718111309.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 37272.
recreate: .

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: 2

🧹 Outside diff range and nitpick comments (2)
app/server/appsmith-server/src/main/resources/logback-spring.xml (2)

3-6: Consider adding environment variable documentation.

The configuration uses environment variables HOSTNAME and APPSMITH_DEPLOYMENT_NAME. Consider adding a comment block documenting these environment variables and their expected values for better maintainability.


12-14: Consider enhancing the dev/test logging pattern.

The current pattern misses log level and logger name, which are useful for debugging. Consider adding these fields:

-          [%d{ISO8601, UTC}] [%t] requestId=%X{X-Appsmith-Request-Id} userEmail=%X{userEmail} traceId=%X{traceId} spanId=%X{spanId} - %m%n
+          [%d{ISO8601, UTC}] [%level] [%logger] [%t] requestId=%X{X-Appsmith-Request-Id} userEmail=%X{userEmail} traceId=%X{traceId} spanId=%X{spanId} - %m%n
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ae7f8c7 and e81b057.

📒 Files selected for processing (3)
  • app/server/appsmith-interfaces/pom.xml (1 hunks)
  • app/server/appsmith-server/src/main/resources/application.properties (0 hunks)
  • app/server/appsmith-server/src/main/resources/logback-spring.xml (1 hunks)
💤 Files with no reviewable changes (1)
  • app/server/appsmith-server/src/main/resources/application.properties
🔇 Additional comments (1)
app/server/appsmith-interfaces/pom.xml (1)

21-26: Consider using the latest stable version 7.4

The dependency addition aligns with the JSON logging objective. However, version 8.0 might be pre-release. Consider using the latest stable version 7.4 unless there's a specific feature requirement.

Comment on lines +27 to +61
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<!-- Add basic information -->
<timestamp>
<fieldName>timestamp</fieldName>
</timestamp>

<contextName/>

<!-- Custom fields for deployment and service instance information -->
<customFields>
{
"deploymentName": "${DEPLOYMENT_NAME}",
"serviceInstanceId": "${SERVICE_INSTANCE_ID}"
}
</customFields>

<!-- Use PatternJsonProvider for structured fields -->
<pattern>
<pattern>
{
"level": "%level",
"logger": "%logger",
"thread": "%thread",
"message": "%message",
"exception": "%exception",
"requestId": "%X{X-Appsmith-Request-Id}",
"userEmail": "%X{userEmail}",
"traceId": "%X{traceId}",
"spanId": "%X{spanId}"
}
</pattern>
</pattern>
</providers>
</encoder>
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

Consider optimizing JSON logging configuration.

The JSON encoder configuration could benefit from stack trace compaction and line separation:

       <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
+        <jsonGeneratorDecorator class="net.logstash.logback.decorate.CompositeJsonGeneratorDecorator">
+          <decorator class="net.logstash.logback.decorate.PrettyPrintingDecorator"/>
+        </jsonGeneratorDecorator>
         <providers>
+          <stackTrace>
+            <throwableConverter class="net.logstash.logback.stacktrace.ShortenedThrowableConverter">
+              <maxDepthPerThrowable>30</maxDepthPerThrowable>
+              <maxLength>2048</maxLength>
+              <shortenedClassNameLength>20</shortenedClassNameLength>
+            </throwableConverter>
+          </stackTrace>

This will prevent stack traces from becoming too verbose in production logs.

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

@github-actions
Copy link

github-actions bot commented Nov 7, 2024

Deploy-Preview-URL: https://ce-37272.dp.appsmith.com

Copy link
Member

@sharat87 sharat87 left a comment

Choose a reason for hiding this comment

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

Can you put in some example log lines in the PR description please? I'm especially interested to see how stack traces show up and if they become unreadable when reading logs as a text file.

@github-actions
Copy link

This PR has not seen activitiy for a while. It will be closed in 7 days unless further activity is detected.

@github-actions github-actions bot added the Stale label Nov 15, 2024
@github-actions
Copy link

This PR has been closed because of inactivity.

@github-actions github-actions bot closed this Nov 22, 2024
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 Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants