Skip to main content

Crate grow_datadog_logs

Crate grow_datadog_logs 

Source
Expand description

§grow-datadog-logs

Rust SDK for Datadog Log Management by Grow Codes: the logs intake (POST /api/v2/logs, gzip, 1000 entries / 5 MB batches, 1 MB per log), Logs Search v2 with cursor pagination, log aggregation, index listing and API key checks. Not affiliated with Datadog, Inc.

use grow_datadog_logs::logging::{attrs, LogClient};
use grow_datadog_logs::{DatadogLogsClient, DatadogLogsConfig, LogClientOptions};

// DD_API_KEY, DD_SITE, DD_SERVICE, … or GROW_DATADOG_LOGS_* variables
let client = DatadogLogsClient::new(DatadogLogsConfig::from_env()?)?;
assert!(client.validate_api_key().await?);
let logs = client.log_client(LogClientOptions::default())?;
logs.logger(Some("checkout"), attrs! {}).info("order placed", attrs! { "order.id" => 42 });
client.close().await; // flushes

Search (needs DD_APP_KEY):

use grow_datadog_logs::SearchLogsRequest;
let query = client.query()?;
let page = query
    .search_logs(&SearchLogsRequest::new("service:checkout status:error").from("now-1h").limit(50))
    .await?;
for record in page.records() {
    println!("{} {}", record.severity, record.body);
}

Features: blocking (a blocking client), testing (in-memory fakes and the conformance runner), tracing-layer and log-bridge (logging adapters, on by default).

Re-exports§

pub use crate::core::Error;
pub use crate::core::ErrorCode;
pub use crate::core::HealthStatus;
pub use crate::core::Result;
pub use crate::core::RetryPolicy;
pub use crate::core::Secret;
pub use crate::mapping::LogEvent;
pub use crate::query::AggregateBucket;
pub use crate::query::AggregateLogsOptions;
pub use crate::query::AggregateLogsResult;
pub use crate::query::Compute;
pub use crate::query::DatadogLogsQuery;
pub use crate::query::GroupBy;
pub use crate::query::GroupByHistogram;
pub use crate::query::GroupBySort;
pub use crate::query::LogIndex;
pub use crate::query::LogsSort;
pub use crate::query::QueryMeta;
pub use crate::query::SearchLogsPage;
pub use crate::query::SearchLogsRequest;
pub use crate::query::SearchWarning;
pub use crate::query::TimeseriesPoint;

Modules§

blockingblocking
Blocking wrapper (feature blocking). Each client owns a tokio runtime with one worker thread, so background work (log batching, exports, watchers, retries’ timers) keeps running between blocking calls.
core
Shared core: errors, configuration, secrets in config, redaction, retries and transport.
logging
Logging category (SPEC §4): records, batching, redaction, the Logger facade, the query model and framework adapters.
mapping
LogRecord ⇄ Datadog JSON: intake entries, limits, trace-id conversion and search-event normalization (API.md §5.2, §6.1; DECISIONS 6, 7, 9).
query
Datadog query client: Logs Search v2, aggregation, indexes, polling tail (API.md §6; DECISIONS 3, 5, 8).
testingtesting
Test support (feature testing): in-memory fakes and the conformance runner (SPEC §6).

Macros§

attrs
Builds an Attributes map: attrs! { "user" => "ada", "n" => 3 }.

Structs§

DatadogLogExporter
LogExporter for POST {intake}/api/v2/logs: maps records to Datadog JSON, truncates oversized messages, splits batches at 1000 entries / 5 MB, gzips (when asked) and sends with header DD-API-KEY only. The intake POST is retried like an idempotent call (429, 5xx, network errors; duplicates are possible after an ambiguous failure).
DatadogLogsClient
Async client for Datadog Log Management. Cheap to clone (clones share one connection pool).
DatadogLogsConfig
Immutable client configuration; build it with DatadogLogsConfig::builder or DatadogLogsConfig::from_env. Debug output redacts every credential.
DatadogLogsConfigBuilder
Builder for DatadogLogsConfig. Values set here win over the environment.
EncodedBatch
Records mapped and split into intake request bodies.
IntakePayload
One intake request body.
LogClientOptions
Options of DatadogLogsClient::log_client.
SiteEndpoints
The two base URLs of a Datadog site.

Constants§

DEFAULT_INTAKE_URL
Default logs intake base URL (the intake host of DEFAULT_SITE).
DEFAULT_SITE
Datadog site used when none is configured (US1).
DEFAULT_SOURCE
ddsource sent with every log when none is configured (DECISIONS 9).
DEFAULT_URL
Default API base URL (the API host of DEFAULT_SITE).
HEADER_API_KEY
Header carrying the API key on every request.
HEADER_APP_KEY
Header carrying the application key on query requests only.
INTAKE_PATH
Path of the logs intake.
RATE_LIMIT_RESET_HEADER
Rate-limit header used as the retry hint when Retry-After is missing (seconds).
SITES
Datadog sites accepted by DatadogLogsConfigBuilder::site and resolve_site (the servers enum of the official OpenAPI specification).
VALIDATE_PATH
Path of the API key check used by health, ping and validate_api_key.

Functions§

map_datadog_error
Maps Datadog’s 403 (missing or invalid key, or a key without the needed permission, which Datadog does not tell apart) onto AUTHENTICATION, keeping the HTTP status 403, the message and the request id. Other errors are returned unchanged.
parse_tags
Splits a DD_TAGS style list: key:value tags separated by commas and/or whitespace. Empty items are dropped.
resolve_site
Returns the intake and API base URLs of a Datadog site (datadoghq.com, datadoghq.eu, us3.datadoghq.com, …). The site is the API site, never the UI host (app.datadoghq.com). It is trimmed and lower-cased; an empty site means DEFAULT_SITE. Unknown sites are a CONFIG error.

Type Aliases§

DatadogLogClient
The batching LogClient returned by DatadogLogsClient::log_client.
DatadogLogsError
Service-prefixed alias of Error.