WeaveDocs
Zer0 Proto Mp

Metrics and Errors

Metrics and typed errors in `zer0-proto-mp` — per-channel throughput counters and a complete error taxonomy.

Purpose

Protocol multiplexing with channels, frames, varints, schemas, handshakes, metrics, and stream integration.

This page follows the real source shape for Zer0 Proto Mp and explains the workflow a developer is likely to use first.

Developer workflow

Start from the smallest constructor or builder, perform one meaningful operation, inspect the returned state, then add the relevant policy, storage, or network integration. The examples below should be expanded whenever the crate API changes.

Primary types to know

  • Channel — libs/zer0-proto-mp/src/channel.rs
  • ChannelHandle — libs/zer0-proto-mp/src/channel.rs
  • ChannelId — libs/zer0-proto-mp/src/frame.rs
  • ChannelStats — libs/zer0-proto-mp/src/channel.rs
  • Frame — libs/zer0-proto-mp/src/frame.rs
  • HandshakeConfig — libs/zer0-proto-mp/src/protocol.rs
  • MessageId — libs/zer0-proto-mp/src/protocol.rs
  • MessageSchema — libs/zer0-proto-mp/src/protocol.rs
  • MuxConfig — libs/zer0-proto-mp/src/config.rs
  • MuxMetrics — libs/zer0-proto-mp/src/metrics.rs
  • Protocol — libs/zer0-proto-mp/src/protocol.rs
  • ProtocolBuilder — libs/zer0-proto-mp/src/protocol.rs

Example shape

use zer0_proto_mp::{MuxConfig, MuxMetrics, WeaveMux, WeaveMuxError};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // MuxMetrics counters live on the WeaveMux and surface via
    // export_metrics_text in Prometheus exposition format.
    let (stream, _peer) = tokio::io::duplex(1024);
    let mux = WeaveMux::new(stream, MuxConfig::default());

    // Force an error by referencing a channel that does not exist.
    let err = mux.channel_stats(zer0_proto_mp::ChannelId(99))
        .expect_err("channel 99 was never opened");
    assert!(matches!(err, WeaveMuxError::ChannelNotFound(_)));

    let snapshot: MuxMetrics = mux.metrics();
    let prom = mux.export_metrics_text("weave_mux");
    println!(
        "frames_total={} bytes_total={} errors={:?} prom_bytes={}",
        snapshot.frames_total,
        snapshot.bytes_total,
        err,
        prom.len(),
    );
    Ok(())
}