Skip to content

Add tracing spans to public Client RPC methods - #86

Open
divbhasin wants to merge 1 commit into
kezhuw:masterfrom
DataDog:add-client-rpc-tracing-spans
Open

Add tracing spans to public Client RPC methods#86
divbhasin wants to merge 1 commit into
kezhuw:masterfrom
DataDog:add-client-rpc-tracing-spans

Conversation

@divbhasin

@divbhasin divbhasin commented May 4, 2026

Copy link
Copy Markdown

Summary

Adds tracing::info_span! to the public RPC entry points on Client, MultiReader, and MultiWriter so callers with a tracing subscriber can observe per-call latency, span hierarchy, and errors for their ZooKeeper operations.

The crate already uses tracing internally (#[instrument] on session functions, tracing::error! in the watcher loop). This extends the same pattern to the public API surface.

What's instrumented

Client::{mkdir, create, delete, get_data, set_data, get_and_watch_data, check_stat, check_and_watch_stat, get_children, get_and_watch_children, sync}, plus MultiReader::commit and MultiWriter::commit.

Each call opens an info_span!("zk.<op>", path = %path) (or kind = "reader" | "writer" for the multi
variants) and records Err outcomes via a tracing::error! event so tracing-opentelemetry and similar
subscriber bridges mark the span as errored.

Testing

This has been tested with our internal usage of the client.

Each public RPC and MultiReader/MultiWriter::commit now opens a
`zk.<op>` `info_span!` and records errors via `tracing::error!`.

Methods returning `impl Future<Output = Result<…>>` can't use
`#[instrument(err)]`, so a `Client::traced` helper awaits the future
inside the span and emits the error event.
@kezhuw

kezhuw commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Errors are semantic apis. It is callers' responsibility to do whatever they want.

zookeeper-client logs wire requests/responses at "debug", state changes at "info", expected failures at "warn", and unexpected failures at "error". I think it is suitable as a library.

The two spans are there for reasons:

  1. There are hard works behind the blocking operations.
  2. Carry session info to logs.

In contrast, most client apis are simple request-response style channels to get responses.

I guess you probably should wrap the client somewhat to fit your application needs.

@kezhuw kezhuw self-assigned this Jul 30, 2026
@kezhuw
kezhuw self-requested a review July 30, 2026 07:01
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.

2 participants