Skip to content

feat(telemetry): wire connection telemetry - #267

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

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

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

Separates Phase 2 from the Phase 1 foundation in the telemetry stack.

This PR wires connection-level telemetry on top of the Phase 1 model/test-support contract:

  • expands telemetry configuration used by session construction
  • adds TelemetryRuntime and connection telemetry context/client wiring
  • emits create-session and delete-session operation telemetry on session open/close
  • supports binding-provided DriverSystemConfiguration with kernel defaults
  • keeps telemetry export failures fail-open and isolated from session behavior

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"
    branch kernel-telemetry-phase-2
    checkout kernel-telemetry-phase-2
    commit id: "phase 2: connection telemetry"
Loading

Connection Flow

sequenceDiagram
    participant User
    participant Session
    participant Transport
    participant Runtime as TelemetryRuntime
    participant Client as TelemetryClient
    participant Exporter as TelemetryExporter

    User->>Session: open(config)
    Session->>Transport: create_session(...)
    Transport-->>Session: session_id
    Session->>Runtime: emit CREATE_SESSION
    Runtime->>Client: enqueue event
    Session-->>User: Session

    User->>Session: close()
    Session->>Transport: delete_session(session_id)
    Session->>Runtime: emit DELETE_SESSION
    Runtime->>Client: bounded flush
    Client->>Exporter: export TelemetryRequest
    Exporter-->>Client: ok/error swallowed
Loading

Validation

Previously run on this stack:

  • cargo test telemetry --lib --locked
  • cargo test c_abi::session --lib --locked
  • git diff --check

@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: 2 Low

Looks good — clean connection-telemetry wiring with proper fail-open semantics (export failures swallowed, close() succeeds regardless) and solid test coverage across disabled/enabled/custom-config/failure cases. Two low-severity notes: build_connection_params emits several hardcoded/reconstructed values that can misreport the real session config, and in_flight JoinHandles are only reaped at close (a latent unbounded-growth for future high-volume telemetry paths, not triggered by connection events in this PR). Nit: in non-test builds test_or_noop_exporter always returns None, so TelemetryConfig { enabled: true } is currently an intentional no-op — this is clearly staged per the module doc, just worth keeping visible until the production exporter lands.

Scope: reviewed as a stacked increment (f214647..head); the parent's changes are reviewed on the parent PR.

Comment thread src/telemetry/runtime.rs
os_version: override_config.os_version.or(defaults.os_version),
os_arch: override_config.os_arch.or(defaults.os_arch),
driver_name: override_config.driver_name.or(defaults.driver_name),
client_app_name: override_config.client_app_name.or(defaults.client_app_name),

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 — build_connection_params reports several connection facts as hardcoded constants rather than reading them from the actual session config:

  • http_path is reconstructed as /sql/1.0/warehouses/{warehouse_id} instead of using the path the connection was actually configured with.
  • mode is always Sea.
  • auto_commit is always Some(true), even though a caller can open a session and disable autocommit (set_autocommit), and enable_arrow / enable_direct_results are unconditionally true.

This is telemetry-only metadata (no functional impact), but it means the emitted DriverConnectionParameters can misreport the session's real configuration, which undercuts the value of the telemetry. Consider threading the real values through, or dropping fields you can't yet source accurately rather than emitting a fixed guess.

Comment thread src/telemetry/client.rs
self.in_flight
.lock()
.expect("poisoned telemetry in-flight queue")
.push(handle);

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 — Completed export JoinHandles pushed into in_flight are only ever reaped by flush_bounded (i.e. at session close). For a long-lived session that spawns many batches, the in_flight vector accumulates already-finished handles for the entire session lifetime, growing without bound. Connection telemetry alone won't trigger this (only 2 events/session vs. batch_size 200, so no batch spawn fires here), but once statement/result-stream telemetry lands on this path it will. Consider retaining only unfinished handles (e.g. retain(|h| !h.is_finished())) when enqueuing, so completed tasks are dropped incrementally.

- build Phase 2 connection telemetry on top of the split Phase 1
telemetry modules
- expand TelemetryConfig with connection telemetry knobs
- expose top-level SessionBuilder/SessionConfig driver system
configuration for binding-provided driver identity
- add TelemetryRuntime, no-op/real connection telemetry, and minimal
in-memory export queue
- emit CREATE_SESSION and DELETE_SESSION telemetry through
Session::open/close
- add tests for disabled telemetry, close flush, fail-open exporter
errors, and driver system configuration defaults

```mermaid
flowchart LR
    TelemetryConfig[SessionConfig.telemetry] --> Open[Session::open]
    DriverSystem[SessionConfig.driver_system_configuration] --> Open
    Open --> Runtime[runtime.rs\nTelemetryRuntime]
    Runtime --> NoOp[runtime.rs\nNoOpConnectionTelemetry]
    Runtime --> Real[runtime.rs\nRealConnectionTelemetry]
    Real --> Context[runtime.rs\nTelemetrySessionContext]
    DriverSystem --> Context
    Real --> Client[client.rs\nTelemetryClient]
    Client --> Queue[In-memory pending queue]
    Client --> Exporter[exporter.rs\nTelemetryExporter]
    Exporter --> Request[models.rs\nTelemetryRequest protoLogs]
    Runtime --> Models[models.rs\nOssSqlDriverTelemetryLog]
```

```mermaid
sequenceDiagram
    participant User
    participant Session
    participant Transport
    participant Runtime as TelemetryRuntime
    participant Client as TelemetryClient
    participant Exporter as TelemetryExporter

    User->>Session: open(config)
    Session->>Transport: create_session(...)
    Transport-->>Session: session_id
    Session->>Runtime: emit CREATE_SESSION
    Runtime->>Client: enqueue event
    Session-->>User: Session

    User->>Session: close()
    Session->>Transport: delete_session(session_id)
    Transport-->>Session: ok/error
    Session->>Runtime: emit DELETE_SESSION
    Runtime->>Client: bounded flush
    Client->>Exporter: export TelemetryRequest
    Exporter-->>Client: ok/error swallowed
    Session-->>User: delete_session result
```

- cargo +stable fmt --all --check
- git diff --check
- cargo test telemetry --lib --locked
- cargo test --locked
- cargo clippy --lib --locked -- -D warnings
- cargo clippy --all-targets --locked -- -D warnings

---------

Signed-off-by: Jay Xiao <jay.xiao@databricks.com>
Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>
Co-authored-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.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 · 1 Low

Solid, well-tested plumbing for connection telemetry — fail-open behavior is verified and event ordering is covered. Two non-blocking concerns: sanitize_error maps SQLSTATE into the stack_trace field (semantic mismatch, drops real diagnostic context) and build_connection_params hardcodes mode/auto_commit/enable_arrow rather than reflecting actual config. Note also (by design for this phase) that test_or_noop_exporter returns None in non-test builds, so enabled: true emits nothing in production until the production exporter lands in a later phase — expected given the stacked-PR scope.

Comment thread src/telemetry/runtime.rs
}
}

fn auth_flow(auth: &AuthConfig) -> Option<DriverAuthFlow> {

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 stuffs the 5-character SQLSTATE into the stack_trace field:

fn sanitize_error(error: &KernelError) -> DriverErrorInfo {
    DriverErrorInfo {
        error_name: Some(error.code.slug().to_string()),
        stack_trace: error.sql_state.clone(),
    }
}

This is a semantic mismatch — telemetry consumers reading stack_trace will get a value like 42P01, not a trace. KernelError already carries a field intended for exactly this: diagnostic_info (documented as "Multi-line text with stack frames or operator context"). Consider mapping stack_trace from diagnostic_info (or leaving it None) and surfacing SQLSTATE elsewhere, so the field's meaning matches the ADBC/JDBC envelope other drivers emit. As written the actual failure context (error.message, diagnostic_info) is dropped entirely and the one field that is populated is misleading.

Comment thread src/telemetry/runtime.rs
auth: &AuthConfig,
) -> DriverConnectionParameters {
DriverConnectionParameters {
http_path: Some(format!("/sql/1.0/warehouses/{}", connection.warehouse_id)),

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 — build_connection_params hardcodes several connection attributes that are actually configurable: mode: DriverMode::Sea, auto_commit: Some(true), enable_arrow: Some(true), enable_direct_results: Some(true). SessionConfig exposes a transport: Option<TransportMode> and autocommit can be toggled via set_autocommit, so this telemetry will misreport those parameters when the caller diverges from the defaults (e.g. Thrift transport or autocommit off). Since these are captured once at session-open time this may be acceptable for now, but the hardcoded mode/auto_commit will silently drift from reality. Worth a comment noting these are placeholders, or wiring them from the real config.

Merged via the queue into main with commit 302a076 Aug 18, 2026
21 of 22 checks passed
@jay-xiao446
jay-xiao446 deleted the kernel-telemetry-phase-2 branch August 20, 2026 20:44

This branch was previously deployed

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