Skip to content
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

bal 2043 winston log error fix only #2379

Merged
merged 5 commits into from
May 16, 2024
Merged

Conversation

liorzam
Copy link
Collaborator

@liorzam liorzam commented May 14, 2024

PR Type

Bug fix

PR Type

enhancement, bug_fix
Previous:
image

Current:
image

image ___

Description

  • Enhanced error handling across various logging services to include more types and detailed information.

  • Updated Sentry service to capture additional error details.

  • Enhancements

    • Improved error logging with additional parameters for better debugging.
    • Enhanced error handling in data analytics with custom error classes.

Summary by CodeRabbit

  • New Features

    • Enhanced error logging capabilities to handle a broader range of error types, including strings and unknown types, providing more detailed stack information.
  • Bug Fixes

    • Improved error handling in various logging services to ensure accurate logging and better debugging information.
  • Refactor

    • Updated logging methods across different services to include additional parameters for more comprehensive error logging.

Copy link

changeset-bot bot commented May 14, 2024

⚠️ No Changeset found

Latest commit: 2c5cd04

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented May 14, 2024

Warning

Rate Limit Exceeded

@liorzam has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 14 minutes and 14 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between ce3c111 and 2c5cd04.

Walkthrough

The recent update enhances error logging capabilities across the Workflow Service by expanding the error method in various logging classes to accept unknown type inputs and improving error handling. Additionally, it updates the subproject commit reference for data migrations.

Changes

File Path Change Summary
services/workflows-service/prisma/data-migrations Updated subproject commit reference.
services/workflows-service/src/common/abstract-logger/abstract-logger.ts
services/workflows-service/src/common/app-logger/app-logger.service.ts
services/workflows-service/src/common/utils/winston-logger/winston-logger.ts
Modified error methods to handle different error types and include additional payload information.
services/workflows-service/src/sentry/sentry.service.ts Added scope.setExtra('error', error); to captureHttpException method.

"In the code where errors roam,
Logs now catch them, bring them home.
Unknown or known, it matters not,
Each mistake is safely caught.
With payloads rich and insights clear,
Our logs now banish every fear.
🐇✨"


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

Copy link
Contributor

PR Description updated to latest commit (d7b12be)

Copy link
Contributor

PR Review 🔍

⏱️ Estimated effort to review [1-5]

3, because the PR involves multiple files and changes in error handling logic across different logging services, which requires careful consideration to ensure that the new error handling mechanisms are correctly implemented without introducing new bugs.

🧪 Relevant tests

No

⚡ Possible issues

Possible Bug: In app-logger.service.ts, when an error is of type string, the stack trace is generated using new Error().stack which might not accurately reflect the location of the original error since it's created at that line.

Possible Bug: In winston-logger.ts, the error handling for string types might not provide sufficient context as it only logs the message without any additional error information or stack trace.

🔒 Security concerns

No

Code feedback:
relevant fileservices/workflows-service/src/common/app-logger/app-logger.service.ts
suggestion      

Consider enhancing the stack trace information for string errors by capturing the stack trace at the point where the error is first created, rather than when it is logged. This can be achieved by modifying how the Error object is instantiated for string errors. [important]

relevant linepayload.stack = new Error().stack;

relevant fileservices/workflows-service/src/common/winston-logger/winston-logger.ts
suggestion      

For consistency and debugging effectiveness, include a stack trace when logging string errors. This can be done by creating an Error object and passing it along with the payload. [important]

relevant linethis.logger.error({ message: error, ...payload });

Copy link
Contributor

PR Code Suggestions ✨

CategorySuggestion                                                                                                                                    Score
Best practice
Add type checking for errors before logging to Sentry to ensure correct error handling

Add error type checking before setting it as an extra in Sentry to prevent potential
issues with non-error objects being logged incorrectly.

services/workflows-service/src/sentry/sentry.service.ts [24]

-scope.setExtra('error', error);
+if (error instanceof Error || typeof error === 'string') {
+  scope.setExtra('error', error);
+}
 
Suggestion importance[1-10]: 8

Why: This suggestion addresses a significant issue by ensuring that only valid error types are logged in Sentry, which is crucial for maintaining the integrity of error logging.

8
Enhancement
Simplify the initialization of the stack property in the payload

Consider initializing the stack property directly in the payload object when the error is
of type string, to simplify the code and enhance readability.

services/workflows-service/src/common/app-logger/app-logger.service.ts [28-33]

-const payload: any = { ...this.getLogMetadata(), logData };
-if (typeof error === 'string') {
-  payload.stack = new Error().stack;
-}
+const payload: any = { ...this.getLogMetadata(), logData, ...(typeof error === 'string' ? { stack: new Error().stack } : {}) };
 
Suggestion importance[1-10]: 7

Why: The suggestion correctly identifies a potential improvement in code readability and simplification by initializing the stack property directly within the payload object.

7
Possible issue
Enhance error logging to handle Error instances properly

Refactor the error handling in WinstonLogger to ensure that the error object is properly
logged when it's not a string, by checking if it's an instance of Error and handling
accordingly.

services/workflows-service/src/common/utils/winston-logger/winston-logger.ts [64-67]

 if (typeof error === 'string') {
   this.logger.error({ message: error, ...payload });
+} else if (error instanceof Error) {
+  this.logger.error({ message: error.message, stack: error.stack, ...payload });
 } else {
   this.logger.error({ error, ...payload });
 }
 
Suggestion importance[1-10]: 6

Why: The suggestion correctly identifies a potential enhancement in error handling by checking if the error is an instance of Error. This could improve the accuracy of the logged information.

6

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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between f7cbe02 and d7b12be.
Files selected for processing (5)
  • services/workflows-service/prisma/data-migrations (1 hunks)
  • services/workflows-service/src/common/abstract-logger/abstract-logger.ts (1 hunks)
  • services/workflows-service/src/common/app-logger/app-logger.service.ts (1 hunks)
  • services/workflows-service/src/common/utils/winston-logger/winston-logger.ts (1 hunks)
  • services/workflows-service/src/sentry/sentry.service.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • services/workflows-service/prisma/data-migrations
Additional comments not posted (4)
services/workflows-service/src/common/abstract-logger/abstract-logger.ts (1)

10-10: Update the error method to accept unknown type.

This change enhances the flexibility of the error method by allowing it to accept any type of error, which can be useful for handling various error scenarios.

services/workflows-service/src/common/app-logger/app-logger.service.ts (1)

28-35: Update the error method to accept unknown type and add stack information for string errors.

This change enhances the flexibility of the error method and ensures that stack information is included for string errors, which can be useful for debugging.

services/workflows-service/src/sentry/sentry.service.ts (1)

24-25: Add error information to the scope when capturing HTTP exceptions.

This change ensures that the error information is included in the Sentry scope, which can be useful for debugging and tracking errors.

services/workflows-service/src/common/utils/winston-logger/winston-logger.ts (1)

63-68: Update the error method to accept an additional payload parameter and handle various error types.

This change enhances the flexibility of the error method by allowing it to accept additional payload data and handle various error types appropriately.

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

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between d7b12be and ce3c111.
Files selected for processing (1)
  • services/workflows-service/src/common/abstract-logger/abstract-logger.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • services/workflows-service/src/common/abstract-logger/abstract-logger.ts

@liorzam liorzam merged commit 48ac2e7 into dev May 16, 2024
9 checks passed
@liorzam liorzam deleted the bal-2043-winston-log-error-fix-only branch May 16, 2024 08:19
@Omri-Levy Omri-Levy mentioned this pull request Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants