Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 15 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/datadog-serverless-compat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ license.workspace = true
description = "Binary to run trace-agent and dogstatsd servers in Serverless environments"

[dependencies]
datadog-serverless-config = { path = "../datadog-serverless-config" }
datadog-trace-agent = { path = "../datadog-trace-agent" }
libdd-trace-utils = { git = "https://github.com/DataDog/libdatadog", rev = "435107c245112397914935c0f7148a18b91cafc6" }
dogstatsd = { path = "../dogstatsd", default-features = true }
Expand Down
3 changes: 2 additions & 1 deletion crates/datadog-serverless-compat/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ use tracing::{debug, error, info};
use tracing_subscriber::EnvFilter;
use zstd::zstd_safe::CompressionLevel;

use datadog_serverless_config as config;
use datadog_trace_agent::{
aggregator::TraceAggregator,
config, env_verifier, mini_agent, stats_flusher, stats_processor,
env_verifier, mini_agent, stats_flusher, stats_processor,
trace_flusher::{self, TraceFlusher},
trace_processor,
};
Expand Down
22 changes: 22 additions & 0 deletions crates/datadog-serverless-config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "datadog-serverless-config"
version = "0.1.0"
license.workspace = true
edition.workspace = true

[dependencies]
anyhow = "1.0"
hyper = { version = "1.6", features = ["http1"] }
libdd-common = { git = "https://github.com/DataDog/libdatadog", rev = "435107c245112397914935c0f7148a18b91cafc6" }
libdd-trace-obfuscation = { git = "https://github.com/DataDog/libdatadog", rev = "435107c245112397914935c0f7148a18b91cafc6" }
libdd-trace-utils = { git = "https://github.com/DataDog/libdatadog", rev = "435107c245112397914935c0f7148a18b91cafc6", features = [
"mini_agent",
] }

[dev-dependencies]
serial_test = "2.0.0"
duplicate = "0.4.1"
libdd-trace-utils = { git = "https://github.com/DataDog/libdatadog", rev = "435107c245112397914935c0f7148a18b91cafc6", features = [
"test-utils",
] }

Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
// Copyright 2023-Present Datadog, Inc. https://www.datadoghq.com/
// SPDX-License-Identifier: Apache-2.0

#![cfg_attr(not(test), deny(clippy::panic))]
#![cfg_attr(not(test), deny(clippy::unwrap_used))]
#![cfg_attr(not(test), deny(clippy::expect_used))]
#![cfg_attr(not(test), deny(clippy::todo))]
#![cfg_attr(not(test), deny(clippy::unimplemented))]

use libdd_common::Endpoint;
use std::borrow::Cow;
use std::collections::HashMap;
Expand All @@ -23,6 +29,12 @@ pub struct Tags {
function_tags_string: OnceLock<String>,
}

impl Default for Tags {
fn default() -> Self {
Self::new()
}
}

impl Tags {
pub fn from_env_string(env_tags: &str) -> Self {
let mut tags = HashMap::new();
Expand Down Expand Up @@ -168,14 +180,14 @@ mod tests {
use std::collections::HashMap;
use std::env;

use crate::config;
use crate::{Config, Tags};

#[test]
#[serial]
fn test_error_if_unable_to_identify_env() {
env::set_var("DD_API_KEY", "_not_a_real_key_");

let config = config::Config::new();
let config = Config::new();
assert!(config.is_err());
assert_eq!(
config.unwrap_err().to_string(),
Expand All @@ -188,7 +200,7 @@ mod tests {
#[serial]
fn test_error_if_no_api_key_env_var() {
env::remove_var("DD_API_KEY");
let config = config::Config::new();
let config = Config::new();
assert!(config.is_err());
assert_eq!(
config.unwrap_err().to_string(),
Expand All @@ -201,7 +213,7 @@ mod tests {
fn test_default_trace_and_trace_stats_urls() {
env::set_var("DD_API_KEY", "_not_a_real_key_");
env::set_var("K_SERVICE", "function_name");
let config_res = config::Config::new();
let config_res = Config::new();
assert!(config_res.is_ok());
let config = config_res.unwrap();
assert_eq!(
Expand Down Expand Up @@ -231,7 +243,7 @@ mod tests {
env::set_var("DD_API_KEY", "_not_a_real_key_");
env::set_var("K_SERVICE", "function_name");
env::set_var("DD_SITE", dd_site);
let config_res = config::Config::new();
let config_res = Config::new();
assert!(config_res.is_ok());
let config = config_res.unwrap();
assert_eq!(config.trace_intake.url, expected_url);
Expand All @@ -255,7 +267,7 @@ mod tests {
env::set_var("DD_API_KEY", "_not_a_real_key_");
env::set_var("K_SERVICE", "function_name");
env::set_var("DD_SITE", dd_site);
let config_res = config::Config::new();
let config_res = Config::new();
assert!(config_res.is_ok());
let config = config_res.unwrap();
assert_eq!(config.trace_stats_intake.url, expected_url);
Expand All @@ -270,7 +282,7 @@ mod tests {
env::set_var("DD_API_KEY", "_not_a_real_key_");
env::set_var("K_SERVICE", "function_name");
env::set_var("DD_APM_DD_URL", "http://127.0.0.1:3333");
let config_res = config::Config::new();
let config_res = Config::new();
assert!(config_res.is_ok());
let config = config_res.unwrap();
assert_eq!(
Expand All @@ -291,7 +303,7 @@ mod tests {
fn test_default_dogstatsd_port() {
env::set_var("DD_API_KEY", "_not_a_real_key_");
env::set_var("ASCSVCRT_SPRING__APPLICATION__NAME", "test-spring-app");
let config_res = config::Config::new();
let config_res = Config::new();
assert!(config_res.is_ok());
let config = config_res.unwrap();
assert_eq!(config.dd_dogstatsd_port, 8125);
Expand All @@ -305,7 +317,7 @@ mod tests {
env::set_var("DD_API_KEY", "_not_a_real_key_");
env::set_var("ASCSVCRT_SPRING__APPLICATION__NAME", "test-spring-app");
env::set_var("DD_DOGSTATSD_PORT", "18125");
let config_res = config::Config::new();
let config_res = Config::new();
println!("{:?}", config_res);
assert!(config_res.is_ok());
let config = config_res.unwrap();
Expand All @@ -315,11 +327,11 @@ mod tests {
env::remove_var("DD_DOGSTATSD_PORT");
}

fn test_config_with_dd_tags(dd_tags: &str) -> config::Config {
fn test_config_with_dd_tags(dd_tags: &str) -> Config {
env::set_var("DD_API_KEY", "_not_a_real_key_");
env::set_var("ASCSVCRT_SPRING__APPLICATION__NAME", "test-spring-app");
env::set_var("DD_TAGS", dd_tags);
let config_res = config::Config::new();
let config_res = Config::new();
assert!(config_res.is_ok());
let config = config_res.unwrap();
env::remove_var("DD_API_KEY");
Expand Down
4 changes: 1 addition & 3 deletions crates/datadog-trace-agent/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ version = "0.1.0"
license.workspace = true
edition.workspace = true

[lib]
bench = false

[dependencies]
anyhow = "1.0"
hyper = { version = "1.6", features = ["http1", "client", "server"] }
Expand All @@ -20,6 +17,7 @@ async-trait = "0.1.64"
tracing = { version = "0.1", default-features = false }
serde = { version = "1.0.145", features = ["derive"] }
serde_json = "1.0"
datadog-serverless-config = { path = "../datadog-serverless-config" }
libdd-common = { git = "https://github.com/DataDog/libdatadog", rev = "435107c245112397914935c0f7148a18b91cafc6" }
libdd-trace-obfuscation = { git = "https://github.com/DataDog/libdatadog", rev = "435107c245112397914935c0f7148a18b91cafc6" }
libdd-trace-protobuf = { git = "https://github.com/DataDog/libdatadog", rev = "435107c245112397914935c0f7148a18b91cafc6" }
Expand Down
1 change: 0 additions & 1 deletion crates/datadog-trace-agent/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#![cfg_attr(not(test), deny(clippy::unimplemented))]

pub mod aggregator;
pub mod config;
pub mod env_verifier;
pub mod http_utils;
pub mod mini_agent;
Expand Down
7 changes: 4 additions & 3 deletions crates/datadog-trace-agent/src/mini_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ use tokio::sync::mpsc::{self, Receiver, Sender};
use tracing::{debug, error};

use crate::http_utils::log_and_create_http_response;
use crate::{config, env_verifier, stats_flusher, stats_processor, trace_flusher, trace_processor};
use crate::{env_verifier, stats_flusher, stats_processor, trace_flusher, trace_processor};
use datadog_serverless_config::Config;
use libdd_trace_protobuf::pb;
use libdd_trace_utils::trace_utils;
use libdd_trace_utils::trace_utils::SendData;
Expand All @@ -26,7 +27,7 @@ const TRACER_PAYLOAD_CHANNEL_BUFFER_SIZE: usize = 10;
const STATS_PAYLOAD_CHANNEL_BUFFER_SIZE: usize = 10;

pub struct MiniAgent {
pub config: Arc<config::Config>,
pub config: Arc<Config>,
pub trace_processor: Arc<dyn trace_processor::TraceProcessor + Send + Sync>,
pub trace_flusher: Arc<dyn trace_flusher::TraceFlusher + Send + Sync>,
pub stats_processor: Arc<dyn stats_processor::StatsProcessor + Send + Sync>,
Expand Down Expand Up @@ -163,7 +164,7 @@ impl MiniAgent {
}

async fn trace_endpoint_handler(
config: Arc<config::Config>,
config: Arc<Config>,
req: hyper_migration::HttpRequest,
trace_processor: Arc<dyn trace_processor::TraceProcessor + Send + Sync>,
trace_tx: Sender<SendData>,
Expand Down
2 changes: 1 addition & 1 deletion crates/datadog-trace-agent/src/stats_flusher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use tracing::{debug, error};
use libdd_trace_protobuf::pb;
use libdd_trace_utils::stats_utils;

use crate::config::Config;
use datadog_serverless_config::Config;

#[async_trait]
pub trait StatsFlusher {
Expand Down
2 changes: 1 addition & 1 deletion crates/datadog-trace-agent/src/stats_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use tracing::debug;
use libdd_trace_protobuf::pb;
use libdd_trace_utils::stats_utils;

use crate::config::Config;
use crate::http_utils::{self, log_and_create_http_response};
use datadog_serverless_config::Config;

#[async_trait]
pub trait StatsProcessor {
Expand Down
2 changes: 1 addition & 1 deletion crates/datadog-trace-agent/src/trace_flusher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use libdd_trace_utils::trace_utils;
use libdd_trace_utils::trace_utils::SendData;

use crate::aggregator::TraceAggregator;
use crate::config::Config;
use datadog_serverless_config::Config;

#[async_trait]
pub trait TraceFlusher {
Expand Down
14 changes: 6 additions & 8 deletions crates/datadog-trace-agent/src/trace_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ use libdd_trace_utils::trace_utils::{self};
use libdd_trace_utils::trace_utils::{EnvironmentType, SendData};
use libdd_trace_utils::tracer_payload::{TraceChunkProcessor, TracerPayloadCollection};

use crate::{
config::Config,
http_utils::{self, log_and_create_http_response, log_and_create_traces_success_http_response},
use crate::http_utils::{
self, log_and_create_http_response, log_and_create_traces_success_http_response,
};
use datadog_serverless_config::Config;

const TRACER_PAYLOAD_FUNCTION_TAGS_TAG_KEY: &str = "_dd.tags.function";

Expand Down Expand Up @@ -101,7 +101,7 @@ impl TraceProcessor for ServerlessTraceProcessor {
// double check content length is < max request content length in case transfer encoding is used
if body_size > config.max_request_content_length {
return log_and_create_http_response(
&format!("Error processing traces: Payload too large"),
"Error processing traces: Payload too large",
StatusCode::PAYLOAD_TOO_LARGE,
);
}
Expand Down Expand Up @@ -163,10 +163,8 @@ mod tests {
use std::{collections::HashMap, sync::Arc, time::UNIX_EPOCH};
use tokio::sync::mpsc::{self, Receiver, Sender};

use crate::{
config::{Config, Tags},
trace_processor::{self, TraceProcessor, TRACER_PAYLOAD_FUNCTION_TAGS_TAG_KEY},
};
use crate::trace_processor::{self, TraceProcessor, TRACER_PAYLOAD_FUNCTION_TAGS_TAG_KEY};
use datadog_serverless_config::{Config, Tags};
use libdd_common::{hyper_migration, Endpoint};
use libdd_trace_protobuf::pb;
use libdd_trace_utils::test_utils::{create_test_gcp_json_span, create_test_gcp_span};
Expand Down
3 changes: 0 additions & 3 deletions crates/dogstatsd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ version = "0.1.0"
edition.workspace = true
license.workspace = true

[lib]
bench = false

[dependencies]
datadog-protos = { version = "0.1.0", default-features = false, git = "https://github.com/DataDog/saluki/", rev = "f863626dbfe3c59bb390985fa6530b0621c2a0a2" }
ddsketch-agent = { version = "0.1.0", default-features = false, git = "https://github.com/DataDog/saluki/", rev = "f863626dbfe3c59bb390985fa6530b0621c2a0a2" }
Expand Down
Loading