diff --git a/bottlecap/Cargo.lock b/bottlecap/Cargo.lock index d2b64d865..0784bc9e1 100644 --- a/bottlecap/Cargo.lock +++ b/bottlecap/Cargo.lock @@ -501,6 +501,7 @@ dependencies = [ "datadog-fips", "datadog-opentelemetry", "datadog-protos", + "datadog-serverless-logging", "ddsketch-agent", "dogstatsd", "figment", @@ -888,7 +889,7 @@ dependencies = [ [[package]] name = "datadog-agent-config" version = "0.1.0" -source = "git+https://github.com/DataDog/serverless-components?rev=8156757470d0843a99fc5d19809ae021cd2c7178#8156757470d0843a99fc5d19809ae021cd2c7178" +source = "git+https://github.com/DataDog/serverless-components?rev=19270f5dcbc2480824bdec25a1d30899edb3e09e#19270f5dcbc2480824bdec25a1d30899edb3e09e" dependencies = [ "datadog-opentelemetry", "dogstatsd", @@ -906,13 +907,14 @@ dependencies = [ [[package]] name = "datadog-agent-trace-sampler" version = "0.1.0" -source = "git+https://github.com/DataDog/serverless-components?rev=8156757470d0843a99fc5d19809ae021cd2c7178#8156757470d0843a99fc5d19809ae021cd2c7178" +source = "git+https://github.com/DataDog/serverless-components?rev=19270f5dcbc2480824bdec25a1d30899edb3e09e#19270f5dcbc2480824bdec25a1d30899edb3e09e" [[package]] name = "datadog-fips" version = "0.1.0" -source = "git+https://github.com/DataDog/serverless-components?rev=8156757470d0843a99fc5d19809ae021cd2c7178#8156757470d0843a99fc5d19809ae021cd2c7178" +source = "git+https://github.com/DataDog/serverless-components?rev=19270f5dcbc2480824bdec25a1d30899edb3e09e#19270f5dcbc2480824bdec25a1d30899edb3e09e" dependencies = [ + "aws-lc-rs", "reqwest", "rustls", "rustls-native-certs", @@ -971,6 +973,14 @@ dependencies = [ "tonic-build", ] +[[package]] +name = "datadog-serverless-logging" +version = "0.1.0" +source = "git+https://github.com/DataDog/serverless-components?rev=19270f5dcbc2480824bdec25a1d30899edb3e09e#19270f5dcbc2480824bdec25a1d30899edb3e09e" +dependencies = [ + "tracing-subscriber", +] + [[package]] name = "ddsketch-agent" version = "0.1.0" @@ -1090,7 +1100,7 @@ dependencies = [ [[package]] name = "dogstatsd" version = "0.1.0" -source = "git+https://github.com/DataDog/serverless-components?rev=8156757470d0843a99fc5d19809ae021cd2c7178#8156757470d0843a99fc5d19809ae021cd2c7178" +source = "git+https://github.com/DataDog/serverless-components?rev=19270f5dcbc2480824bdec25a1d30899edb3e09e#19270f5dcbc2480824bdec25a1d30899edb3e09e" dependencies = [ "datadog-protos", "ddsketch-agent", diff --git a/bottlecap/Cargo.toml b/bottlecap/Cargo.toml index 07b8f8e0b..68cf42869 100644 --- a/bottlecap/Cargo.toml +++ b/bottlecap/Cargo.toml @@ -95,10 +95,11 @@ libdd-trace-normalization = "3.0.1" libdd-trace-obfuscation = { version = "6.0.0", default-features = false } libdd-trace-stats = { version = "7.0.0", default-features = false } datadog-opentelemetry = { version = "0.5.2", default-features = false, features = ["_unstable_propagation"] } -dogstatsd = { git = "https://github.com/DataDog/serverless-components", rev = "8156757470d0843a99fc5d19809ae021cd2c7178", default-features = false } -datadog-fips = { git = "https://github.com/DataDog/serverless-components", rev = "8156757470d0843a99fc5d19809ae021cd2c7178", default-features = false } -datadog-agent-config = { git = "https://github.com/DataDog/serverless-components", rev = "8156757470d0843a99fc5d19809ae021cd2c7178", default-features = false } -datadog-agent-trace-sampler = { git = "https://github.com/DataDog/serverless-components", rev = "8156757470d0843a99fc5d19809ae021cd2c7178", default-features = false } +dogstatsd = { git = "https://github.com/DataDog/serverless-components", rev = "19270f5dcbc2480824bdec25a1d30899edb3e09e", default-features = false } +datadog-fips = { git = "https://github.com/DataDog/serverless-components", rev = "19270f5dcbc2480824bdec25a1d30899edb3e09e", default-features = false } +datadog-agent-config = { git = "https://github.com/DataDog/serverless-components", rev = "19270f5dcbc2480824bdec25a1d30899edb3e09e", default-features = false } +datadog-agent-trace-sampler = { git = "https://github.com/DataDog/serverless-components", rev = "19270f5dcbc2480824bdec25a1d30899edb3e09e", default-features = false } +datadog-serverless-logging = { git = "https://github.com/DataDog/serverless-components", rev = "19270f5dcbc2480824bdec25a1d30899edb3e09e", default-features = false } libddwaf = { version = "1.28.1", git = "https://github.com/DataDog/libddwaf-rust", rev = "d1534a158d976bd4f747bf9fcc58e0712d2d17fc", default-features = false, features = ["serde"] } [dev-dependencies] diff --git a/bottlecap/LICENSE-3rdparty.csv b/bottlecap/LICENSE-3rdparty.csv index 07ec6ff60..ca5d1db00 100644 --- a/bottlecap/LICENSE-3rdparty.csv +++ b/bottlecap/LICENSE-3rdparty.csv @@ -53,6 +53,7 @@ datadog-agent-trace-sampler,https://github.com/DataDog/serverless-components,Apa datadog-fips,https://github.com/DataDog/serverless-components,Apache-2.0,The datadog-fips Authors datadog-opentelemetry,https://github.com/DataDog/dd-trace-rs/tree/main/datadog-opentelemetry,Apache-2.0,Datadog Inc. datadog-protos,https://github.com/DataDog/saluki,Apache-2.0,The datadog-protos Authors +datadog-serverless-logging,https://github.com/DataDog/serverless-components,Apache-2.0,The datadog-serverless-logging Authors ddsketch-agent,https://github.com/DataDog/saluki,Apache-2.0,The ddsketch-agent Authors defmt,https://github.com/knurling-rs/defmt,MIT OR Apache-2.0,The Knurling-rs developers defmt-macros,https://github.com/knurling-rs/defmt,MIT OR Apache-2.0,The Knurling-rs developers diff --git a/bottlecap/src/bin/bottlecap/main.rs b/bottlecap/src/bin/bottlecap/main.rs index 3078b25b6..7d986f976 100644 --- a/bottlecap/src/bin/bottlecap/main.rs +++ b/bottlecap/src/bin/bottlecap/main.rs @@ -83,6 +83,7 @@ use bottlecap::{ }, }; use datadog_fips::reqwest_adapter::create_reqwest_client_builder; +use datadog_serverless_logging::{LEVEL_BY_TARGET_ENV_VAR, build_env_filter}; use decrypt::{ has_additional_endpoints_secrets, resolve_additional_endpoints_secrets, resolve_secrets, }; @@ -107,7 +108,6 @@ use tokio::time::Instant; use tokio::{sync::Mutex as TokioMutex, sync::mpsc::Sender}; use tokio_util::sync::CancellationToken; use tracing::{debug, error, warn}; -use tracing_subscriber::EnvFilter; use ustr::Ustr; fn resolve_dsm_service( @@ -234,13 +234,15 @@ fn enable_logging_subsystem() { ) .unwrap_or(LogLevel::Info); - let env_filter = format!( - "h2=off,hyper=off,reqwest=off,rustls=off,datadog-trace-mini-agent=off,{log_level:?}", - ); + let (env_filter, invalid_entries) = build_env_filter( + &format!( + "h2=off,hyper=off,reqwest=off,rustls=off,datadog-trace-mini-agent=off,{log_level:?}" + ), + &std::env::var(LEVEL_BY_TARGET_ENV_VAR).unwrap_or_default(), + ) + .expect("could not parse log level in configuration"); let subscriber = tracing_subscriber::fmt::Subscriber::builder() - .with_env_filter( - EnvFilter::try_new(env_filter).expect("could not parse log level in configuration"), - ) + .with_env_filter(env_filter) .with_level(true) .with_thread_names(false) .with_thread_ids(false) @@ -252,6 +254,9 @@ fn enable_logging_subsystem() { .finish(); tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed"); + if !invalid_entries.is_empty() { + warn!("Ignoring invalid {LEVEL_BY_TARGET_ENV_VAR} entries: {invalid_entries:?}"); + } debug!("Logging subsystem enabled"); } diff --git a/bottlecap/src/logger/README.md b/bottlecap/src/logger/README.md new file mode 100644 index 000000000..0c86b5aae --- /dev/null +++ b/bottlecap/src/logger/README.md @@ -0,0 +1,16 @@ +# Log Levels by Target + +`DD_LOG_LEVEL_BY_TARGET` turns on more logs for one part of the extension, without the debug logs of all other parts. It is mainly for Datadog engineers and support, to collect logs for a support ticket. The Datadog documentation site does not describe it. + +Set these environment variables on the Lambda function: + +| Environment variable | Value | +| --- | --- | +| `DD_LOG_LEVEL` | The level for all other logs, for example `info`. The default is `info`. | +| `DD_LOG_LEVEL_BY_TARGET` | A comma-separated list of `=` entries | + +A level is `off`, `error`, `warn`, `info`, `debug` or `trace`. For example, if `DD_LOG_LEVEL` is `info` and `DD_LOG_LEVEL_BY_TARGET` is `cold_start_duration=debug`, the extension logs at `info` level as usual, and also logs the duration of each cold start step. + +An entry matches each target that starts with its text. For an entry that is not valid, the extension logs a warning that names the entry, and skips it. + +Use the targets that `mod.rs` defines, such as `cold_start_duration`. Other targets are module paths and crate names, which change when the code moves. diff --git a/bottlecap/src/logger/mod.rs b/bottlecap/src/logger/mod.rs index 177870494..6419f4fdf 100644 --- a/bottlecap/src/logger/mod.rs +++ b/bottlecap/src/logger/mod.rs @@ -8,6 +8,10 @@ use tracing_subscriber::registry::LookupSpan; pub mod cold_start; +// `DD_LOG_LEVEL_BY_TARGET` matches a target by text prefix, so no target name may start with +// another one: an entry for `trace_flush` would also match `trace_flush_duration`. +// `README.md` in this folder documents `DD_LOG_LEVEL_BY_TARGET`. + /// Tracing target for the duration of each cold start step. pub const COLD_START_DURATION: &str = "cold_start_duration";