Skip to content

Conversation

@fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Mar 9, 2025

pick from ali-sdk#122

closes #9

Summary by CodeRabbit

  • New Features
    • Introduced configurable logging capabilities for database operations. Users can now enable logging to capture SQL queries along with execution details and error information.
  • Tests
    • Expanded test coverage validates the new logging functionality, ensuring queries are accurately captured and formatted during execution.

@coderabbitai
Copy link

coderabbitai bot commented Mar 9, 2025

Walkthrough

The changes add logging functionality across multiple modules. The RDSClient and Operator classes now support a logging property that can be set during instantiation. In addition, a new Logging type is defined and integrated into client options and handler signatures. A test suite was also added to verify that SQL queries are logged correctly.

Changes

File(s) Change Summary
src/client.ts, src/operator.ts, src/types.ts Integrated logging support: added logging property in classes, a setLogging method in Operator, defined a new Logging type, and updated handler signatures.
test/client.test.ts Added a logging test suite to validate that SQL queries are correctly logged with proper formatting and thread ID checks.

Sequence Diagram(s)

sequenceDiagram
    participant Client as RDSClient
    participant Conn as Connection
    Client->>Conn: getConnection()
    Conn->>Client: Return connection object
    Client->>Conn: setLogging(logging)
Loading
sequenceDiagram
    participant Op as Operator
    participant Logger as Logging Function
    Op->>Op: query(sql, threadId)
    alt Logging is defined
        Op->>Logger: Invoke logging(sql, threadId)
    else No logging
        Op--)Op: Continue execution
    end
    Op->>Op: Process query result
Loading

Poem

I'm a bunny bouncing through the code,
Hopping on logs with a perky mode.
SQL tales whisper in every line,
Like crunchy carrots, simply divine.
I celebrate these hops—all in a log-filled rhyme!

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/operator.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-eggache".

(The package "eslint-plugin-eggache" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-eggache@latest --save-dev

The plugin "eslint-plugin-eggache" was referenced from the config file in ".eslintrc » eslint-config-egg/typescript » ./index.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

src/client.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-eggache".

(The package "eslint-plugin-eggache" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-eggache@latest --save-dev

The plugin "eslint-plugin-eggache" was referenced from the config file in ".eslintrc » eslint-config-egg/typescript » ./index.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

src/types.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-eggache".

(The package "eslint-plugin-eggache" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-eggache@latest --save-dev

The plugin "eslint-plugin-eggache" was referenced from the config file in ".eslintrc » eslint-config-egg/typescript » ./index.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

  • 1 others

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between db72b8e and fc6cf49.

📒 Files selected for processing (4)
  • src/client.ts (3 hunks)
  • src/operator.ts (4 hunks)
  • src/types.ts (2 hunks)
  • test/client.test.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: Node.js / Test (ubuntu-latest, 22, mysql@8)
  • GitHub Check: Node.js / Test (ubuntu-latest, 22, mysql@9)
  • GitHub Check: Node.js / Test (ubuntu-latest, 22, mysql@5)
  • GitHub Check: Node.js / Test (ubuntu-latest, 20, mysql@9)
  • GitHub Check: Node.js / Test (ubuntu-latest, 20, mysql@5)
  • GitHub Check: Node.js / Test (ubuntu-latest, 18, mysql@9)
  • GitHub Check: Node.js / Test (ubuntu-latest, 18, mysql@8)
  • GitHub Check: Node.js / Test (ubuntu-latest, 18, mysql@5)
  • GitHub Check: Node.js / Test (ubuntu-latest, 16, mysql@9)
  • GitHub Check: Node.js / Test (ubuntu-latest, 16, mysql@8)
  • GitHub Check: Node.js / Test (ubuntu-latest, 16, mysql@5)
🔇 Additional comments (10)
src/operator.ts (4)

12-12: Import of new Logging type added

This line imports the new Logging type which is used for the logging functionality being added to the codebase.


24-24: New logging property added to Operator class

A new optional property logging of type Logging is added to the Operator class to store the logging function.


49-51: Added setLogging method to configure logging

This method allows for setting the logging function on an operator instance, enabling proper propagation of logging configuration from client to connections.


90-92: Added logging implementation in query method

Good implementation of logging feature that:

  1. Checks if the logging property is a function before using it
  2. Passes the SQL query and additional context (threadId) to the logging function

This will allow for flexible logging implementations by consumers of this library.

src/client.ts (3)

70-70: Updated constructor parameter destructuring to include logging

The constructor now extracts the logging property from options, allowing it to be passed to the client during initialization.


111-111: Storing the logging property on the client instance

The logging property is properly stored on the client instance, making it available for use in other methods.


181-181: Propagating logging to connection instances

This line ensures that each new connection receives the logging configuration from the client, maintaining logging consistency across all database operations.

src/types.ts (2)

12-12: Added logging property to RDSClientOptions interface

This change extends the RDSClientOptions interface to include an optional logging property, enabling users to specify a logging function when creating an RDS client.


72-72: Added Logging type definition

The Logging type is defined as a function that takes a message string and variadic arguments, following a common pattern for logging functions. This allows for flexible logging implementations, including console logging, custom formatters, and integration with existing logging libraries.

test/client.test.ts (1)

341-363: Added test suite for logging functionality

Great test implementation that:

  1. Creates a mock logging function to capture SQL queries
  2. Verifies both simple queries and queries with parameter substitution
  3. Checks that thread ID is properly passed to the logging function
  4. Validates the exact formatted SQL output

These tests provide good coverage for the new logging feature and will help prevent regressions.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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 generate docstrings to generate docstrings for this 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.

@codecov
Copy link

codecov bot commented Mar 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.46%. Comparing base (7339921) to head (fc6cf49).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #11      +/-   ##
==========================================
+ Coverage   98.44%   98.46%   +0.01%     
==========================================
  Files          10       10              
  Lines        1159     1174      +15     
  Branches      238      240       +2     
==========================================
+ Hits         1141     1156      +15     
  Misses         18       18              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fengmk2 fengmk2 merged commit 4b97cb0 into master Mar 9, 2025
18 checks passed
@fengmk2 fengmk2 deleted the loging branch March 9, 2025 08:31
fengmk2 pushed a commit that referenced this pull request Mar 9, 2025
[skip ci]

## [1.3.0](v1.2.2...v1.3.0) (2025-03-09)

### Features

* add custom logging ([ali-sdk#122](https://github.com/node-modules/rds/issues/122)) ([#11](#11)) ([4b97cb0](4b97cb0))
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.

pick add custom logging

3 participants