instrumented

Crates.ioinstrumented
lib.rsinstrumented
version0.1.3
sourcesrc
created_at2019-08-25 17:46:40.379504
updated_at2019-08-28 19:03:50.711456
descriptioninstrument your code
homepage
repositoryhttps://github.com/umpyre-code/instrumented
max_upload_size
id159580
size10,771
Brenden Matthews (brndnmtthws)

documentation

README

Current Crates.io Version Docs pipeline status coverage report

Instrumented 🎸

Observe your service.

You can specify the global metrics prefix with the METRICS_PREFIX env var, and provide default labels with the METRICS_LABELS env var, which accepts a command separated list of label=value pairs. For example:

METRICS_PREFIX=myapp
METRICS_LABELS=app=myapp,env=prod,region=us

Example

extern crate instrumented;
extern crate log;
extern crate reqwest;

use instrumented::instrument;

#[instrument(INFO)]
fn my_func() {
    use std::{thread, time};
    let ten_millis = time::Duration::from_millis(10);
    thread::sleep(ten_millis);
}

#[derive(Debug)]
pub struct MyError;

#[instrument(INFO)]
fn my_func_with_ok_result() -> Result<String, MyError> {
    use std::{thread, time};
    let ten_millis = time::Duration::from_millis(10);
    thread::sleep(ten_millis);

    Ok(String::from("hello world"))
}

#[instrument(INFO)]
fn my_func_with_err_result() -> Result<String, MyError> {
    use std::{thread, time};
    let ten_millis = time::Duration::from_millis(10);
    thread::sleep(ten_millis);

    Err(MyError)
}

fn main() {
    let addr = "127.0.0.1:5000".to_string();
    instrumented::init(&addr);

    my_func();
    assert_eq!(my_func_with_ok_result().is_ok(), true);
    assert_eq!(my_func_with_err_result().is_err(), true);

    let body = reqwest::get(&format!("http://{}/metrics", addr))
        .unwrap()
        .text()
        .unwrap();

    println!("{}", body);
}
Commit count: 9

cargo fmt