Skip to content

feat(telemetry): add phase 1 telemetry foundation - #266

Merged
jay-xiao446 merged 2 commits into
mainfrom
kernel-telemetry-phase-1
Aug 18, 2026
Merged

jay-xiao446 merged 2 commits into
mainfrom
kernel-telemetry-phase-1

Conversation

@jay-xiao446

@jay-xiao446 jay-xiao446 commented Aug 18, 2026 •

Copy link
Copy Markdown
Collaborator

🥞 Stacked PR

Use this link to review incremental changes.


Summary

This PR is Phase 1 of the telemetry stack. It contains only the foundational telemetry model contract and local test-support exports.

Phase 1:

  • adds telemetry model/request serialization aligned with the Databricks SQL driver telemetry shape
  • adds local test-support exports for capturing telemetry without live service access
  • keeps the code paths local to the kernel crate so later phases can build on the same model without exposing test-only helpers as public API

Phase 2 connection telemetry has been split into the next stack PR.

Flow

flowchart LR
    model[Telemetry Models]
    request[TelemetryRequest]
    exporter[TelemetryExporter trait]
    capture[Capturing Test Exporter]
    tests[Serialization + capture tests]

    model --> request
    request --> exporter
    exporter --> capture
    capture --> tests
Loading

Stack

gitGraph
    commit id: "main"
    branch kernel-telemetry-phase-1
    checkout kernel-telemetry-phase-1
    commit id: "phase 1: model contract"
    commit id: "phase 1: local exports"
Loading

Validation

Previously run on this stack:

  • cargo test telemetry --lib --locked
  • git diff --check

Signed-off-by: Jay Xiao <jay.xiao@databricks.com>
Signed-off-by: Jay Xiao <jay.xiao@databricks.com>

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: 1 Medium · 3 Low

Solid, well-tested telemetry foundation with clean fail-open wiring and good serialization-shape coverage. One medium concern: sanitize_error sources DriverErrorInfo.stack_trace from the 5-char sql_state, which mislabels the field and drops the actual error detail on the paths that hit it (see F1). A few low-severity notes on the always-disabled-in-production gate, unbounded in_flight handle growth, and a runtime_version that can never populate. Nits: several DriverConnectionParameters values (mode/enable_arrow/enable_direct_results/auto_commit) are hardcoded rather than derived from actual session config — fine for the foundation phase but worth revisiting as those knobs become real.

Comment thread src/telemetry/runtime.rs Outdated
fn sanitize_error(error: &KernelError) -> DriverErrorInfo {
DriverErrorInfo {
error_name: Some(error.code.slug().to_string()),
stack_trace: error.sql_state.clone(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium — sanitize_error populates DriverErrorInfo.stack_trace from error.sql_state. That is a semantic mismatch: sql_state is a 5-character SQLSTATE code (e.g. 42601), not a stack trace. Two consequences:

  1. For the common error paths that flow through this code (a failed delete_session, i.e. transport/network/HTTP errors), sql_state is almost always None, so stack_trace will be empty and the error telemetry carries only error_name (the code slug) — no descriptive detail at all.
  2. When sql_state is present, it is mislabeled as a stack trace, which will confuse anyone reading the telemetry against the documented envelope shape.

The Error type carries richer, more relevant fields for diagnostics — message, diagnostic_info, error_code — that would be more appropriate here (subject to whatever redaction policy applies). At minimum, sourcing stack_trace from sql_state looks like a copy/paste of the wrong field.

Comment thread src/telemetry/runtime.rs Outdated
session_id: Some(self.session.session_id.clone()),
system_configuration: Some(self.session.system_configuration.clone()),
driver_connection_params: Some(self.session.connection_params.clone()),
auth_type: Some(self.session.auth_type.clone()),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Low — In non-test builds test_or_noop_exporter always returns None, so from_config returns TelemetryRuntime::disabled() even when the caller set TelemetryConfig { enabled: true, .. }. This is expected for the phase-1 foundation (no production exporter is wired yet), but a user who opts in via the public SessionBuilder::telemetry(..) + enabled: true gets a completely silent no-op with no log line indicating telemetry was dropped. Consider a one-time tracing::debug!/warn! when enabled is true but no exporter is available, so the silent-disable is diagnosable once real exporters land.

Comment thread src/telemetry/client.rs Outdated
pub(super) fn enqueue(&self, log: TelemetryFrontendLog) {
let batch = {
let mut pending = self.pending.lock().expect("poisoned telemetry queue");
pending.push(log);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Low — enqueue pushes every spawned batch-export JoinHandle into in_flight, but handles are only removed in drain_in_flight(), which runs solely from flush_bounded() (session close). For a long-lived session that flushes many batches before close, the in_flight vector grows monotonically with completed-but-not-joined handles and is never pruned until close. For phase-1 connection telemetry (one create + one delete per session) this is negligible, but the client is generic and later phases enqueue per-statement events. Consider retaining only unfinished handles (e.g. drop finished ones opportunistically on enqueue) to bound memory over a session's lifetime.

Comment thread src/telemetry/runtime.rs Outdated
let defaults = DriverSystemConfiguration {
driver_version: Some(env!("CARGO_PKG_VERSION").to_string()),
runtime_name: Some("rust".to_string()),
runtime_version: option_env!("RUSTC_VERSION").map(str::to_string),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Low — runtime_version is read from option_env!("RUSTC_VERSION"), but nothing in the repo sets that environment variable at build time (no build.rs emits it; rustc_version appears only as a transitive lock entry). option_env! is evaluated at compile time, so this field will always be None and runtime_version will never be emitted. Either wire up a build.rs that exports RUSTC_VERSION (via the rustc_version crate already in the lock graph) or drop the field until it can be populated, to avoid a field that silently never appears.

@jay-xiao446

Copy link
Copy Markdown
Collaborator Author

/trigger all

@oss-reviewer-bot oss-reviewer-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: 1 Low

Solid foundational PR — verified against the reference C# driver's proto schema/models: wrapper field casing (uploadTime/protoLogs camelCase, workspace_id/frontend_log_event_id snake_case), enum SCREAMING_SNAKE_CASE values, and the full field set all match. One low note: the inner sql_driver_log int64 fields serialize as JSON numbers whereas the reference's proto3-JSON path emits them as strings — likely benign since proto parsers accept both, but worth a conscious decision given the PR's parity goal.

Comment thread src/telemetry/models.rs
#[serde(skip_serializing_if = "Option::is_none")]
pub error_info: Option<DriverErrorInfo>,
#[serde(skip_serializing_if = "Option::is_none")]
pub operation_latency_ms: Option<i64>,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Low — The inner OssSqlDriverTelemetryLog and its nested messages are serialized here with plain serde_json, which emits 64-bit integers (operation_latency_ms, *_latency_millis, chunk_id, retry_count, http_connection_pool_size, socket_timeout, etc.) as JSON numbers. The reference C# driver serializes this same message through the protobuf JsonFormatter (ProtoJsonConverter.cs), and the proto3 JSON mapping encodes int64/uint64/fixed64 fields as JSON strings (e.g. "operation_latency_ms": "25", not 25). So the on-wire shape of sql_driver_log diverges from the reference for every 64-bit field.

This is likely benign in practice — the proto3 JSON spec requires parsers to accept both a number and a decimal string for int64, so a compliant backend parser should ingest the numeric form. But since this PR's stated goal is to mirror "the SQL driver telemetry envelope used by the ADBC and JDBC drivers," it's worth a deliberate decision + a note (and ideally a test asserting the chosen int64 representation), rather than an incidental difference. Note this only affects fields inside sql_driver_log; the wrapper workspace_id/timestamp_millis are number-typed in the reference too (System.Text.Json), so those already match.

@jay-xiao446

Copy link
Copy Markdown
Collaborator Author

/merge

@jay-xiao446
jay-xiao446 added this pull request to the merge queue Aug 18, 2026
Merged via the queue into main with commit 274c7c3 Aug 18, 2026
19 of 20 checks passed
@jay-xiao446
jay-xiao446 deleted the kernel-telemetry-phase-1 branch August 20, 2026 20:44

This branch was previously deployed

1 inactive deployment
azure-prod — f2146471 Deployed Aug 18, 2026 by oss-reviewer-bot[bot] via followup #613
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.

1 participant