Skip to content

Experimental tracing logging for command()#520

Merged
peter-leonov-ch merged 37 commits intomainfrom
tracing-logging-command
Feb 23, 2026
Merged

Experimental tracing logging for command()#520
peter-leonov-ch merged 37 commits intomainfrom
tracing-logging-command

Conversation

@mshustov
Copy link
Copy Markdown
Member

@mshustov mshustov commented Jan 8, 2026

Summary

In this PR:

  • add tracing logs for the Node.js keep-alive connection code with enough context to help with debugging
  • making the log level available in all modules
  • guard log event generation with explicit guards making log-only code free when not used
  • massaged the code to use less of this properties for keeping context and more the params that brings us closer to thread/async safe Go-like context monad
  • parameterized our test even more with "all logs enabled" vs "all logs disabled" config option

Checklist

  • Unit and integration tests covering the common scenarios were added
  • A human-readable description of the changes was provided to include in CHANGELOG

@mshustov mshustov requested a review from Copilot January 8, 2026 20:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds experimental tracing/logging instrumentation to the command execution flow to help diagnose stream handling and timing issues. The changes introduce detailed trace logging at key points during command execution and stream draining operations.

Key changes:

  • Enhanced drainStream function with optional logging parameters to trace stream drain lifecycle events
  • Added comprehensive logging throughout the command execution pipeline including timing metrics and stream state information
  • Modified parameter passing to ensure query_id is propagated consistently through the execution flow

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/client-node/src/connection/stream.ts Added logging to track stream drain operations including chunk counts, bytes received, and duration metrics
packages/client-node/src/connection/node_base_connection.ts Instrumented command execution flow with trace logging for timing, stream states, and error conditions; adjusted query_id handling
Comments suppressed due to low confidence (1)

packages/client-node/src/connection/stream.ts:99

  • The event name in removeListener should be 'close' not 'onClose'. This typo means the close event listener will never be properly removed, potentially causing a memory leak in long-running applications.
    function removeListeners() {
      stream.removeListener('data', dropData)
      stream.removeListener('end', onEnd)
      stream.removeListener('error', onError)
      stream.removeListener('onClose', onClose)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 17, 2026

Codecov Report

❌ Patch coverage is 73.19588% with 26 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...client-node/src/connection/node_base_connection.ts 72.72% 8 Missing and 10 partials ⚠️
packages/client-node/src/connection/stream.ts 70.00% 6 Missing ⚠️
packages/client-common/src/client.ts 71.42% 0 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@peter-leonov-ch
Copy link
Copy Markdown
Collaborator

peter-leonov-ch commented Feb 18, 2026

I've pushed changes that:

  • introduce a verbosity flag (verbose) to allow us fearlessly add as much debugging code as needed without paying for it when not needed
  • gently introducing the Go-like context idiom to allow passing domain and log (and in future tracing) context around; this is potentially replacing/augmenting carrying client params around
  • for logging the actual queries added another logging option unsafeLogUnredactedQueries much like React's dangerouslySetInnerHTML or in general unsafe marker from Rust

If the verbosity flag lifts-off we should address the testing story by running tests with and without verbosity to make sure switching in production is safe. Think of this as performance vs. debug builds in other platforms.

@peter-leonov-ch peter-leonov-ch marked this pull request as ready for review February 18, 2026 09:55
@peter-leonov-ch peter-leonov-ch self-requested a review as a code owner February 18, 2026 09:55
@peter-leonov-ch peter-leonov-ch changed the title DO NOT MERGE. experimental tracing logging for command Experimental tracing logging for command Feb 18, 2026
@peter-leonov-ch
Copy link
Copy Markdown
Collaborator

After a discussion we're moving with adding a log level as an argument instead of verbosity that will do the same but keep the entity count lower.

@peter-leonov-ch
Copy link
Copy Markdown
Collaborator

Ok, log_verbose seems to work in CI. Starting to migrate to the explicit log level.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 14 out of 14 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@peter-leonov-ch
Copy link
Copy Markdown
Collaborator

@copilot check the code in this branch for cases where a call to logger (logWriter, log_writer, logger) can have a query directly or indirectly passed without checking for the unsafeLogUnredactedQueries parameter to be true.

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 19, 2026

@peter-leonov-ch I've opened a new pull request, #565, to work on those changes. Once the pull request is ready, I'll request review from you.

},
database: config.database ?? 'default',
log_writer: new LogWriter(logger, 'Connection', config.log?.level),
log_level: config.log?.level ?? ClickHouseLogLevel.OFF,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

IMO, default should be INFO

Copy link
Copy Markdown
Collaborator

@peter-leonov-ch peter-leonov-ch Feb 23, 2026

Choose a reason for hiding this comment

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

Fair point. OFF seems to be the default for the default LogWriter:

https://github.com/ClickHouse/clickhouse-js/blob/main/packages/client-common/src/logger.ts#L85

Do you want to change it and converge both to INFO?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Copilot confirms: https://github.com/ClickHouse/clickhouse-js/tasks/9ca5c8b1-2b5d-48c3-bcab-086836eee881?author=peter-leonov-ch

The current default is OFF

And also warns about suppressed warnings:

The current default log level is OFF. This means that when users create a client with no arguments, all logging is disabled - including warnings about deprecated configuration options.

Maybe we change the default to WARN instead and make sure the log levels in to code use WARN for noteworthy bits?

With WARN as default, I need to check what logs a successful ping() call generates. Looking at the other integration test, a successful ping produces a debug log, which would be suppressed at WARN level.

Looks like Copilot can draft something here for "free" 🙂

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Maybe we change the default to WARN instead and make sure the log levels in to code use WARN for noteworthy bits?

do we have any logs with info level?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A quick grep shoes we do not.

@peter-leonov-ch peter-leonov-ch merged commit 81d0e22 into main Feb 23, 2026
92 of 94 checks passed
@peter-leonov-ch peter-leonov-ch deleted the tracing-logging-command branch February 23, 2026 17:25
peter-leonov-ch added a commit that referenced this pull request Feb 25, 2026
Waiting on:
* #520

## Summary

* adding tests to cover for the tricky connection related situations
* augment logs with context required for debugging

## Checklist

Delete items not relevant to your PR:

- [x] Unit and integration tests covering the common scenarios were
added
- [x] A human-readable description of the changes was provided to
include in CHANGELOG

---------

Co-authored-by: Copilot <[email protected]>
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.

4 participants