From 85576d75f021e6a2665b35a301b9f59544e80473 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Thu, 26 Nov 2026 10:15:25 +0100 Subject: [PATCH] feat: option to export only audit logs through OTel Co-Authored-By: Claude Opus 5.5 --- backend/src/monitor.rs | 11 +++++++++-- backend/windmill-common/src/global_settings.rs | 1 + backend/windmill-common/src/instance_config.rs | 3 +++ backend/windmill-common/src/lib.rs | 2 ++ backend/windmill-common/src/tracing_init.rs | 14 +++++++++++--- frontend/src/lib/components/InstanceSetting.svelte | 12 ++++++++++++ 6 files changed, 38 insertions(+), 5 deletions(-) diff --git a/backend/src/monitor.rs b/backend/src/monitor.rs index 6c70e666a8..d6946e3d16 100644 --- a/backend/src/monitor.rs +++ b/backend/src/monitor.rs @@ -111,7 +111,7 @@ use windmill_common::{ CRITICAL_ALERT_MUTE_ZOMBIE_JOB_RESTART, CRITICAL_ERROR_CHANNELS, DB, DEFAULT_HUB_BASE_URL, DEFAULT_OTEL_TRACES_RETENTION_SECS, DEFAULT_SERVICE_LOG_RETENTION_SECS, HUB_BASE_URL, JOB_RETENTION_SECS, JOB_RETENTION_SECS_OVERRIDES, JOB_RETENTION_SECS_OVERRIDES_LOADED, - METRICS_DEBUG_ENABLED, METRICS_ENABLED, MONITOR_LOGS_ON_OBJECT_STORE, OTEL_LOGS_ENABLED, + METRICS_DEBUG_ENABLED, METRICS_ENABLED, MONITOR_LOGS_ON_OBJECT_STORE, OTEL_LOGS_AUDIT_ONLY, OTEL_LOGS_ENABLED, OTEL_METRICS_ENABLED, OTEL_TRACING_ENABLED, STORE_AUDIT_LOGS_S3, }; use windmill_common::{ @@ -802,6 +802,7 @@ pub fn apply_metrics_enabled(value: Option) { struct OtelSetting { metrics_enabled: Option, logs_enabled: Option, + logs_audit_only: Option, tracing_enabled: Option, #[serde(default, deserialize_with = "empty_as_none")] otel_exporter_otlp_endpoint: Option, @@ -829,6 +830,11 @@ pub async fn load_otel(db: &DB) { .map(|x| x.parse::().unwrap_or(false)) .unwrap_or(false) }); + let logs_audit_only = o.logs_audit_only.unwrap_or_else(|| { + std::env::var("OTEL_LOGS_AUDIT_ONLY") + .map(|x| x.parse::().unwrap_or(false)) + .unwrap_or(false) + }); let tracing_enabled = o.tracing_enabled.unwrap_or_else(|| { std::env::var("OTEL_TRACING_ENABLED") .map(|x| x.parse::().unwrap_or(false)) @@ -837,6 +843,7 @@ pub async fn load_otel(db: &DB) { OTEL_METRICS_ENABLED.store(metrics_enabled, Ordering::Relaxed); OTEL_LOGS_ENABLED.store(logs_enabled, Ordering::Relaxed); + OTEL_LOGS_AUDIT_ONLY.store(logs_audit_only, Ordering::Relaxed); OTEL_TRACING_ENABLED.store(tracing_enabled, Ordering::Relaxed); let endpoint = if let Some(endpoint) = o.otel_exporter_otlp_endpoint { @@ -867,7 +874,7 @@ pub async fn load_otel(db: &DB) { std::env::set_var("OTEL_EXPORTER_OTLP_COMPRESSION", compression); } } - println!("OTEL settings loaded: tracing ({tracing_enabled}), logs ({logs_enabled}), metrics ({metrics_enabled}), endpoint ({:?}), headers defined: ({})", + println!("OTEL settings loaded: tracing ({tracing_enabled}), logs ({logs_enabled}, audit only: {logs_audit_only}), metrics ({metrics_enabled}), endpoint ({:?}), headers defined: ({})", endpoint, headers.is_some()); } else { tracing::error!("Error deserializing otel settings"); diff --git a/backend/windmill-common/src/global_settings.rs b/backend/windmill-common/src/global_settings.rs index e87dd17a76..623823dea3 100644 --- a/backend/windmill-common/src/global_settings.rs +++ b/backend/windmill-common/src/global_settings.rs @@ -932,6 +932,7 @@ pub const ENV_SETTINGS: &[&str] = &[ "OTEL_METRICS_ENABLED", "OTEL_TRACING_ENABLED", "OTEL_LOGS_ENABLED", + "OTEL_LOGS_AUDIT_ONLY", "OTEL_EXPORTER_OTLP_ENDPOINT", "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", "OTEL_EXPORTER_OTLP_METRICS_ENDPOINT", diff --git a/backend/windmill-common/src/instance_config.rs b/backend/windmill-common/src/instance_config.rs index 1e92fe6372..f8246a5b8c 100644 --- a/backend/windmill-common/src/instance_config.rs +++ b/backend/windmill-common/src/instance_config.rs @@ -649,6 +649,9 @@ pub struct OtelSettings { pub metrics_enabled: Option, #[serde(skip_serializing_if = "Option::is_none")] pub logs_enabled: Option, + /// With logs enabled, export audit events only. + #[serde(skip_serializing_if = "Option::is_none")] + pub logs_audit_only: Option, #[serde(skip_serializing_if = "Option::is_none")] pub tracing_enabled: Option, #[serde(skip_serializing_if = "Option::is_none")] diff --git a/backend/windmill-common/src/lib.rs b/backend/windmill-common/src/lib.rs index 822b0fda31..ca993ac634 100644 --- a/backend/windmill-common/src/lib.rs +++ b/backend/windmill-common/src/lib.rs @@ -482,6 +482,8 @@ lazy_static::lazy_static! { pub static ref OTEL_METRICS_ENABLED: AtomicBool = AtomicBool::new(std::env::var("OTEL_METRICS").is_ok()); pub static ref OTEL_TRACING_ENABLED: AtomicBool = AtomicBool::new(std::env::var("OTEL_TRACING").is_ok()); pub static ref OTEL_LOGS_ENABLED: AtomicBool = AtomicBool::new(std::env::var("OTEL_LOGS").is_ok()); + /// Export only audit events through the OTel logs bridge, not the service logs. + pub static ref OTEL_LOGS_AUDIT_ONLY: AtomicBool = AtomicBool::new(std::env::var("OTEL_LOGS_AUDIT_ONLY").is_ok_and(|x| x.parse::().unwrap_or(false))); pub static ref METRICS_DEBUG_ENABLED: AtomicBool = AtomicBool::new(false); diff --git a/backend/windmill-common/src/tracing_init.rs b/backend/windmill-common/src/tracing_init.rs index 855e077004..93e3c3b10e 100644 --- a/backend/windmill-common/src/tracing_init.rs +++ b/backend/windmill-common/src/tracing_init.rs @@ -166,8 +166,12 @@ pub fn initialize_tracing( file_env_filter.clone() }; - // Create a common filter for OTEL logs bridge and tracing layer to respect RUST_LOG - let otel_logs_filter = file_env_filter.clone(); + // The OTEL logs bridge follows RUST_LOG, unless it exports audit events only: those are + // emitted at INFO and must reach the collector whatever level the service logs at. + let audit_only = crate::OTEL_LOGS_AUDIT_ONLY.load(std::sync::atomic::Ordering::Relaxed); + let otel_logs_filter = (!audit_only).then(|| file_env_filter.clone()); + let otel_audit_filter = + audit_only.then(|| Targets::new().with_target(AUDIT_TARGET, LevelFilter::INFO)); // Apply filter to the opentelemetry tracing layer to prevent debug events from being attached to spans #[cfg(all(feature = "otel", feature = "enterprise"))] @@ -180,7 +184,11 @@ pub fn initialize_tracing( let opentelemetry_filtered = opentelemetry; let base_layer = tracing_subscriber::registry() - .with(logs_bridge.with_filter(otel_logs_filter)) + .with( + logs_bridge + .with_filter(otel_logs_filter) + .with_filter(otel_audit_filter), + ) .with(opentelemetry_filtered); // The service log files are written to be indexed, not tailed, so they always carry the diff --git a/frontend/src/lib/components/InstanceSetting.svelte b/frontend/src/lib/components/InstanceSetting.svelte index 32c97f6623..36d972604a 100644 --- a/frontend/src/lib/components/InstanceSetting.svelte +++ b/frontend/src/lib/components/InstanceSetting.svelte @@ -671,6 +671,18 @@ options={{ right: 'Metrics' }} /> + {#if $values[setting.key].logs_enabled} + + {/if}