metry

Crates.iometry
lib.rsmetry
version0.1.1
sourcesrc
created_at2024-07-31 08:28:13.401602
updated_at2024-08-06 20:04:21.852619
descriptionAll-in-one telemetry framework, based on tracing crate.
homepagehttps://github.com/ottofeller/telemetry/tree/main/metry
repositoryhttps://github.com/ottofeller/telemetry.git
max_upload_size
id1320732
size40,959
Artem Rudenko (gvidon)

documentation

README

Ottofeller telemetry library

This crate contains the API for telemetry setup in Rust.

Overview

This crate supplements tracing library and provides an easy way to setup providers for collection of logs, metrics and traces.

What does this crate contain?

  • Telemetry API: Provides a way to setup collection of logs, metrics and traces with a choice of preconfigured providers.

The other modules are provide a way to fine-tune telemetry during setup. They contain reasonable defalts as well as allow configuration in the scope of exposed API.

  • Logs: A collection of log providers. Available options are Stdout and Stderr.
  • Metrics: A collection of log providers. Available options are Stdout and CloudWatch.
  • Traces: A collection of log providers. Available options are Stdout and Xray.

Getting started

To have the telemetry collected one needs to:

  • setup providers for each type of telemetry;
  • instrument the code with relevant events.

Setup telemetry

use metry::telemetry;

telemetry::new()
    .with_stdout_logs()
    .with_aws_metrics()
    .with_aws_traces()
    .init()
    .await;

Instrument your code

use tracing::{info, info_span};

// Emit a log event with level info
info!("Started execution");

// Start a synchronous trace span
let span = info_span!("my sync span");
span.in_scope(|| {
    info!("This event is recorder within the trace span");

    // Do work inside the span...

    // Collect metrics: count on foo
    info!(monotonic_counter.foo = 1);
});

// Run async code in a future with a span attached
let future_result: Vec<u64> = some_future
    .instrument(tracing::info_span!("my async span"))
    .await;

// Collect metrics: put data into the bar histogram
info!(histogram.bar = future_result);
info!("Execution complete");
Commit count: 0

cargo fmt