-
Notifications
You must be signed in to change notification settings - Fork 0
feat(log-agent): add datadog-log-agent crate and wire into serverless-compat #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
litianningdatadog
wants to merge
40
commits into
main
Choose a base branch
from
tianning.li/SVLS-8573-datadog-log-agent
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,706
−75
Open
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 cf28960
- use serde flatten with Map instead of Option<Map> to avoid deser quirk
litianningdatadog 2555810
feat(log-agent): add LogAggregator with size/count-bounded batch coll…
litianningdatadog 54a16fa
refactor(log-agent): clean up get_batch loop to include comma bytes i…
litianningdatadog a9ee357
feat(log-agent): add AggregatorService + AggregatorHandle with channe…
litianningdatadog 44ad97f
feat(log-agent): add LogFlusher with zstd compression, retry logic, a…
litianningdatadog 42f2a6e
fix(log-agent): align flusher tests with spec requirements
litianningdatadog 3352802
fix(log-agent): code quality improvements in flusher and config
litianningdatadog 8eb882c
feat(log-agent): integrate datadog-log-agent into serverless-compat b…
litianningdatadog de898f9
fix(log-agent): improve main.rs wiring — early return on missing API …
litianningdatadog c5d5f55
test(log-agent): add integration test suite covering full pipeline, b…
litianningdatadog b961465
feat(log-agent): derive Clone on LogFlusher
litianningdatadog 75b11e5
- add CLAUDE.md to .gitignore
litianningdatadog e8522af
chore(log-agent): add hyper/http-body-util/hyper-util deps for log se…
litianningdatadog 95163cd
feat(log-agent): add LogServer HTTP intake skeleton
litianningdatadog ae8161c
test(log-agent): add LogServer HTTP intake integration tests
litianningdatadog b1906e8
feat(serverless-compat): start LogServer HTTP intake on DD_LOGS_PORT …
litianningdatadog 0a91ea6
chore: remove stale TODO comment — LogServer wires the log-ingestion …
litianningdatadog 34a5530
test(log-agent): add unit and integration tests for LogServer network…
litianningdatadog 0a5eed8
test(log-agent): add network intake integration tests for LogServer
litianningdatadog 45f9a92
fix(log-agent): treat 408/425/429 as retryable instead of permanent 4xx
litianningdatadog 18aa732
fix(serverless-compat): warn when log agent flush fails
litianningdatadog 2402301
fix(log-server): accept chunked requests by checking Content-Length h…
litianningdatadog ebd1ed3
chore(log-agent): change default log intake port to 10517 and documen…
litianningdatadog 528f2d1
feat(log-agent): send additional endpoints concurrently in flush()
litianningdatadog 2f465e6
perf(log-agent): dispatch all log batches concurrently in flush()
litianningdatadog 5439458
fix(log-agent): drain response body after each HTTP send
litianningdatadog ca8ebec
feat(log-agent): per-endpoint API key for additional_endpoints
litianningdatadog c8c3dc7
fix(log-agent): fall back to uncompressed on zstd compression failure
litianningdatadog 3fc3042
feat(log-agent): implement cross-invocation retry via RequestBuilder …
litianningdatadog 9b2bc29
fix(log-agent): account for JSON framing bytes in batch size checks
litianningdatadog fc8c23a
test(log-agent): replace tautological OPW URL test with real behavior…
litianningdatadog de28793
test(log-agent): remove no-op compile-time size_of test
litianningdatadog c5fd8b9
refactor(log-agent): rename LogEntry::new to from_message; drop compr…
litianningdatadog 8601155
refactor(log-agent): rename LogEntry → IntakeEntry and log_entry → in…
litianningdatadog 6036707
refactor(log-agent): drop Log prefix from Aggregator and AggregatorCo…
litianningdatadog 445909d
refactor(log-agent): rename FlusherMode → Destination; add #[must_use…
litianningdatadog 77378b6
chore: fix all clippy and fmt warnings across workspace
litianningdatadog e017903
feat(datadog-log-agent): add LogEntry and FlusherMode type aliases
litianningdatadog 51700e5
revert(datadog-log-agent): remove LogEntry/FlusherMode type aliases
litianningdatadog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| /target | ||
| /.idea | ||
| /CLAUDE.md | ||
|
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| 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 = [] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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..]) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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-agentSingular doesn't reflect the standard across Datadog
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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