datadog_api/
lib.rs

1//! # Datadog API Client Library
2//!
3//! A Rust client for the Datadog API with type-safe access to monitors,
4//! dashboards, metrics, logs, synthetics, and more.
5//!
6//! ## Architecture
7//!
8//! ```text
9//! ┌─────────────────────────────────────────────────────────────┐
10//! │                      datadog-api                            │
11//! ├─────────────────────────────────────────────────────────────┤
12//! │  config.rs          │  Configuration & credentials         │
13//! │  ├─ DatadogConfig   │  API keys, site, retry settings      │
14//! │  └─ SecretString    │  Zeroize-on-drop credential wrapper  │
15//! ├─────────────────────────────────────────────────────────────┤
16//! │  client.rs          │  HTTP client with middleware         │
17//! │  └─ DatadogClient   │  Retry logic, auth headers, gzip     │
18//! ├─────────────────────────────────────────────────────────────┤
19//! │  apis/              │  Domain-specific API modules         │
20//! │  ├─ monitors        │  Monitor CRUD operations             │
21//! │  ├─ dashboards      │  Dashboard management                │
22//! │  ├─ metrics         │  Metrics queries                     │
23//! │  ├─ logs            │  Log search                          │
24//! │  ├─ synthetics      │  Synthetic tests                     │
25//! │  ├─ events          │  Event stream                        │
26//! │  ├─ infrastructure  │  Hosts and tags                      │
27//! │  ├─ downtimes       │  Scheduled downtimes                 │
28//! │  ├─ incidents       │  Incident management                 │
29//! │  ├─ slos            │  Service Level Objectives            │
30//! │  ├─ security        │  Security rules                      │
31//! │  ├─ notebooks       │  Notebooks                           │
32//! │  ├─ teams/users     │  Team and user management            │
33//! │  └─ traces          │  APM traces                          │
34//! ├─────────────────────────────────────────────────────────────┤
35//! │  models/            │  Request/response types (Serde)      │
36//! ├─────────────────────────────────────────────────────────────┤
37//! │  error.rs           │  Error types with helper methods     │
38//! │  └─ Error           │  is_retryable, is_not_found, etc.    │
39//! └─────────────────────────────────────────────────────────────┘
40//! ```
41//!
42//! ## Quick Start
43//!
44//! ```no_run
45//! use datadog_api::{DatadogClient, DatadogConfig};
46//! use datadog_api::apis::MetricsApi;
47//!
48//! #[tokio::main]
49//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
50//!     let config = DatadogConfig::from_env()?;
51//!     let client = DatadogClient::new(config)?;
52//!     let metrics_api = MetricsApi::new(client);
53//!     let metrics = metrics_api.list_metrics("system.cpu").await?;
54//!     println!("Found {} metrics", metrics.metrics.unwrap_or_default().len());
55//!     Ok(())
56//! }
57//! ```
58//!
59//! ## Configuration Sources
60//!
61//! Credentials load from (in order):
62//! 1. **File**: `~/.datadog-mcp/credentials.json`
63//! 2. **Keyring**: System credential storage (requires `keyring` feature)
64//! 3. **Environment**: `DD_API_KEY`, `DD_APP_KEY`, `DD_SITE`
65//!
66//! Use `DatadogConfig::from_env_or_file()` to try all sources.
67//!
68//! ## Error Handling
69//!
70//! ```no_run
71//! # use datadog_api::Error;
72//! fn handle(e: &Error) {
73//!     if e.is_not_found() { /* 404 */ }
74//!     else if e.is_rate_limited() { /* 429 - back off */ }
75//!     else if e.is_retryable() { /* transient - retry */ }
76//! }
77//! ```
78//!
79//! ## Supported Sites
80//!
81//! - US1: `datadoghq.com` (default)
82//! - US3: `us3.datadoghq.com`
83//! - US5: `us5.datadoghq.com`
84//! - EU: `datadoghq.eu`
85//! - AP1: `ap1.datadoghq.com`
86//! - US1-FED: `ddog-gov.com`
87//!
88//! ## Cargo Features
89//!
90//! - `keyring` (default): Secure credential storage in system keyring
91
92pub mod apis;
93pub mod client;
94pub mod config;
95pub mod error;
96pub mod models;
97pub mod pagination;
98pub mod rate_limit;
99pub mod timestamp;
100
101pub use client::{CacheInfo, CachedResponse, DatadogClient};
102pub use config::{DatadogConfig, HttpConfig, RetryConfig};
103pub use error::{Error, Result};
104pub use models::{
105    GroupDefinition, HeatmapDefinition, NoteDefinition, QueryTableDefinition,
106    QueryValueDefinition, TemplateVariable, TimeseriesDefinition, ToplistDefinition, Widget,
107    WidgetDefinition, WidgetLayout,
108};
109pub use pagination::{CursorParams, PageParams, PaginatedResponse, PaginationMeta};
110pub use rate_limit::{RateLimitConfig, RateLimiter};
111pub use timestamp::{TimestampMillis, TimestampNanos, TimestampSecs};