Skip to main content

Module telemetry

Module telemetry 

Source
Expand description

Telemetry: tracing spans, metrics, and structured events for client calls.

This is the transport-neutral instrumentation the client crates wrap their RPCs with (Option B: telemetry lives in canton-core). Every instrumented call opens a canton.rpc tracing span, emits request/error counters via the metrics facade, and logs a structured success/error event.

Exporting. Following the standard Rust telemetry model, this crate emits and the application chooses the exporters: a tracing_subscriber for logs and spans, a metrics recorder for counters. Metrics carry method + transport labels, so any recorder (Prometheus, an OTLP bridge, …) gets the per-endpoint request/error breakdown for free (success = requests − errors).

The otel feature supplies a supported OpenTelemetry path for both halves rather than leaving it as an exercise: otel::otlp_tracer builds the span exporter, otel::otlp_metrics builds the metrics pipeline and installs the recorder that bridges this crate’s counters onto it, and trace context is injected into every outgoing request — gRPC metadata, JSON headers, and the WebSocket upgrade — automatically.

Streams. Use instrument for a call that returns a value and instrument_stream for one that returns a stream. The difference is not cosmetic: a subscription’s outcome is not known when it opens, so instrumenting only the opening records every long-lived stream as a success and never revisits it.

Modules§

otelotel
OpenTelemetry export helpers (enable the otel feature).

Constants§

METRIC_ERRORS
Counter: client errors, labelled by method, transport, and retriable.
METRIC_REQUESTS
Counter: total client requests, labelled by method and transport.
TRANSPORT_GRPC
transport label / span-field value for the gRPC lane.
TRANSPORT_JSON
transport label / span-field value for the JSON lane.

Functions§

current_trace_id
The current span’s trace id as 32 hex characters, when an OpenTelemetry context is active.
instrument
Instrument a client RPC future: open a canton.rpc span, count the request (and any error), and log a structured outcome event.
instrument_stream
Instrument a client stream: the same span, counters and events as instrument, but for the life of the stream rather than the moment it opens.