Skip to content

Commit 2049503

Browse files
authored
[SVLS-8211] feat: Add timeout for requests to span_dedup_service (#986)
## Problem Span dedup service sometimes fails to return the result and thus logs the error: > DD_EXTENSION | ERROR | Failed to send check_and_add response: true I see this error in our Self Monitoring and a customer's account. Also I believe it causes extension to fail to receive traces from the tracer, causing missing traces. This is because the caller of span dedup is in `process_traces()`, which is the function that handles the tracer's HTTP request to send traces. If this function fails to get span dedup result and gets stuck, the HTTP request will time out. ## This PR While I don't yet know what causes the error, this PR adds a patch to mitigate the impact: 1. Change log level from `error` to `warn` 2. Add a timeout of 5 seconds to the span dedup check, so that if the caller doesn't get an answer soon, it defaults to treating the trace as not a duplicate, which is the most common case. ## Testing To merge this PR then check log in self monitoring, as it's hard to run high-volume tests in self monitoring from a non-main branch.
1 parent 4ab1ae4 commit 2049503

3 files changed

Lines changed: 13 additions & 0 deletions

File tree

env.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,13 @@ pub struct EnvConfig {
417417
/// Default is `false`.
418418
#[serde(deserialize_with = "deserialize_optional_bool_from_anything")]
419419
pub compute_trace_stats_on_extension: Option<bool>,
420+
/// @env `DD_SPAN_DEDUP_TIMEOUT`
421+
///
422+
/// The timeout for the span deduplication service to check if a span key exists, in seconds.
423+
/// For now, this is a temporary field added to debug the failure of `check_and_add()` in span dedup service.
424+
/// Do not use this field extensively in production.
425+
#[serde(deserialize_with = "deserialize_optional_duration_from_seconds_ignore_zero")]
426+
pub span_dedup_timeout: Option<Duration>,
420427
/// @env `DD_API_KEY_SECRET_RELOAD_INTERVAL`
421428
///
422429
/// The interval at which the Datadog API key is reloaded, in seconds.
@@ -640,6 +647,7 @@ fn merge_config(config: &mut Config, env_config: &EnvConfig) {
640647
merge_option_to_value!(config, env_config, capture_lambda_payload);
641648
merge_option_to_value!(config, env_config, capture_lambda_payload_max_depth);
642649
merge_option_to_value!(config, env_config, compute_trace_stats_on_extension);
650+
merge_option!(config, env_config, span_dedup_timeout);
643651
merge_option!(config, env_config, api_key_secret_reload_interval);
644652
merge_option_to_value!(config, env_config, serverless_appsec_enabled);
645653
merge_option!(config, env_config, appsec_rules);
@@ -835,6 +843,7 @@ mod tests {
835843
jail.set_env("DD_CAPTURE_LAMBDA_PAYLOAD", "true");
836844
jail.set_env("DD_CAPTURE_LAMBDA_PAYLOAD_MAX_DEPTH", "5");
837845
jail.set_env("DD_COMPUTE_TRACE_STATS_ON_EXTENSION", "true");
846+
jail.set_env("DD_SPAN_DEDUP_TIMEOUT", "5");
838847
jail.set_env("DD_API_KEY_SECRET_RELOAD_INTERVAL", "10");
839848
jail.set_env("DD_SERVERLESS_APPSEC_ENABLED", "true");
840849
jail.set_env("DD_APPSEC_RULES", "/path/to/rules.json");
@@ -988,6 +997,7 @@ mod tests {
988997
capture_lambda_payload: true,
989998
capture_lambda_payload_max_depth: 5,
990999
compute_trace_stats_on_extension: true,
1000+
span_dedup_timeout: Some(Duration::from_secs(5)),
9911001
api_key_secret_reload_interval: Some(Duration::from_secs(10)),
9921002
serverless_appsec_enabled: true,
9931003
appsec_rules: Some("/path/to/rules.json".to_string()),

mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ pub struct Config {
346346
pub capture_lambda_payload: bool,
347347
pub capture_lambda_payload_max_depth: u32,
348348
pub compute_trace_stats_on_extension: bool,
349+
pub span_dedup_timeout: Option<Duration>,
349350
pub api_key_secret_reload_interval: Option<Duration>,
350351

351352
pub serverless_appsec_enabled: bool,
@@ -451,6 +452,7 @@ impl Default for Config {
451452
capture_lambda_payload: false,
452453
capture_lambda_payload_max_depth: 10,
453454
compute_trace_stats_on_extension: false,
455+
span_dedup_timeout: None,
454456
api_key_secret_reload_interval: None,
455457

456458
serverless_appsec_enabled: false,

yaml.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -995,6 +995,7 @@ api_security_sample_delay: 60 # Seconds
995995
capture_lambda_payload: true,
996996
capture_lambda_payload_max_depth: 5,
997997
compute_trace_stats_on_extension: true,
998+
span_dedup_timeout: None,
998999
api_key_secret_reload_interval: None,
9991000

10001001
serverless_appsec_enabled: true,

0 commit comments

Comments
 (0)