fix(common-utils): route ClickHouse query debug logging through an injectable logger#2679
fix(common-utils): route ClickHouse query debug logging through an injectable logger#2679truehazker wants to merge 6 commits into
Conversation
BaseClickhouseClient.logDebugQuery dumped the full SQL of every ClickHouse query to the console unconditionally, outside the pino logger, so HYPERDX_LOG_LEVEL could not suppress it and API pod logs filled with per-query spam. Query logging is now off by default and enabled only with HYPERDX_LOG_QUERIES=true. The gate is one line in the shared base-class method every query path routes through, reusing the existing isNode helper so browser bundles stay silent. docker-compose passes the variable through to the all-in-one app container, and .env documents the toggle next to HYPERDX_LOG_LEVEL. Closes hyperdxio#2416
|
@truehazker is attempting to deploy a commit to the HyperDX Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: a550f21 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Greptile SummaryThis PR makes ClickHouse query logging opt-in through an injectable logger. The main changes are:
Confidence Score: 5/5This looks safe to merge.
|
| Filename | Overview |
|---|---|
| packages/common-utils/src/clickhouse/index.ts | Adds the logger option, exports the logger types, and makes query logging silent unless a logger is passed. |
| packages/common-utils/src/clickhouse/node.ts | Updates the node query path to call the renamed query logging method. |
| packages/common-utils/src/clickhouse/browser.ts | Updates the browser query path to call the renamed query logging method. |
| packages/app/src/clickhouse.ts | Injects the default query logger for app dev and local-mode clients while preserving caller overrides. |
| packages/cli/src/api/client.ts | Removes the old CLI query-log override that no longer applies. |
| packages/common-utils/src/clickhouse/tests/index.test.ts | Adds unit tests for the new ClickHouse query logging behavior. |
| .changeset/gate-clickhouse-query-debug-log.md | Adds patch changesets for the packages affected by the logging change. |
Reviews (4): Last reviewed commit: "Merge branch 'main' into claude/gate-cli..." | Re-trigger Greptile
Deep ReviewScope: PR #2679 — gate ClickHouse per-query SQL debug logging behind Intent: ✅ No critical issues found. The guard sits on a 🔵 P3 nitpicks (2)
Reviewers (2): ce-correctness-reviewer, orchestrator-analysis. Testing gaps:
|
The passthrough referenced ${HYPERDX_LOG_QUERIES} while .env only ships the
variable commented out, so every `docker compose up` printed a "variable is
not set" warning. Use the :- default-empty form; the gate still requires an
explicit 'true', so behavior is unchanged.
The disabled-state test asserted five logDebugQuery calls behind a single
expect, so a failure would not name the offending value. Each non-'true'
value ('', 'false', '1', 'TRUE') and the unset case now get their own test,
matching the it.each idiom already used in this file.
| query: string, | ||
| query_params: Record<string, any> = {}, | ||
| ): void { | ||
| if (!isNode || process.env.HYPERDX_LOG_QUERIES !== 'true') return; |
There was a problem hiding this comment.
The SQL debugging logs are useful on the app side. What do you think about passing a custom logger (e.g. Pino for the API) through the client instead? We could add a customLogger option here:
hyperdx/packages/common-utils/src/clickhouse/index.ts
Lines 624 to 633 in 7a4ad98
ref: https://clickhouse.com/docs/integrations/javascript#logging-nodejs-only
There was a problem hiding this comment.
I agree, I just didn't want to deal with nextjs env vars for logging purposes, but this way they're not the issue anymore. Let me dig into your proposal first, I'll update my PR once I check all the consumers (app, api, cli) and I'll leave a note in this thread.
There was a problem hiding this comment.
Turned out nicely, updates are pushed, PR description updated. I've changed the logging level to trace by default to keep it silent and loud once tuning the log level on purpose. Let me know if renaming/level changing was extra and not needed. But I guess it makes things cleaner
…le customLogger Rework of the query-log gate per review feedback on hyperdxio#2679: instead of a dedicated env var, `ClickhouseClientOptions` now accepts an optional `customLogger` (the `Logger` interface from `@clickhouse/client-common`), and `logQuery` (was `logDebugQuery`) emits through it at `trace` — silent whenever no logger is injected. - The app injects the re-exported `DefaultLogger` in dev and local mode, where the devtools console is the only place to see query SQL; prod stays silent so consoleCapture can't ship SQL to telemetry. - The API intentionally injects nothing: silent by default fixes the log flooding, and a pino adapter can be passed at any client later (trace-level emit keeps HYPERDX_LOG_LEVEL=debug deployments quiet). - The CLI's silencing override is now dead code and removed. - HYPERDX_LOG_QUERIES is gone from .env and docker-compose.
…ub.com/truehazker/hyperdx into claude/gate-clickhouse-query-debug-log # Conflicts: # docker-compose.yml # packages/common-utils/src/clickhouse/__tests__/index.test.ts
Summary
BaseClickhouseClient.logDebugQuerywrote the full SQL of every ClickHouse query to stdout via rawconsole.debug— unconditionally and outside the pino logger, soHYPERDX_LOG_LEVELcannot suppress it. In self-hosted deployments with log capture this dominates pod logs andotel_logsretention (#2416).This PR makes query logging silent by default and injectable, per review feedback:
ClickhouseClientOptionsaccepts an optionalcustomLogger(theLoggerinterface from@clickhouse/client-common), and the renamedlogQueryemits through it — no logger, no output. The gate stays in the shared base-class method that every query path (node and browser clients) already routes through.Per consumer:
DefaultLoggerin dev and local mode, where queries hit ClickHouse directly and the devtools console is the only place to see SQL. Production stays silent so the browser SDK's consoleCapture can't ship query SQL to telemetry.logDebugQuery-silencing override became dead code and is removed.Emitting at
trace— rather thandebug— is deliberate:.envfiles already setHYPERDX_LOG_LEVEL=debug, so a future pino adapter emitting atdebugwould resurrect the exact spam this PR removes.tracekeeps it an explicit opt-in even once a logger is wired.Also included: unit tests for the silent-by-default, injected-logger, and param-interpolation cases (
yarn ci:unitinpackages/common-utils), a changeset, and removal of the earlierHYPERDX_LOG_QUERIESplumbing from.envand docker-compose.Maintainer notes:
@hyperdx/apiwithout source changes: it bundles common-utils, so released API images stop emitting the per-query dump.How to test on Vercel preview
N/A — backend logging behavior; in dev/local-mode builds, query SQL appears in the devtools console (at Verbose level).
References