Crate prima_datadog[][src]

Expand description

This is an opinionated library to share code and approach to Datadog logging in prima.it

Getting started

You need to call Datadog::init in your main binary, and to do so you’ll need as argument a type that implements the Configuration trait.

Inside the configuration you’ll find an implementation of this trait tailored for prima.it needs.

use prima_datadog::{*, configuration::PrimaConfiguration};

// initializes the PrimaConfiguration struct
let configuration = PrimaConfiguration::new(
    "0.0.0.0:1234", // to address
    "0.0.0.0:0", // from address
    "service_name", // namespace for all metrics
    "production".parse().unwrap() // environment
);

// Initializes a Datadog instance
Datadog::init(configuration);

// Then you can use the macros exposed at the base level of the module
incr!("test");
incr!("test"; "some" => "data");
decr!("test");
decr!("test"; "some" => "data");
count!("test", 20);
count!("test", 10; "some" => "data");
time!("test", || { println!("expensive computation");});
time!("test", || { println!("expensive computation");}; "some" => "data");
timing!("test", 20);
timing!("test", 20; "some" => "data");
gauge!("test", "gauge value");
gauge!("test", "gauge value"; "some" => "data");
histogram!("test", "histogram value");
histogram!("test", "histogram value"; "some" => "data");
distribution!("test", "distribution value");
distribution!("test", "distribution value"; "some" => "data");
set!("test", "set value");
set!("test", "set value"; "some" => "data");
  
// The first argument is the metric name. It accepts string literal (like the previous example)
// or a type path that implements [AsRef] for `T: str`

// custom metric, based on an enum type. It can really be whatever you want, //!
// as long as it implements AsRef<str>
enum Metric {
    John,
    Paul,
    George,
    Ringo,
}

impl AsRef<str> for Metric {
    fn as_ref(&self) -> &str {
        match self {
            Metric::John => "john",
            Metric::Paul => "paul",
            Metric::George => "george",
            Metric::Ringo => "ringo",
        }
    }
}

// now you can do
incr!(Metric::John; "play" => "guitar");
incr!(Metric::Paul; "play" => "bass");
incr!(Metric::George; "play" => "sitar");
incr!(Metric::Ringo; "play" => "drums");

References

Modules

Configuration module

Error module for this crate

Macros

Decrement a StatsD counter

Decrement a StatsD counter

Report a value in a distribution

Report an arbitrary value as a gauge

Report a value in a histogram

Increment a StatsD counter

Report a value in a set

Make an arbitrary change to a StatsD counter

Send your own timing metric in milliseconds

Structs

The Datadog struct is the main entry point for the library

Struct for adding optional pieces to a service check

Enums

Represents the different states a service can be in

Traits

This trait represent a client that is able to interact with the datadog statsd collector. It’s main use in this library is having a common interface for the underlying implementation, and being able to mock it for testing purposes