Inline ClickHouseTracer hook calls; drop defensive wrappers#782
Inline ClickHouseTracer hook calls; drop defensive wrappers#782Copilot wants to merge 7 commits into
Conversation
|
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
Adds an optional, dependency-free tracer hook family on the client config that mirrors the OpenTelemetry Span API and is invoked around query / command / exec / insert / ping, with all hook calls guarded so a broken tracer cannot break client operations.
Changes:
- New public types/constants (
ClickHouseTracer,ClickHouseTracerSpanAttributes,ClickHouseTracerSpanStatus,ClickHouseSpanNames) inclient-common, re-exported byclientandclient-web; newtracerconfig field. - New
runWithTracerhelper that wraps each lifecycle operation, emits base attributes (db.system,db.namespace,server.address,clickhouse.application, op-specific), updates the server-assignedquery_id, and translates outcomes to OK/ERROR status withrecordException. - Documentation (
docs/howto/tracing.md), CHANGELOG entry under 1.20.0, and unit tests covering all operations, the empty-insert short-circuit, error propagation, and broken-tracer resilience.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/client-common/src/tracing.ts | New public tracer interface, attribute/status types, and span-name constants. |
| packages/client-common/src/tracing_internal.ts | runWithTracer and applyAttributes helpers with WARN-level error swallowing. |
| packages/client-common/src/config.ts | Adds optional tracer config field. |
| packages/client-common/src/client.ts | Wires runWithTracer into query/command/exec/insert/ping and adds baseSpanAttributes. |
| packages/client-common/src/index.ts | Public re-exports of new tracing types/constants. |
| packages/client-node/src/index.ts | Re-exports new tracing surface from @clickhouse/client. |
| packages/client-web/src/index.ts | Re-exports new tracing surface from @clickhouse/client-web. |
| packages/client-common/tests/unit/tracing.test.ts | Unit tests for hook flow, error path, no-tracer passthrough, and broken-tracer resilience. |
| docs/howto/tracing.md | New tracing how-to with OTEL adapter and recording-only examples. |
| CHANGELOG.md | 1.20.0 entry describing the new tracer-hooks API. |
|
Just a suggestion from the outside: you might want to avoid custom tracing boilerplate and refactor this using native Node.js diagnostics_channel. We implemented this exact pattern for telemetry in ydbjs. It allowed us to completely decouple the tracer from the main package and seamlessly inject telemetry via --import. It keeps the core clean and lightweight. https://github.com/ydb-platform/ydb-js-sdk/tree/main/packages/telemetry |
|
@copilot resolve the merge conflicts in this pull request |
Conflicts are resolved in merge commit |
Summary
Reworks the recently-added
tracerhooks API to be a near zero-cost addition: removes therunWithTracer()/safeCallTracer()/logTracerError()wrappers and inlines bare hook calls into each client method. Tracer exceptions now propagate to the caller — users are expected to verify their tracer doesn't throw via a simple e2e test rather than the client carrying defensive plumbing on the hot path. Docs are updated to emphasize the zero-dependency design.client-common/src/client.ts— Each ofquery/command/exec/insert/pingnow opens the span inline, wraps the underlyingconnection.*call in a flattry / catch / finally, and callsthis.tracer?.setAttributes/setStatus/recordException/endSpandirectly. No helper, no per-hook try/catch.client-common/src/tracing_internal.ts— Deleted.client-common/src/tracing.ts,config.ts— JSDoc updated: hooks are inlined on the hot path with no defensive wrapper; implementations must be non-throwing.docs/howto/tracing.md— Calls out zero-dependency / nothing-in-the-bundle / near-zero per-op cost up front; replaces the "broken tracer cannot break the client" guarantee with the new propagation contract.__tests__/unit/tracing.test.ts— Replaced the swallow-exceptions tests with one asserting tracer exceptions propagate and one assertingendSpanstill runs on success.Shape on the hot path:
Checklist
CHANGELOG: Tracer hooks are now invoked inline with no defensive wrapper — exceptions thrown by a user-supplied
ClickHouseTracerpropagate to the caller instead of being swallowed and logged at WARN.