ddog

Crates.ioddog
lib.rsddog
version0.1.0
sourcesrc
created_at2022-08-09 18:05:15.343905
updated_at2022-08-11 19:37:18.45862
descriptionA Minimal Datadog SDK built in Pure Rust.
homepage
repositoryhttps://github.com/abigger87/ddog/
max_upload_size
id641949
size103,622
refcell (refcell)

documentation

README

ddog • ci license crates.io

A Minimal Datadog SDK Built in Pure Rust.

Getting Started

Add the ddog crate to your project:

ddog = "0.1.0"

Usage

The simplest way to use the Datadog SDK is by using the Builder.

To create a new builder, you can instantiate one with the new method: let mut builder = ddog::prelude::Builder::new();.

Then, to create a new query with a given endpoint, the Builder has explicit methods exposed for the specified endpoint. For example, to post metrics series data to datadog, call the post_series method which returns a Route trait.

Examples

Below we show how to use ddog to post metric series data to the Datadog API.

Note: This request will not succeed since the DD_API_KEY environment variable is set to an invalid value in the request headers section.

use ddog::prelude::*;

async {
    let mut builder = builder::Builder::new();
    let (status, res) = builder.v2()
        .post_series()
        .headers(vec![
            ("Accept", "application/json"),
            ("Content-Type", "application/json"),
            ("DD-API-KEY", "<api_key>"),
            ("DD-APPLICATION-KEY", "<application_key>"),
        ])
        .body(
            r#"{
                "series": [{
                    "metric": "my.metric.name",
                    "type": 1,
                    "interval": 100000,
                    "unit": "count",
                    "tags": [ "my_tag:" ],
                    "source_type_name": "my_source_type",
                    "resources": [{
                        "name": "length",
                        "type": "time"
                    }],
                    "points": [
                        { "timestamp": 1660157680, "value": 10.0 },
                    ],
                    "metadata": {
                        "origin": {
                            "metric_type": 1,
                            "product": 1,
                            "service": 1
                        }
                    }
                }]
            }"#
        )
        .execute().await;
    // This should return a 403 status code now since the above API key is invalid.
    println!("Status Code: {:?}", status);
    println!("Response: {:?}", res);
};

License

AGPL-3.0-only

Acknowledgements

Commit count: 33

cargo fmt