Crates.io | ddog |
lib.rs | ddog |
version | 0.1.0 |
source | src |
created_at | 2022-08-09 18:05:15.343905 |
updated_at | 2022-08-11 19:37:18.45862 |
description | A Minimal Datadog SDK built in Pure Rust. |
homepage | |
repository | https://github.com/abigger87/ddog/ |
max_upload_size | |
id | 641949 |
size | 103,622 |
A Minimal Datadog SDK Built in Pure Rust.
Add the ddog
crate to your project:
ddog = "0.1.0"
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.
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);
};