#datadog #open-api #api-client #was

datadog-api-client

Rust client for the Datadog API

9 releases (breaking)

new 0.6.0 Nov 7, 2024
0.4.0 Sep 4, 2024
0.1.3 Jul 1, 2024
0.0.1 Mar 28, 2024

#97 in HTTP client

Download history 22/week @ 2024-07-18 54/week @ 2024-07-25 848/week @ 2024-08-01 207/week @ 2024-08-08 78/week @ 2024-08-15 27/week @ 2024-08-22 118/week @ 2024-08-29 91/week @ 2024-09-05 65/week @ 2024-09-12 79/week @ 2024-09-19 110/week @ 2024-09-26 103/week @ 2024-10-03 161/week @ 2024-10-10 243/week @ 2024-10-17 158/week @ 2024-10-24 132/week @ 2024-10-31

712 downloads per month

Apache-2.0

17MB
370K SLoC

Datadog API Client

Rust HTTP client for the Datadog API.

To submit support or feature requests, please visit https://www.datadoghq.com/support/

Overview

This API client was generated from Datadog's public OpenAPI specs. Generator code and templates can be found in the repository's .generator/ folder.

Installation

Run cargo add datadog-api-client or add the following to Cargo.toml under [dependencies]:

datadog-api-client = "0"

Getting Started

Please follow the installation instructions and try the following snippet to validate your Datadog API key:

use datadog_api_client::datadog::Configuration;
use datadog_api_client::datadogV1::api_authentication::AuthenticationAPI;

#[tokio::main]
async fn main() {
    let configuration = Configuration::new();
    let api = AuthenticationAPI::with_config(configuration);
    let resp = api.validate().await;
    if let Ok(value) = resp {
        println!("{:#?}", value);
    } else {
        println!("{:#?}", resp.unwrap_err());
    }
}

Example snippets for every callable endpoint can be found in the repository's /examples/ directory.

Authentication

By default the library will use the DD_API_KEY and DD_APP_KEY environment variables to authenticate against the Datadog API.
To provide your own set of credentials, you need to set some keys on the configuration:

configuration.set_auth_key(
    "apiKeyAuth",
    APIKey {
        key: "<DD-API-KEY>".to_string(),
        prefix: "".to_owned(),
    },
);
configuration.set_auth_key(
    "appKeyAuth",
    APIKey {
        key: "<DD-APP-KEY>".to_string(),
        prefix: "".to_owned(),
    },
);

Datacenter Selection

By default the library will use the US1 Datadog datacenter, at datadoghq.com. To change this, we expose OpenAPI-style server index and server variable fields. For example, to switch the target datacenter to the EU datacenter, you can set the following values on the configuration object:

configuration.server_index = 0;
configuration.server_variables.insert("site".into(), "datadoghq.eu".into());

Alternatively, you can set the environment variable DD_SITE=datadoghq.eu to achieve the same result.

For a list of sites and alternative server URL schemes, you can refer to the code here.

Unstable Endpoints

This client includes access to Datadog API endpoints while they are in an unstable state and may undergo breaking changes. An extra configuration step is required to use these endpoints:

configuration.set_unstable_operation_enabled("<OPERATION_NAME>", true)

where <OPERATION_NAME> is the API version and name of the method used to interact with that endpoint. For example: v2.list_incidents, or v2.query_timeseries_data

Optional Features

  • native-tls (enabled by default): Enables TLS functionality using the native-tls crate.
  • rustls-tls: Enables TLS functionality using the alternative rustls crate.

Contributing

As most of the code in this repository is generated, we will only accept PRs for files that are not modified by our code-generation machinery (changes to the generated files would get overwritten). We happily accept contributions to files that are not autogenerated, such as tests and development tooling.

Author

support@datadoghq.com

Dependencies

~10–24MB
~342K SLoC