mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-30 00:07:30 +00:00
feat: option to export only audit logs through OTel
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
9a7ab54746
commit
85576d75f0
@@ -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<serde_json::Value>) {
|
||||
struct OtelSetting {
|
||||
metrics_enabled: Option<bool>,
|
||||
logs_enabled: Option<bool>,
|
||||
logs_audit_only: Option<bool>,
|
||||
tracing_enabled: Option<bool>,
|
||||
#[serde(default, deserialize_with = "empty_as_none")]
|
||||
otel_exporter_otlp_endpoint: Option<String>,
|
||||
@@ -829,6 +830,11 @@ pub async fn load_otel(db: &DB) {
|
||||
.map(|x| x.parse::<bool>().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::<bool>().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::<bool>().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");
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -649,6 +649,9 @@ pub struct OtelSettings {
|
||||
pub metrics_enabled: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub logs_enabled: Option<bool>,
|
||||
/// With logs enabled, export audit events only.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub logs_audit_only: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub tracing_enabled: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
|
||||
@@ -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::<bool>().unwrap_or(false)));
|
||||
|
||||
pub static ref METRICS_DEBUG_ENABLED: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -671,6 +671,18 @@
|
||||
options={{ right: 'Metrics' }}
|
||||
/>
|
||||
</div>
|
||||
{#if $values[setting.key].logs_enabled}
|
||||
<Toggle
|
||||
disabled={!$enterpriseLicense}
|
||||
id="logs_audit_only"
|
||||
bind:checked={$values[setting.key].logs_audit_only}
|
||||
options={{
|
||||
right: 'Export audit logs only',
|
||||
rightTooltip:
|
||||
'Send only audit events through the logs exporter, not the service logs. Audit events are then exported whatever RUST_LOG is set to.'
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<div class="flex flex-col gap-1">
|
||||
<label
|
||||
|
||||
Reference in New Issue
Block a user