datadog-api
A Rust client library for the Datadog API with type-safe access to monitors, dashboards, metrics, logs, synthetics, and more.
Features
- 16 API modules covering monitors, dashboards, metrics, logs, synthetics, events, infrastructure, downtimes, incidents, SLOs, security, notebooks, teams, users, and traces
- Automatic retry with exponential backoff for transient failures
- Rate limiting with client-side token bucket
- Conditional requests with ETag/If-Modified-Since support
- Type-safe timestamps with
TimestampSecs,TimestampMillis,TimestampNanos - Secure credential storage via system keyring (macOS Keychain, Windows Credential Manager, Secret Service)
- All Datadog regions supported (US1, US3, US5, EU, AP1, US1-FED)
Installation
[]
= "0.1"
To disable keyring support (for environments without a system keyring):
[]
= { = "0.1", = false }
Quick Start
use ;
use MonitorsApi;
async
Configuration
Environment Variables
# Optional, defaults to datadoghq.com
Programmatic Configuration
use ;
let config = new
.with_site
.with_retry
.with_http;
let client = new?;
Credential Sources
The library loads credentials in this order:
- Keyring (if
keyringfeature enabled): System credential storage - File:
~/.datadog-mcp/credentials.json - Environment:
DD_API_KEY,DD_APP_KEY,DD_SITE
// Try all sources
let config = from_env_or_file?;
// Or load from specific source
let config = from_env?; // Environment only
API Modules
use *;
let client = new?;
// Monitoring
let monitors = new;
let dashboards = new;
let slos = new;
// Metrics & Logs
let metrics = new;
let logs = new;
let events = new;
// Infrastructure
let infra = new;
let downtimes = new;
// Testing
let synthetics = new;
// Security & Incidents
let security = new;
let incidents = new;
// Organization
let teams = new;
let users = new;
let notebooks = new;
// APM
let traces = new;
Error Handling
use Error;
match api.get_monitor.await
Timestamps
Type-safe timestamp handling to avoid unit confusion:
use ;
// Current time
let now = now;
// Relative times
let yesterday = days_ago;
let last_hour = hours_ago;
// Convert between units
let millis: TimestampMillis = now.to_millis;
// Use in queries
let metrics = api.query_metrics.await?;
Conditional Requests
Reduce bandwidth with ETag caching:
use CacheInfo;
// First request
let response = client..await?;
let cache_info = response.as_ref.map;
// Subsequent request - returns None if unchanged (304)
let response = client..await?;
match response
Supported Datadog Sites
| Site | Domain | Usage |
|---|---|---|
| US1 (default) | datadoghq.com |
Most users |
| US3 | us3.datadoghq.com |
US region 3 |
| US5 | us5.datadoghq.com |
US region 5 |
| EU | datadoghq.eu |
European Union |
| AP1 | ap1.datadoghq.com |
Asia Pacific |
| US1-FED | ddog-gov.com |
US Government |
License
MIT - See LICENSE for details.
Related
- datadog-mcp - MCP server that uses this library to connect AI assistants to Datadog