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

feat: Adding extensive loggers #224

Merged
merged 1 commit into from
Oct 14, 2024
Merged

Conversation

Ashutosh619-sudo
Copy link
Contributor

@Ashutosh619-sudo Ashutosh619-sudo commented Oct 8, 2024

https://app.clickup.com/1864988/v/l/6-901603904304-1

Summary by CodeRabbit

  • New Features

    • Introduced enhanced logging functionality for better traceability of API interactions.
    • Added debug and info logging for various API request and response scenarios.
  • Bug Fixes

    • Improved error logging to capture HTTP errors more effectively.

Copy link

coderabbitai bot commented Oct 8, 2024

Walkthrough

The changes introduce logging functionality to the Client class in the sage_desktop_sdk/core/client.py file. A logger is instantiated and utilized across various methods to log debug and info messages related to API requests and responses. This includes logging for GET and POST requests, capturing both successful and error responses to improve traceability and assist in debugging.

Changes

File Change Summary
sage_desktop_sdk/core/client.py Added logging functionality: created a logger, added debug and info logging in _query_get_all_generator, _query_get_all, _query_get_by_id, and _post_request methods for API interactions.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API
    Client->>API: GET request
    API-->>Client: Response
    Client->>Client: Log response
    Client->>API: POST request
    Client->>Client: Log payload
    API-->>Client: Response
    Client->>Client: Log response
Loading

Poem

In the code where rabbits hop,
A logger now will never stop.
With each request, both big and small,
It captures tales of one and all.
Debugging made a joyful dance,
In logs, we find our second chance! 🐇✨


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.

CodeRabbit Configuration 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

github-actions bot commented Oct 8, 2024

Tests Skipped Failures Errors Time
157 0 💤 0 ❌ 0 🔥 12.144s ⏱️

Copy link

@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

🧹 Outside diff range and nitpick comments (4)
sage_desktop_sdk/core/client.py (4)

125-126: Improve logging practices for security and consistency

While adding logging is beneficial, consider the following improvements:

  1. On line 125, avoid logging the full response text as it may contain sensitive information. Instead, log only necessary details or mask sensitive data.

  2. On line 138, use request_url instead of url to log the full URL for consistency with the debug log.

Consider applying these changes:

-logger.debug('Response for get request for url: %s, %s', request_url, response.text)
+logger.debug('Response for get request for url: %s, status: %s', request_url, response.status_code)

-logger.info('Response for get request for url: %s, %s', url, err.response.text)
+logger.info('Response for get request for url: %s, status: %s', request_url, err.response.status_code)

Also applies to: 138-138


170-170: Improve logging practices for security and consistency

Similar to the previous comment, consider the following improvements:

  1. On line 170, avoid logging the full response text as it may contain sensitive information.

  2. On line 174, use request_url instead of url to log the full URL for consistency.

Consider applying these changes:

-logger.debug('Response for get request for url: %s, %s', request_url, response.text)
+logger.debug('Response for get request for url: %s, status: %s', request_url, response.status_code)

-logger.info('Response for get request for url: %s, %s', url, response.text)
+logger.info('Response for get request for url: %s, status: %s', request_url, response.status_code)

Also applies to: 174-174


240-240: Enhance logging security and consistency in POST requests

While the addition of logging is beneficial, consider the following security and consistency improvements:

  1. On line 240, avoid logging the full payload as it may contain sensitive information. Instead, log only necessary details or mask sensitive data.

  2. On line 243, avoid logging the full response text for the same reason.

  3. On line 246, maintain consistency with error logging in other methods.

Consider applying these changes:

-logger.debug('Payload for post request: %s', data)
+logger.debug('Sending POST request to: %s', request_url)

-logger.debug('Response for post request: %s', response.text)
+logger.debug('Response for POST request to %s, status: %s', request_url, response.status_code)

-logger.info('Response for post request: %s', response.text)
+logger.info('Error response for POST request to %s, status: %s', request_url, response.status_code)

Also applies to: 243-243, 246-246


Line range hint 1-258: Consider adding logging configuration options

The addition of logging across all methods in the Client class is a great improvement for traceability and debugging. However, to make the logging more flexible for users of the SDK, consider adding configuration options.

Implement a way for users to configure logging levels and handlers. This could be done by:

  1. Adding a method to the Client class to set the logging level:
def set_log_level(self, level):
    logger.setLevel(level)
  1. Providing documentation on how users can configure their own logging handlers if they want more control over log output.

This will allow users to adjust the verbosity of logs based on their needs, from silencing all logs to capturing detailed debug information.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 2adf3ec and bc88b50.

📒 Files selected for processing (1)
  • sage_desktop_sdk/core/client.py (7 hunks)
🧰 Additional context used
🔇 Additional comments (2)
sage_desktop_sdk/core/client.py (2)

2-2: LGTM: Logging setup looks good

The addition of the logging import and the logger initialization using logging.getLogger(__name__) follows best practices for setting up logging in Python modules.

Also applies to: 18-18


206-206: Apply consistent logging improvements

The logging changes in this method are identical to those in the _query_get_all method. Please apply the same improvements suggested in the previous comment to these lines as well.

Also applies to: 210-210

@Ashutosh619-sudo Ashutosh619-sudo merged commit 3cde4d7 into master Oct 14, 2024
3 checks passed
Ashutosh619-sudo added a commit that referenced this pull request Oct 14, 2024
Ashutosh619-sudo added a commit that referenced this pull request Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants