2 releases

0.1.1 Aug 6, 2024
0.1.0 Jul 31, 2024

#450 in Debugging

Apache-2.0

40KB
722 lines

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");

Dependencies

~49MB
~696K SLoC