chaincodec-observability
OpenTelemetry metrics, distributed tracing, and structured logging for ChainCodec.
chaincodec-observability wires up OpenTelemetry metrics and tracing spans so you can monitor decode throughput, error rates, and latency from any OTLP-compatible backend — Prometheus, Grafana Tempo, Jaeger, Datadog, or the OpenTelemetry Collector.
Features
- Metrics — decode throughput, error rate, batch size, schema cache hit ratio via OTLP counters + histograms
- Tracing — distributed spans for decode pipelines, compatible with Jaeger, Tempo, and Zipkin
- Structured logging — JSON log output via
tracing-subscriberwith field-level context - OTLP export — pushes telemetry to any OpenTelemetry Collector over gRPC
- Prometheus compatible — pair with
opentelemetry-prometheusfor pull-based metrics scraping - Low overhead — metrics are batched; tracing supports configurable sampling rates
Installation
[]
= "0.1"
Quick start
use ;
use global;
async
Exported metrics
| Metric | Type | Labels | Description |
|---|---|---|---|
chaincodec.events_decoded |
Counter | chain, schema |
Events successfully decoded |
chaincodec.events_skipped |
Counter | chain |
Events with no schema match |
chaincodec.decode_errors |
Counter | chain, error_type |
Decode failures by type |
chaincodec.decode_latency_ms |
Histogram | chain |
Per-event decode time (ms) |
chaincodec.batch_size |
Histogram | — | Events per batch request |
chaincodec.schema_cache_hits |
Counter | — | Schema fingerprint cache hits |
Structured logging
// JSON logs — for production log aggregators (Loki, Datadog, CloudWatch)
fmt
.json
.with_env_filter
.init;
// Human-readable — for local development
fmt
.with_env_filter
.init;
Set log level via environment variable:
RUST_LOG=chaincodec=debug,info
Prometheus integration
Pair with opentelemetry-prometheus for pull-based metrics:
[]
= "0.1"
= "0.16"
= "0.13"
= "0.7"
use PrometheusExporter;
use Registry;
let prom_registry = new;
let _exporter = exporter
.with_registry
.build?;
// Expose /metrics endpoint (Axum)
let app = new.route;
Distributed tracing
When instrumented, every decode operation emits a span visible in Jaeger / Grafana Tempo:
chaincodec.decode_event
chain: "ethereum"
schema: "ERC20Transfer"
block_number: 19500000
duration: 0.42ms
Configure sampling in the OTLP exporter to control overhead on high-throughput paths.
Ecosystem
| Crate | Purpose |
|---|---|
| chaincodec-core | Traits, types, primitives |
| chaincodec-evm | EVM ABI event & call decoder |
| chaincodec-batch | Rayon parallel batch decode |
| chaincodec-stream | Live WebSocket event streaming |
| chaincodec-observability | OpenTelemetry metrics & tracing (this crate) |
License
MIT — see LICENSE