feat(kernel): surface kernel logs through Python logging on use_kernel#824
feat(kernel): surface kernel logs through Python logging on use_kernel#824vikrantpuppala wants to merge 2 commits into
Conversation
When the kernel backend loads, auto-initialize the kernel's
tracing -> Python logging bridge so `use_kernel=True` users see kernel
logs with no extra setup. Kernel logs land under the
`databricks.sql.kernel` logger (a child of the connector's
`databricks.sql.*` namespace), so an existing
`logging.getLogger("databricks.sql").setLevel(...)` cascades to them.
- `_errors.py` calls `databricks_sql_kernel.init_logging()` once at
extension load (it's the canonical kernel-import site). The call is
`getattr`-guarded so an older kernel wheel without the function still
works — just without kernel logs.
- e2e tests assert kernel records reach the `databricks.sql.kernel`
logger (and the pyo3 boundary under `databricks.sql.kernel.pyo3`) and
that the level set on the logger is respected. Creds-gated per the
existing kernel e2e convention.
Requires the companion kernel/pyo3 change
(databricks-sql-kernel#120) that exposes `init_logging()`.
Co-authored-by: Isaac
Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
|
🟠 P1 (Important — should fix before merge)
🟡 P2 (Minor)
|
Review feedback from PR #824 (gopalldb): - P1: guard the init_logging() call against throwing, not just a missing function. A panic across the PyO3 boundary surfaces as pyo3_runtime.PanicException (a BaseException, not Exception), so a bare call could escape module import and fail every use_kernel=True connection over a non-essential logging feature. Wrap in try/except BaseException, log a debug breadcrumb, continue. This also neutralizes the idempotency concern regardless of the Rust impl. - P2: soften the level-control test docstring to make clear it asserts the effective customer-visible outcome (sub-threshold records don't surface), not source-side suppression — caplog filters after the FFI. - P2: downgrade the databricks.sql.kernel.pyo3 assertion to a soft warning so a benign kernel change to the boundary breadcrumb target doesn't break the connector e2e suite. The core databricks.sql.kernel contract is still hard-asserted. Co-authored-by: Isaac Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
|
Thanks @gopalldb — these are great catches. Dispositions below; pushed in ca9234b. P1#1 — bare
|
Summary
On the
use_kernel=Truepath, the Rust kernel's logs now surface through Python's stdlibloggingautomatically — no extra setup. Kernel logs land under thedatabricks.sql.kernellogger, a child of the connector'sdatabricks.sql.*namespace, so a customer's existing logging config just works:Before this, kernel-backed sessions emitted nothing into Python logging — the kernel produced
tracingevents but nothing on the Python path consumed them.Changes
backend/kernel/_errors.pycallsdatabricks_sql_kernel.init_logging()once when the kernel extension loads (the canonical kernel-import site). The call isgetattr-guarded, so an older kernel wheel without the function still works — just without kernel logs.tests/e2e/test_kernel_backend.pyadds two creds-gated e2e tests (matching the existing kernel e2e convention):test_kernel_logs_reach_python_logging— a query at DEBUG produces records ondatabricks.sql.kernel, and the pyo3 boundary surfaces underdatabricks.sql.kernel.pyo3.test_kernel_log_level_is_respected— at WARNING, the chatty DEBUG kernel records are filtered out (proving level control, not unconditional forwarding).Cross-layer visibility
With this, a single query shows the full vertical in one stream:
Dependency
Requires the companion kernel/pyo3 change that exposes
init_logging(): databricks/databricks-sql-kernel#120. Until a kernel wheel containing that function is installed, this is a no-op (thegetattrguard), so it's safe to merge independently.Testing
Both e2e tests pass against a live warehouse with a locally-built kernel wheel (
maturin develop).🤖 Generated with Claude Code