rtb-telemetry
Part of the phpboyscout Rust toolkit: small, framework-free crates extracted from rust-tool-base.
Opt-in anonymous usage telemetry with pluggable sinks. Events carry a
salted SHA-256 machine identity (the raw machine ID never leaves the
crate), an RFC-3339 UTC timestamp, and caller-supplied attributes.
Collection is disabled by default at every layer: tool authors opt in
at compile time by depending on the crate, users opt in at runtime via
CollectionPolicy::Enabled, a decision the consent module persists.
use ;
use Arc;
let sink = new;
let telemetry = builder
.tool
.tool_version
.salt
.sink
.policy
.build;
telemetry.record.await?;
Built-in sinks: NoopSink, MemorySink, FileSink (newline-delimited
JSON). The remote-sinks Cargo feature adds HttpSink (JSON POST over
HTTPS) and OtlpSink (OpenTelemetry log records over OTLP/gRPC).
OtlpSink also has an OTLP/HTTP transport, and it does not work. The SDK's
exporter thread panics and nothing is exported, while emit still returns
Ok(()). Use a grpc://, grpcs:// or :4317 endpoint. The failure and
the versions it was tested against are in
Sinks.
The three sinks that write outside the process (FileSink, HttpSink,
OtlpSink) run rtb-redact over
Event::args and Event::err_msg before serialisation. MemorySink and
NoopSink do not, because neither lets the event leave. Event::attrs is
never redacted by any sink.
- Docs: https://telemetry.rust.phpboyscout.uk
- API reference: https://docs.rs/rtb-telemetry
- Crate: https://crates.io/crates/rtb-telemetry
Development
just ci runs the full local gate (fmt, clippy, nextest, doc, deny).
Run clippy and nextest with --all-features as well to cover the
remote-sinks sinks. Tests include a cucumber BDD suite
(tests/bdd.rs); the MachineId::derive scenario reads
/etc/machine-id (CI seeds a stable one). Releases are cut by
colophon from Conventional Commits; do not tag manually.
License
MIT