Repository navigation
feat(c-abi): add callback logging bridge - #278
Conversation
There was a problem hiding this comment.
Verdict: 1 Low
Looks good — solid, well-tested callback logging bridge that correctly mirrors the existing kernel_init_logging OFF-level / first-call-wins semantics and shares LOGGING_INITIALIZED. One low-severity note: the callback layer drops enclosing-span fields that the file/stderr path surfaces, which slightly undercuts the docstring's "structured fields" claim.
There was a problem hiding this comment.
Verdict: 1 Low
Looks good — a clean, well-documented C ABI callback logging bridge that correctly reuses the existing first-call-wins subscriber machinery, with matching Rust integration and C smoke tests. One low maintainability note (duplicated OFF/filter-derivation logic between the two init entry points). Nit: CallbackLogLayer::on_event allocates three CStrings per event on the emitting thread's hot path — acceptable given filtering gates volume, but worth noting if high-verbosity forwarding is expected.
ac34b11 to
b821d53
Compare
There was a problem hiding this comment.
Verdict: 1 Low
Looks good — the C ABI callback logging bridge is correct and well-covered. The nullable-fn-pointer FFI idiom, Send + Sync layer (user_data as usize), global filter placement, shared OFF/NULL/UTF-8 level resolution, NUL sanitization, and first-call-wins sharing via LOGGING_INITIALIZED are all sound, with unit + integration + C-smoke tests. One low-severity maintainability note inline (duplicated default-filter fallback). Nit: non-message string fields are rendered unquoted (name=value) by CallbackMessageVisitor, unlike the fmt layer which quotes them — harmless but a formatting divergence between the two sinks.
2163214 to
2dd4739
Compare
Address review findings on the callback logging bridge (#278): - Replace the lossy `OnceLock<bool>` with a `LoggingOutcome` enum so a later initializer can tell whether its own sink actually won. `kernel_init_logging_callback` now returns `Internal` — not a misleading `Success` — when a file/stderr sink already won, so a host never believes a silently-dropped callback is live. File-open-failure, foreign-subscriber, and cross-sink cases now carry distinct, accurate messages (also fixing the prior "already installed" misreport after a log-file open error). - Guard `CallbackLogLayer::on_event` with `catch_unwind` so a panic on a tokio worker can't unwind through tracing dispatch and abort in-flight work, mirroring the `catch_ffi` / `block_on_ffi` guards on the C-ABI entry points. - Add a thread-local reentrancy guard so a callback that re-emits a kernel event drops the nested record instead of recursing without bound. Enclosing-span fields (e.g. `session_id`) remain intentionally excluded from the callback message, as documented. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
a0827c6 to
e5e1082
Compare
Address review findings on the callback logging bridge (#278): - Replace the lossy `OnceLock<bool>` with a `LoggingOutcome` enum so a later initializer can tell whether *its own* sink actually won. `kernel_init_logging_callback` now returns `Internal` — not a misleading `Success` — whenever it did not install the sink: a file/stderr sink won first, or a *different* callback won first. The winning callback sink retains the callback + `user_data` identity, so a second, different registration is rejected (a host never believes a dropped callback is live) while re-registering the identical callback stays idempotent. File-open-failure, foreign-subscriber, and cross-sink cases each carry distinct, accurate messages (also fixing the prior "already installed" misreport after a log-file open error). - Guard `CallbackLogLayer::on_event` with `catch_unwind` so a panic on a tokio worker can't unwind through tracing dispatch and abort in-flight work, mirroring the `catch_ffi` / `block_on_ffi` guards on the C-ABI entry points. - Add a thread-local reentrancy guard so a callback that re-emits a kernel event drops the nested record instead of recursing without bound. Enclosing-span fields (e.g. `session_id`) remain intentionally excluded from the callback message, as documented. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
e5e1082 to
48692b2
Compare
There was a problem hiding this comment.
Verdict: 1 Low
Looks good — solid, well-tested C ABI callback logging bridge. The LoggingOutcome/LoggingSink refactor preserves first-call-wins semantics, default_env_filter is behavior-equivalent to the prior inline default, and the on_event panic + reentrancy guards are correct (Drop-based reset survives unwind). One Low: the callback initializer's documented "Success means this callback is installed" contract doesn't account for the OFF-level path, which returns Success without installing anything.
…back `kernel_init_logging_callback` short-circuits on level `OFF` and returns `Success` without installing any callback sink (mirroring `kernel_init_logging`). The callback contract said "`Success` means this exact callback is the installed sink", omitting the OFF case that `kernel_init_logging`'s own docs already note. Add the "(or level OFF)" clause to the C header and the Rust doc-comment so the callback contract is as precise as the file/stderr one. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Signed-off-by: Vu Anh Phung <vu.phung@databricks.com>
Adds a C ABI logging initializer that forwards Rust kernel tracing records through a caller-provided callback. This lets the Go driver route kernel records into its existing zerolog sink, so
logger.SetLogOutput—including arbitraryio.Writerimplementations and later destination changes—works the same on the Thrift and kernel paths. Go integration: databricks/databricks-sql-go#450.This mirrors the existing Node implementation: its N-API binding installs a tracing layer, writes records to a bounded 4096-record queue, and drains them asynchronously through a
ThreadsafeFunctionintoDBSQLLogger. The Go integration places the asynchronous handoff on the host side instead: this C callback delivers synchronously, then Go copies the borrowed strings into its own bounded 4096-record channel and drains them into zerolog. Neither bridge waits for a timer or a full batch before draining; Node batches records already available (up to 512), while Go forwards them one at a time.Python does not need this C ABI entry point because PyO3 already uses
pyo3_logto enter Pythonlogging. Go reaches the kernel through the generic C ABI/cgo boundary, where the existing file/stderr initializer cannot represent its host logger.Callback delivery is process-wide and first-call-wins:
Successmeans levelOFFwas requested (which installs nothing) or this exact callback (keyed on callback +user_data) is the installed sink, and any initializer that loses — a file/stderr sink, a different callback, or a foreign subscriber — returns a distinctInternalrather than a misleadingSuccess, so a host never assumes a dropped callback is live. Theon_eventbridge contains panics and guards against callback reentrancy. The message contains event-local fields; enclosing span fields are not included.Tests:
cargo +stable fmt --all -- --check;cargo clippy --all-targets -- -D warnings;cargo test;make c-abi-test.