Skip to content

Commit 04a8b7d

Browse files
feat: dual shipping APM support (#735)
Adds support for dual shipping traces to endpoints configured using the `apm_config` YAML or `DD_APM_CONFIG_ADDITIONAL_ENDPOINTS` env var config. #### Additional Notes: - Bumped libdatadog (and serverless-components) to include DataDog/libdatadog#1139 - Adds configuration option to set compression level for trace payloads
1 parent 70aa67f commit 04a8b7d

File tree

14 files changed

+187
-201
lines changed

14 files changed

+187
-201
lines changed

bottlecap/Cargo.lock

Lines changed: 23 additions & 152 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bottlecap/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ datadog-trace-protobuf = { git = "https://github.com/DataDog/libdatadog", rev =
5757
datadog-trace-utils = { git = "https://github.com/DataDog/libdatadog", rev = "8a49c7df2d9cbf05118bfd5b85772676f71b34f2" , features = ["mini_agent"] }
5858
datadog-trace-normalization = { git = "https://github.com/DataDog/libdatadog", rev = "8a49c7df2d9cbf05118bfd5b85772676f71b34f2" }
5959
datadog-trace-obfuscation = { git = "https://github.com/DataDog/libdatadog", rev = "8a49c7df2d9cbf05118bfd5b85772676f71b34f2" }
60-
dogstatsd = { git = "https://github.com/DataDog/serverless-components", rev = "985120329d0ba96c1ec8d719cc38e1f7ce11a092", default-features = false }
61-
datadog-trace-agent = { git = "https://github.com/DataDog/serverless-components", rev = "c3d8ed4f90591c6958921145d485463860307f78" }
62-
datadog-fips = { git = "https://github.com/DataDog/serverless-components", rev = "c3d8ed4f90591c6958921145d485463860307f78", default-features = false }
60+
dogstatsd = { git = "https://github.com/DataDog/serverless-components", rev = "d131de8419c191ce21c91bb30b5915c4d8a2cc5a", default-features = false }
61+
datadog-trace-agent = { git = "https://github.com/DataDog/serverless-components", rev = "d131de8419c191ce21c91bb30b5915c4d8a2cc5a" }
62+
datadog-fips = { git = "https://github.com/DataDog/serverless-components", rev = "d131de8419c191ce21c91bb30b5915c4d8a2cc5a", default-features = false }
6363
axum = { version = "0.8.4", default-features = false, features = ["default"] }
6464

6565
[dev-dependencies]

bottlecap/LICENSE-3rdparty.csv

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ log,https://github.com/rust-lang/log,MIT OR Apache-2.0,The Rust Project Develope
108108
matchers,https://github.com/hawkw/matchers,MIT,Eliza Weisman <[email protected]>
109109
matchit,https://github.com/ibraheemdev/matchit,MIT AND BSD-3-Clause,Ibraheem Ahmed <[email protected]>
110110
memchr,https://github.com/BurntSushi/memchr,Unlicense OR MIT,"Andrew Gallant <[email protected]>, bluss"
111-
memfd,https://github.com/lucab/memfd-rs,MIT OR Apache-2.0,"Luca Bruno <[email protected]>, Simonas Kazlauskas <[email protected]>"
112111
mime,https://github.com/hyperium/mime,MIT OR Apache-2.0,Sean McArthur <[email protected]>
113112
miniz_oxide,https://github.com/Frommi/miniz_oxide/tree/master/miniz_oxide,MIT OR Zlib OR Apache-2.0,"Frommi <[email protected]>, oyvindln <[email protected]>, Rich Geldreich [email protected]"
114113
mio,https://github.com/tokio-rs/mio,MIT,"Carl Lerche <[email protected]>, Thomas de Zeeuw <[email protected]>, Tokio Contributors <[email protected]>"

bottlecap/src/bin/bottlecap/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,11 +1057,11 @@ fn start_trace_agent(
10571057
let stats_processor = Arc::new(stats_processor::ServerlessStatsProcessor {});
10581058

10591059
// Traces
1060-
let trace_flusher = Arc::new(trace_flusher::ServerlessTraceFlusher {
1061-
aggregator: trace_aggregator.clone(),
1062-
config: Arc::clone(config),
1063-
api_key_factory: Arc::clone(api_key_factory),
1064-
});
1060+
let trace_flusher = Arc::new(trace_flusher::ServerlessTraceFlusher::new(
1061+
trace_aggregator.clone(),
1062+
config.clone(),
1063+
api_key_factory.clone(),
1064+
));
10651065

10661066
let obfuscation_config = obfuscation_config::ObfuscationConfig {
10671067
tag_replace_rules: config.apm_replace_tags.clone(),

bottlecap/src/config/env.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,21 @@ pub struct EnvConfig {
163163
/// @env `DD_APM_CONFIG_OBFUSCATION_HTTP_REMOVE_PATHS_WITH_DIGITS`
164164
#[serde(deserialize_with = "deserialize_optional_bool_from_anything")]
165165
pub apm_config_obfuscation_http_remove_paths_with_digits: Option<bool>,
166+
/// @env `DD_APM_CONFIG_COMPRESSION_LEVEL`
167+
///
168+
/// The Agent compresses traces before sending them. The `compression_level` parameter
169+
/// accepts values from 0 (no compression) to 9 (maximum compression but
170+
/// higher resource usage).
171+
pub apm_config_compression_level: Option<i32>,
166172
/// @env `DD_APM_FEATURES`
167173
#[serde(deserialize_with = "deserialize_array_from_comma_separated_string")]
168174
pub apm_features: Vec<String>,
175+
/// @env `DD_APM_ADDITIONAL_ENDPOINTS`
176+
///
177+
/// Additional endpoints to send traces to.
178+
/// <https://docs.datadoghq.com/agent/configuration/dual-shipping/?tab=helm#environment-variable-configuration-1>
179+
#[serde(deserialize_with = "deserialize_additional_endpoints")]
180+
pub apm_additional_endpoints: HashMap<String, Vec<String>>,
169181
//
170182
// Trace Propagation
171183
/// @env `DD_TRACE_PROPAGATION_STYLE`
@@ -347,7 +359,9 @@ fn merge_config(config: &mut Config, env_config: &EnvConfig) {
347359
env_config,
348360
apm_config_obfuscation_http_remove_paths_with_digits
349361
);
362+
merge_option_to_value!(config, env_config, apm_config_compression_level);
350363
merge_vec!(config, env_config, apm_features);
364+
merge_hashmap!(config, env_config, apm_additional_endpoints);
351365

352366
// Trace Propagation
353367
merge_vec!(config, env_config, trace_propagation_style);
@@ -533,10 +547,12 @@ mod tests {
533547
"DD_APM_CONFIG_OBFUSCATION_HTTP_REMOVE_PATHS_WITH_DIGITS",
534548
"true",
535549
);
550+
jail.set_env("DD_APM_CONFIG_COMPRESSION_LEVEL", "3");
536551
jail.set_env(
537552
"DD_APM_FEATURES",
538553
"enable_otlp_compute_top_level_by_span_kind,enable_stats_by_span_kind",
539554
);
555+
jail.set_env("DD_APM_ADDITIONAL_ENDPOINTS", "{\"https://trace.agent.datadoghq.com\": [\"apikey2\", \"apikey3\"], \"https://trace.agent.datadoghq.eu\": [\"apikey4\"]}");
540556

541557
// Trace Propagation
542558
jail.set_env("DD_TRACE_PROPAGATION_STYLE", "datadog");
@@ -673,10 +689,21 @@ mod tests {
673689
),
674690
apm_config_obfuscation_http_remove_query_string: true,
675691
apm_config_obfuscation_http_remove_paths_with_digits: true,
692+
apm_config_compression_level: 3,
676693
apm_features: vec![
677694
"enable_otlp_compute_top_level_by_span_kind".to_string(),
678695
"enable_stats_by_span_kind".to_string(),
679696
],
697+
apm_additional_endpoints: HashMap::from([
698+
(
699+
"https://trace.agent.datadoghq.com".to_string(),
700+
vec!["apikey2".to_string(), "apikey3".to_string()],
701+
),
702+
(
703+
"https://trace.agent.datadoghq.eu".to_string(),
704+
vec!["apikey4".to_string()],
705+
),
706+
]),
680707
trace_propagation_style: vec![TracePropagationStyle::Datadog],
681708
trace_propagation_style_extract: vec![TracePropagationStyle::B3],
682709
trace_propagation_extract_first: true,

0 commit comments

Comments
 (0)