6 releases

0.1.0 Aug 11, 2022
0.0.5 Aug 11, 2022

#550 in Debugging

AGPL-3.0-only

47KB
773 lines

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

Dependencies

~11–25MB
~375K SLoC