Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
99079bb
feat(log-agent): scaffold datadog-log-agent crate with constants and …
litianningdatadog Mar 9, 2026
cf28960
- use serde flatten with Map instead of Option<Map> to avoid deser quirk
litianningdatadog Mar 9, 2026
2555810
feat(log-agent): add LogAggregator with size/count-bounded batch coll…
litianningdatadog Mar 9, 2026
54a16fa
refactor(log-agent): clean up get_batch loop to include comma bytes i…
litianningdatadog Mar 9, 2026
a9ee357
feat(log-agent): add AggregatorService + AggregatorHandle with channe…
litianningdatadog Mar 9, 2026
44ad97f
feat(log-agent): add LogFlusher with zstd compression, retry logic, a…
litianningdatadog Mar 9, 2026
42f2a6e
fix(log-agent): align flusher tests with spec requirements
litianningdatadog Mar 9, 2026
3352802
fix(log-agent): code quality improvements in flusher and config
litianningdatadog Mar 9, 2026
8eb882c
feat(log-agent): integrate datadog-log-agent into serverless-compat b…
litianningdatadog Mar 9, 2026
de898f9
fix(log-agent): improve main.rs wiring — early return on missing API …
litianningdatadog Mar 9, 2026
c5d5f55
test(log-agent): add integration test suite covering full pipeline, b…
litianningdatadog Mar 9, 2026
b961465
feat(log-agent): derive Clone on LogFlusher
litianningdatadog Mar 9, 2026
75b11e5
- add CLAUDE.md to .gitignore
litianningdatadog Mar 10, 2026
e8522af
chore(log-agent): add hyper/http-body-util/hyper-util deps for log se…
litianningdatadog Mar 10, 2026
95163cd
feat(log-agent): add LogServer HTTP intake skeleton
litianningdatadog Mar 10, 2026
ae8161c
test(log-agent): add LogServer HTTP intake integration tests
litianningdatadog Mar 10, 2026
b1906e8
feat(serverless-compat): start LogServer HTTP intake on DD_LOGS_PORT …
litianningdatadog Mar 10, 2026
0a91ea6
chore: remove stale TODO comment — LogServer wires the log-ingestion …
litianningdatadog Mar 10, 2026
34a5530
test(log-agent): add unit and integration tests for LogServer network…
litianningdatadog Mar 10, 2026
0a5eed8
test(log-agent): add network intake integration tests for LogServer
litianningdatadog Mar 10, 2026
45f9a92
fix(log-agent): treat 408/425/429 as retryable instead of permanent 4xx
litianningdatadog Mar 10, 2026
18aa732
fix(serverless-compat): warn when log agent flush fails
litianningdatadog Mar 10, 2026
2402301
fix(log-server): accept chunked requests by checking Content-Length h…
litianningdatadog Mar 10, 2026
ebd1ed3
chore(log-agent): change default log intake port to 10517 and documen…
litianningdatadog Mar 10, 2026
528f2d1
feat(log-agent): send additional endpoints concurrently in flush()
litianningdatadog Mar 11, 2026
2f465e6
perf(log-agent): dispatch all log batches concurrently in flush()
litianningdatadog Mar 11, 2026
5439458
fix(log-agent): drain response body after each HTTP send
litianningdatadog Mar 11, 2026
ca8ebec
feat(log-agent): per-endpoint API key for additional_endpoints
litianningdatadog Mar 11, 2026
c8c3dc7
fix(log-agent): fall back to uncompressed on zstd compression failure
litianningdatadog Mar 11, 2026
3fc3042
feat(log-agent): implement cross-invocation retry via RequestBuilder …
litianningdatadog Mar 11, 2026
9b2bc29
fix(log-agent): account for JSON framing bytes in batch size checks
litianningdatadog Mar 12, 2026
fc8c23a
test(log-agent): replace tautological OPW URL test with real behavior…
litianningdatadog Mar 12, 2026
de28793
test(log-agent): remove no-op compile-time size_of test
litianningdatadog Mar 12, 2026
c5fd8b9
refactor(log-agent): rename LogEntry::new to from_message; drop compr…
litianningdatadog Mar 12, 2026
8601155
refactor(log-agent): rename LogEntry → IntakeEntry and log_entry → in…
litianningdatadog Mar 12, 2026
6036707
refactor(log-agent): drop Log prefix from Aggregator and AggregatorCo…
litianningdatadog Mar 12, 2026
445909d
refactor(log-agent): rename FlusherMode → Destination; add #[must_use…
litianningdatadog Mar 12, 2026
77378b6
chore: fix all clippy and fmt warnings across workspace
litianningdatadog Mar 12, 2026
e017903
feat(datadog-log-agent): add LogEntry and FlusherMode type aliases
litianningdatadog Mar 12, 2026
51700e5
revert(datadog-log-agent): remove LogEntry/FlusherMode type aliases
litianningdatadog Mar 12, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target
/.idea
/CLAUDE.md

22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ resolver = "2"
members = [
"crates/*",
]
exclude = [
"crates/.claude",
]

[workspace.package]
edition = "2024"
Expand Down
1 change: 1 addition & 0 deletions crates/datadog-agent-config/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ impl ConfigSource for EnvConfigSource {

#[cfg_attr(coverage_nightly, coverage(off))] // Test modules skew coverage metrics
#[cfg(test)]
#[allow(clippy::result_large_err)]
mod tests {
use std::time::Duration;

Expand Down
1 change: 1 addition & 0 deletions crates/datadog-agent-config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@ where

#[cfg_attr(coverage_nightly, coverage(off))] // Test modules skew coverage metrics
#[cfg(test)]
#[allow(clippy::result_large_err)]
pub mod tests {
use libdd_trace_obfuscation::replacer::parse_rules_from_string;

Expand Down
1 change: 1 addition & 0 deletions crates/datadog-agent-config/yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ impl ConfigSource for YamlConfigSource {

#[cfg_attr(coverage_nightly, coverage(off))] // Test modules skew coverage metrics
#[cfg(test)]
#[allow(clippy::result_large_err)]
mod tests {
use std::path::Path;
use std::time::Duration;
Expand Down
35 changes: 35 additions & 0 deletions crates/datadog-log-agent/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2025-Present Datadog, Inc. https://www.datadoghq.com/
# SPDX-License-Identifier: Apache-2.0

[package]
name = "datadog-log-agent"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename this to datadog-logs-agent

Singular doesn't reflect the standard across Datadog

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d keep it as-is to align with the naming convention of datadog-trace-agent

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the difference with a trace agent is that a trace is a set on spans, whereas we don't have a term to group logs, that's why its called logs agent and it is something we're bringing from the original Go agent – the code in this repo shouldn't be taken as a source of truth, the trace agent itself lacks a lot of functionality

version = "0.1.0"
edition.workspace = true
license.workspace = true

[lib]
bench = false

[dependencies]
datadog-fips = { path = "../datadog-fips" }
reqwest = { version = "0.12.4", features = ["json", "http2"], default-features = false }
serde = { version = "1.0.197", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.116", default-features = false, features = ["alloc"] }
thiserror = { version = "1.0.58", default-features = false }
hyper = { version = "1", features = ["http1", "server"] }
http-body-util = "0.1"
hyper-util = { version = "0.1", features = ["tokio"] }
futures = { version = "0.3", default-features = false, features = ["alloc"] }
tokio = { version = "1.37.0", default-features = false, features = ["sync", "net"] }
tracing = { version = "0.1.40", default-features = false }
zstd = { version = "0.13.3", default-features = false }

[dev-dependencies]
http = "1"
mockito = { version = "1.5.0", default-features = false }
serde_json = { version = "1.0.116", default-features = false, features = ["alloc"] }
reqwest = { version = "0.12.4", features = ["json"], default-features = false }
tokio = { version = "1.37.0", default-features = false, features = ["macros", "rt-multi-thread", "net", "time"] }

[features]
default = []
196 changes: 196 additions & 0 deletions crates/datadog-log-agent/examples/send_logs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
// Copyright 2023-Present Datadog, Inc. https://www.datadoghq.com/
// SPDX-License-Identifier: Apache-2.0

//! Local test helper: inserts sample log entries and flushes them via the log agent pipeline.
//!
//! # Usage
//!
//! ## Flush to a local capture server (recommended for local dev)
//!
//! The easiest way — runs capture server and example together:
//! ./scripts/test-log-intake.sh
//!
//! Or manually in two terminals:
//!
//! In terminal 1 — start the capture server (handles POST, prints JSON):
//! python3 scripts/test-log-intake.sh # not available standalone
//! # Use the script above, or run: python3 -c "$(sed -n '/PYEOF/,/PYEOF/p' scripts/test-log-intake.sh)"
//!
//! In terminal 2 — run this example:
//! DD_OBSERVABILITY_PIPELINES_WORKER_LOGS_ENABLED=true \
//! DD_OBSERVABILITY_PIPELINES_WORKER_LOGS_URL=http://localhost:9999/logs \
//! DD_API_KEY=local-test-key \
//! cargo run -p datadog-log-agent --example send_logs
//!
//! NOTE: `python3 -m http.server` does NOT work — it rejects POST requests.
//!
//! ## Flush to a real Datadog endpoint
//!
//! DD_API_KEY=<your-key> \
//! DD_SITE=datadoghq.com \
//! cargo run -p datadog-log-agent --example send_logs
//!
//! ## Configuration via env vars
//!
//! | Variable | Default |
//! |--------------------------------------------------|--------------------|
//! | DD_API_KEY | (empty) |
//! | DD_SITE | datadoghq.com |
//! | DD_LOGS_CONFIG_USE_COMPRESSION | true |
//! | DD_LOGS_CONFIG_COMPRESSION_LEVEL | 3 |
//! | DD_OBSERVABILITY_PIPELINES_WORKER_LOGS_ENABLED | false |
//! | DD_OBSERVABILITY_PIPELINES_WORKER_LOGS_URL | (empty) |
//! | LOG_ENTRY_COUNT | 5 |

use datadog_log_agent::{
AggregatorService, Destination, IntakeEntry, LogFlusher, LogFlusherConfig,
};

#[allow(clippy::disallowed_methods)] // plain reqwest::Client for local testing
#[tokio::main]
async fn main() {
let entry_count: usize = std::env::var("LOG_ENTRY_COUNT")
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(5);

let config = LogFlusherConfig::from_env();

// Print effective configuration
let (endpoint, compressed) = describe_config(&config);
println!("──────────────────────────────────────────");
println!(" datadog-log-agent local test");
println!("──────────────────────────────────────────");
println!(" endpoint : {endpoint}");
println!(" api_key : {}", mask(&config.api_key));
println!(" compressed : {compressed}");
println!(" entries : {entry_count}");
println!("──────────────────────────────────────────");

// Start aggregator service
let (service, handle) = AggregatorService::new();
tokio::spawn(service.run());

// Insert sample entries representing different runtimes
let mut entries = Vec::with_capacity(entry_count);

for i in 0..entry_count {
let entry = match i % 3 {
0 => lambda_entry(i),
1 => azure_entry(i),
_ => plain_entry(i),
};
entries.push(entry);
}

println!("\nInserting {entry_count} log entries...");
handle.insert_batch(entries).expect("insert_batch failed");

// Build HTTP client
let client = reqwest::Client::builder()
.timeout(config.flush_timeout)
.build()
.expect("failed to build HTTP client");

// Flush
println!("Flushing to {endpoint}...");
let flusher = LogFlusher::new(config, client, handle);
let failed = flusher.flush(vec![]).await;

if failed.is_empty() {
println!("\n✓ Flush succeeded");
} else {
eprintln!("\n✗ Flush failed — check endpoint and API key");
std::process::exit(1);
}
}

// ── Sample log entry builders ─────────────────────────────────────────────────

fn lambda_entry(i: usize) -> IntakeEntry {
let mut attrs = serde_json::Map::new();
attrs.insert(
"lambda".to_string(),
serde_json::json!({
"arn": "arn:aws:lambda:us-east-1:123456789012:function:my-fn",
"request_id": format!("req-{i:04}")
}),
);
IntakeEntry {
message: format!("[lambda] invocation #{i} completed"),
timestamp: now_ms(),
hostname: Some("arn:aws:lambda:us-east-1:123456789012:function:my-fn".to_string()),
service: Some("my-fn".to_string()),
ddsource: Some("lambda".to_string()),
ddtags: Some("env:local,runtime:lambda".to_string()),
status: Some("info".to_string()),
attributes: attrs,
}
}

fn azure_entry(i: usize) -> IntakeEntry {
let mut attrs = serde_json::Map::new();
attrs.insert(
"azure".to_string(),
serde_json::json!({
"resource_id": "/subscriptions/sub-123/resourceGroups/rg/providers/Microsoft.Web/sites/my-fn",
"operation_name": "Microsoft.Web/sites/functions/run/action"
}),
);
IntakeEntry {
message: format!("[azure] function triggered #{i}"),
timestamp: now_ms(),
hostname: Some("my-azure-fn".to_string()),
service: Some("payments".to_string()),
ddsource: Some("azure-functions".to_string()),
ddtags: Some("env:local,runtime:azure".to_string()),
status: Some("info".to_string()),
attributes: attrs,
}
}

fn plain_entry(i: usize) -> IntakeEntry {
IntakeEntry {
message: format!("[generic] log message #{i}"),
timestamp: now_ms(),
hostname: Some("localhost".to_string()),
service: Some("test-service".to_string()),
ddsource: Some("rust".to_string()),
ddtags: Some("env:local".to_string()),
status: if i.is_multiple_of(5) {
Some("error".to_string())
} else {
Some("info".to_string())
},
attributes: serde_json::Map::new(),
}
}

// ── Helpers ───────────────────────────────────────────────────────────────────

fn now_ms() -> i64 {
std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.map(|d| d.as_millis() as i64)
.unwrap_or(0)
}

fn describe_config(config: &LogFlusherConfig) -> (String, bool) {
match &config.mode {
Destination::Datadog => (
format!("https://http-intake.logs.{}/api/v2/logs", config.site),
config.use_compression,
),
Destination::ObservabilityPipelinesWorker { url } => (url.clone(), false),
}
}

fn mask(s: &str) -> String {
if s.is_empty() {
return "(not set)".to_string();
}
if s.len() <= 8 {
return "*".repeat(s.len());
}
format!("{}…{}", &s[..4], &s[s.len() - 4..])
}
Loading
Loading