mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-28 08:06:16 +00:00
feat: a second OTel logs exporter for audit logs (#12675)
* feat: a second OTel logs exporter for audit logs Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore: pin ee to the audit logs exporter companion Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: redact otel exporter headers when logging the otel setting Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore: update ee-repo-ref to 9a5254e3dc2ea4af8e20fd497b50025f99fa02b3 This commit updates the EE repository reference after PR #1013 was merged in windmill-ee-private. Previous ee-repo-ref: 8c53ef5354a79af46cdce617b0df5416c240a27c New ee-repo-ref: 9a5254e3dc2ea4af8e20fd497b50025f99fa02b3 Automated by sync-ee-ref workflow. --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
windmill-internal-app[bot]
parent
f45209064a
commit
f28bdff94f
Generated
+2
@@ -16530,6 +16530,7 @@ dependencies = [
|
||||
"openidconnect",
|
||||
"opentelemetry 0.30.0",
|
||||
"opentelemetry-appender-tracing",
|
||||
"opentelemetry-http 0.30.0",
|
||||
"opentelemetry-otlp 0.30.0",
|
||||
"opentelemetry-semantic-conventions 0.30.0",
|
||||
"opentelemetry_sdk 0.30.0",
|
||||
@@ -16545,6 +16546,7 @@ dependencies = [
|
||||
"rand 0.9.5",
|
||||
"rcgen",
|
||||
"regex",
|
||||
"reqwest 0.12.28",
|
||||
"reqwest 0.13.5",
|
||||
"reqwest-middleware",
|
||||
"reqwest-retry",
|
||||
|
||||
@@ -712,6 +712,7 @@ tracing-opentelemetry = "0.31.0"
|
||||
opentelemetry_sdk = { version = "0.30.0", features = ["rt-tokio", "testing"] }
|
||||
opentelemetry-otlp = { version = "0.30.0", features = ["grpc-tonic", "tls", "http-proto", "gzip-tonic", "zstd-tonic"] }
|
||||
opentelemetry-appender-tracing = "0.30.0"
|
||||
opentelemetry-http = "0.30.0"
|
||||
opentelemetry-semantic-conventions = { version = "0.30.0", features = ["semconv_experimental"] }
|
||||
opentelemetry-proto = { version = "0.30.0", features = ["with-serde", "gen-tonic"] }
|
||||
prost = "0.13"
|
||||
|
||||
@@ -1 +1 @@
|
||||
04fb511569ecb790b24e0a2f70e316de34cbb067
|
||||
9a5254e3dc2ea4af8e20fd497b50025f99fa02b3
|
||||
|
||||
+42
-2
@@ -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, OtelAuditLogsExport, OTEL_AUDIT_LOGS_EXPORT, OTEL_LOGS_ENABLED, OTEL_LOGS_EXCLUDE_AUDIT,
|
||||
OTEL_METRICS_ENABLED, OTEL_TRACING_ENABLED, STORE_AUDIT_LOGS_S3,
|
||||
};
|
||||
use windmill_common::{
|
||||
@@ -802,6 +802,15 @@ pub fn apply_metrics_enabled(value: Option<serde_json::Value>) {
|
||||
struct OtelSetting {
|
||||
metrics_enabled: Option<bool>,
|
||||
logs_enabled: Option<bool>,
|
||||
logs_exclude_audit: Option<bool>,
|
||||
audit_logs_enabled: Option<bool>,
|
||||
#[serde(default, deserialize_with = "empty_as_none")]
|
||||
audit_logs_endpoint: Option<String>,
|
||||
#[serde(default, deserialize_with = "empty_as_none")]
|
||||
audit_logs_headers: Option<String>,
|
||||
#[serde(default, deserialize_with = "empty_as_none")]
|
||||
audit_logs_protocol: Option<String>,
|
||||
audit_logs_workspaces: Option<Vec<String>>,
|
||||
tracing_enabled: Option<bool>,
|
||||
#[serde(default, deserialize_with = "empty_as_none")]
|
||||
otel_exporter_otlp_endpoint: Option<String>,
|
||||
@@ -837,6 +846,37 @@ pub async fn load_otel(db: &DB) {
|
||||
|
||||
OTEL_METRICS_ENABLED.store(metrics_enabled, Ordering::Relaxed);
|
||||
OTEL_LOGS_ENABLED.store(logs_enabled, Ordering::Relaxed);
|
||||
|
||||
let env_bool = |var: &str| {
|
||||
std::env::var(var)
|
||||
.map(|x| x.parse::<bool>().unwrap_or(false))
|
||||
.unwrap_or(false)
|
||||
};
|
||||
let logs_exclude_audit = o
|
||||
.logs_exclude_audit
|
||||
.unwrap_or_else(|| env_bool("OTEL_LOGS_EXCLUDE_AUDIT"));
|
||||
OTEL_LOGS_EXCLUDE_AUDIT.store(logs_exclude_audit, Ordering::Relaxed);
|
||||
let audit_logs = OtelAuditLogsExport::new(
|
||||
o.audit_logs_enabled
|
||||
.unwrap_or_else(|| env_bool("OTEL_AUDIT_LOGS_ENABLED")),
|
||||
o.audit_logs_endpoint
|
||||
.or_else(|| std::env::var("OTEL_AUDIT_LOGS_ENDPOINT").ok()),
|
||||
o.audit_logs_headers
|
||||
.or_else(|| std::env::var("OTEL_AUDIT_LOGS_HEADERS").ok()),
|
||||
o.audit_logs_protocol
|
||||
.or_else(|| std::env::var("OTEL_AUDIT_LOGS_PROTOCOL").ok()),
|
||||
// A saved empty list means every workspace and does not fall back to the
|
||||
// environment, so clearing the list in the UI cannot bring an env list back.
|
||||
o.audit_logs_workspaces.or_else(|| {
|
||||
std::env::var("OTEL_AUDIT_LOGS_WORKSPACES")
|
||||
.ok()
|
||||
.map(|v| v.split(',').map(str::to_string).collect())
|
||||
}),
|
||||
);
|
||||
let audit_logs_endpoint = audit_logs.as_ref().map(|a| a.endpoint.clone());
|
||||
if let Ok(mut export) = OTEL_AUDIT_LOGS_EXPORT.write() {
|
||||
*export = audit_logs;
|
||||
}
|
||||
OTEL_TRACING_ENABLED.store(tracing_enabled, Ordering::Relaxed);
|
||||
|
||||
let endpoint = if let Some(endpoint) = o.otel_exporter_otlp_endpoint {
|
||||
@@ -867,7 +907,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}, without audit: {logs_exclude_audit}), audit logs endpoint ({audit_logs_endpoint:?}), metrics ({metrics_enabled}), endpoint ({:?}), headers defined: ({})",
|
||||
endpoint, headers.is_some());
|
||||
} else {
|
||||
tracing::error!("Error deserializing otel settings");
|
||||
|
||||
@@ -17,7 +17,8 @@ benchmark = []
|
||||
parquet = []
|
||||
aws_auth = ["dep:aws-sdk-sts", "dep:aws-config"]
|
||||
otel = ["dep:opentelemetry-semantic-conventions", "dep:opentelemetry-otlp", "dep:opentelemetry_sdk",
|
||||
"dep:tracing-opentelemetry", "dep:opentelemetry-appender-tracing", "dep:tonic", "dep:opentelemetry"]
|
||||
"dep:tracing-opentelemetry", "dep:opentelemetry-appender-tracing", "dep:tonic", "dep:opentelemetry",
|
||||
"dep:opentelemetry-http", "dep:reqwest_otel"]
|
||||
smtp = ["dep:mail-send", "dep:rustls", "dep:tokio-rustls", "dep:rustls-native-certs", "dep:webpki-roots"]
|
||||
scoped_cache = []
|
||||
cloud = []
|
||||
@@ -142,6 +143,9 @@ opentelemetry = { workspace = true, optional = true }
|
||||
tracing-opentelemetry = { workspace = true, optional = true }
|
||||
opentelemetry-appender-tracing = { workspace = true, optional = true }
|
||||
tonic = { workspace = true, optional = true }
|
||||
opentelemetry-http = { workspace = true, optional = true }
|
||||
# The reqwest the OTLP/HTTP exporter is built on, for a client of our own around it.
|
||||
reqwest_otel = { package = "reqwest", version = "0.12", features = ["blocking"], optional = true }
|
||||
equivalent = "1.0.2"
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
@@ -933,6 +933,12 @@ pub const ENV_SETTINGS: &[&str] = &[
|
||||
"OTEL_METRICS_ENABLED",
|
||||
"OTEL_TRACING_ENABLED",
|
||||
"OTEL_LOGS_ENABLED",
|
||||
"OTEL_LOGS_EXCLUDE_AUDIT",
|
||||
// OTEL_AUDIT_LOGS_HEADERS is left out for the same reason as the exporter headers above.
|
||||
"OTEL_AUDIT_LOGS_ENABLED",
|
||||
"OTEL_AUDIT_LOGS_ENDPOINT",
|
||||
"OTEL_AUDIT_LOGS_PROTOCOL",
|
||||
"OTEL_AUDIT_LOGS_WORKSPACES",
|
||||
"OTEL_EXPORTER_OTLP_ENDPOINT",
|
||||
"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT",
|
||||
"OTEL_EXPORTER_OTLP_METRICS_ENDPOINT",
|
||||
|
||||
@@ -649,6 +649,21 @@ pub struct OtelSettings {
|
||||
pub metrics_enabled: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub logs_enabled: Option<bool>,
|
||||
/// Leave audit events out of the logs export.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub logs_exclude_audit: Option<bool>,
|
||||
/// A second logs exporter that receives audit events only.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub audit_logs_enabled: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub audit_logs_endpoint: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub audit_logs_headers: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub audit_logs_protocol: Option<String>,
|
||||
/// Restrict the audit export to these workspaces; instance-level entries are always kept.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub audit_logs_workspaces: Option<Vec<String>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub tracing_enabled: Option<bool>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
@@ -1229,7 +1244,10 @@ const NESTED_SENSITIVE_FIELDS: &[(&str, &[&str])] = &[
|
||||
("custom_instance_pg_databases", &["user_pwd"]),
|
||||
("external_instance_pg", &["password"]),
|
||||
("github_enterprise_app", &["private_key"]),
|
||||
("otel", &["otel_exporter_otlp_headers"]),
|
||||
(
|
||||
"otel",
|
||||
&["otel_exporter_otlp_headers", "audit_logs_headers"],
|
||||
),
|
||||
];
|
||||
|
||||
/// Settings that are maps-of-objects where each child has sensitive sub-fields.
|
||||
@@ -3117,6 +3135,19 @@ mod tests {
|
||||
assert!(formatted.contains("****"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_setting_value_redacts_otel_headers() {
|
||||
let val = serde_json::json!({
|
||||
"otel_exporter_otlp_endpoint": "http://collector:4317",
|
||||
"otel_exporter_otlp_headers": "Authorization=Bearer main-token-12345",
|
||||
"audit_logs_headers": "Authorization=Bearer audit-token-67890"
|
||||
});
|
||||
let formatted = format_setting_value("otel", &val);
|
||||
assert!(!formatted.contains("main-token-12345"));
|
||||
assert!(!formatted.contains("audit-token-67890"));
|
||||
assert!(formatted.contains("http://collector:4317"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_setting_value_redacts_nested_credentials() {
|
||||
let val = serde_json::json!({
|
||||
|
||||
@@ -484,6 +484,10 @@ 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());
|
||||
/// Leave audit events out of the logs export, for when the audit export carries them.
|
||||
pub static ref OTEL_LOGS_EXCLUDE_AUDIT: AtomicBool = AtomicBool::new(env_bool("OTEL_LOGS_EXCLUDE_AUDIT"));
|
||||
pub static ref OTEL_AUDIT_LOGS_EXPORT: std::sync::RwLock<Option<OtelAuditLogsExport>> =
|
||||
std::sync::RwLock::new(OtelAuditLogsExport::from_env());
|
||||
|
||||
pub static ref METRICS_DEBUG_ENABLED: AtomicBool = AtomicBool::new(false);
|
||||
|
||||
@@ -3469,3 +3473,58 @@ impl KillpillSender {
|
||||
// self.already_sent.load(Ordering::SeqCst)
|
||||
// }
|
||||
}
|
||||
|
||||
fn env_bool(var: &str) -> bool {
|
||||
std::env::var(var).is_ok_and(|x| x.parse::<bool>().unwrap_or(false))
|
||||
}
|
||||
|
||||
/// An OTLP logs exporter of its own for audit events, beside the logs export: audit events can
|
||||
/// go to long-term storage while the service logs go elsewhere, or nowhere.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct OtelAuditLogsExport {
|
||||
pub endpoint: String,
|
||||
/// `key=value` pairs separated by commas, as in `OTEL_EXPORTER_OTLP_HEADERS`.
|
||||
pub headers: Option<String>,
|
||||
/// `grpc` (the default) or `http/protobuf`.
|
||||
pub protocol: Option<String>,
|
||||
/// Only the audit events of these workspaces, and of the instance itself, are exported.
|
||||
/// `None` exports every workspace.
|
||||
pub workspaces: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
impl OtelAuditLogsExport {
|
||||
pub fn new(
|
||||
enabled: bool,
|
||||
endpoint: Option<String>,
|
||||
headers: Option<String>,
|
||||
protocol: Option<String>,
|
||||
workspaces: Option<Vec<String>>,
|
||||
) -> Option<Self> {
|
||||
let endpoint = endpoint.filter(|e| !e.trim().is_empty())?;
|
||||
enabled.then(|| Self {
|
||||
endpoint: endpoint.trim().to_string(),
|
||||
headers: headers.filter(|h| !h.trim().is_empty()),
|
||||
protocol: protocol.filter(|p| !p.trim().is_empty()),
|
||||
workspaces: workspaces
|
||||
.map(|w| {
|
||||
w.iter()
|
||||
.map(|w| w.trim().to_string())
|
||||
.filter(|w| !w.is_empty())
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
.filter(|w| !w.is_empty()),
|
||||
})
|
||||
}
|
||||
|
||||
fn from_env() -> Option<Self> {
|
||||
Self::new(
|
||||
env_bool("OTEL_AUDIT_LOGS_ENABLED"),
|
||||
std::env::var("OTEL_AUDIT_LOGS_ENDPOINT").ok(),
|
||||
std::env::var("OTEL_AUDIT_LOGS_HEADERS").ok(),
|
||||
std::env::var("OTEL_AUDIT_LOGS_PROTOCOL").ok(),
|
||||
std::env::var("OTEL_AUDIT_LOGS_WORKSPACES")
|
||||
.ok()
|
||||
.map(|v| v.split(',').map(str::to_string).collect()),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,20 @@ pub(crate) fn init_logs_bridge_for_service(
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "private"))]
|
||||
pub(crate) fn init_audit_logs_bridge(_mode: &Mode, _hostname: &str, _env: &str) -> Option<EnvFilter> {
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "private"))]
|
||||
pub(crate) fn init_audit_logs_bridge_for_service(
|
||||
_service: &str,
|
||||
_hostname: &str,
|
||||
_env: &str,
|
||||
) -> Option<EnvFilter> {
|
||||
None
|
||||
}
|
||||
|
||||
/// Export the log records still batched, for a process about to exit.
|
||||
#[cfg(not(feature = "private"))]
|
||||
pub async fn flush_otel_logs() {}
|
||||
|
||||
@@ -67,6 +67,14 @@ fn create_targets_filter(default_env_filter: LevelFilter) -> Targets {
|
||||
}
|
||||
}
|
||||
|
||||
fn audit_filter() -> Targets {
|
||||
Targets::new().with_target(AUDIT_TARGET, LevelFilter::INFO)
|
||||
}
|
||||
|
||||
fn not_audit_filter() -> tracing_subscriber::filter::FilterFn<impl Fn(&tracing::Metadata<'_>) -> bool> {
|
||||
tracing_subscriber::filter::filter_fn(|m| m.target() != AUDIT_TARGET)
|
||||
}
|
||||
|
||||
pub const LOGS_SERVICE: &str = "logs/services/";
|
||||
pub const LOGS_AUDIT: &str = "logs/audit/";
|
||||
|
||||
@@ -120,6 +128,7 @@ pub fn initialize_tracing(
|
||||
let opentelemetry: Option<EnvFilter> = None;
|
||||
|
||||
let logs_bridge = crate::otel_oss::init_logs_bridge(&mode, hostname, environment);
|
||||
let audit_logs_bridge = crate::otel_oss::init_audit_logs_bridge(&mode, hostname, environment);
|
||||
|
||||
use tracing_appender::rolling::{RollingFileAppender, Rotation};
|
||||
|
||||
@@ -168,6 +177,9 @@ pub fn initialize_tracing(
|
||||
|
||||
// Create a common filter for OTEL logs bridge and tracing layer to respect RUST_LOG
|
||||
let otel_logs_filter = file_env_filter.clone();
|
||||
let otel_logs_without_audit = crate::OTEL_LOGS_EXCLUDE_AUDIT
|
||||
.load(std::sync::atomic::Ordering::Relaxed)
|
||||
.then(not_audit_filter);
|
||||
|
||||
// Apply filter to the opentelemetry tracing layer to prevent debug events from being attached to spans
|
||||
#[cfg(all(feature = "otel", feature = "enterprise"))]
|
||||
@@ -180,7 +192,17 @@ 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_logs_without_audit),
|
||||
)
|
||||
// Audit events reach their own export whatever RUST_LOG is set to.
|
||||
.with(
|
||||
audit_logs_bridge
|
||||
.with_filter(audit_filter())
|
||||
.with_filter(audit_workspace_filter()),
|
||||
)
|
||||
.with(opentelemetry_filtered);
|
||||
|
||||
// The service log files are written to be indexed, not tailed, so they always carry the
|
||||
@@ -229,9 +251,18 @@ pub fn initialize_tracing(
|
||||
/// value, masked by a list of known secret fields rather than by shape, and that is fit
|
||||
/// for the operator's own stdout but not for a collector.
|
||||
pub fn initialize_subcommand_tracing(service: &str, hostname: &str, environment: &str) {
|
||||
let logs_bridge = crate::otel_oss::init_logs_bridge_for_service(service, hostname, environment);
|
||||
let logs_bridge = (!crate::OTEL_LOGS_EXCLUDE_AUDIT.load(std::sync::atomic::Ordering::Relaxed))
|
||||
.then(|| crate::otel_oss::init_logs_bridge_for_service(service, hostname, environment))
|
||||
.flatten();
|
||||
let audit_logs_bridge =
|
||||
crate::otel_oss::init_audit_logs_bridge_for_service(service, hostname, environment);
|
||||
tracing_subscriber::registry()
|
||||
.with(logs_bridge.with_filter(Targets::new().with_target(AUDIT_TARGET, LevelFilter::INFO)))
|
||||
.with(logs_bridge.with_filter(audit_filter()))
|
||||
.with(
|
||||
audit_logs_bridge
|
||||
.with_filter(audit_filter())
|
||||
.with_filter(audit_workspace_filter()),
|
||||
)
|
||||
.with(
|
||||
tracing_subscriber::fmt::layer().with_filter(
|
||||
EnvFilter::builder()
|
||||
@@ -242,6 +273,50 @@ pub fn initialize_subcommand_tracing(service: &str, hostname: &str, environment:
|
||||
.init();
|
||||
}
|
||||
|
||||
/// Keeps the audit events of the listed workspaces and lets every other event through.
|
||||
/// Entries about the instance itself are recorded under workspace `global` and always kept:
|
||||
/// no workspace stands behind them, and dropping them would hide settings changes.
|
||||
struct AuditWorkspaceFilter(std::collections::HashSet<String>);
|
||||
|
||||
impl AuditWorkspaceFilter {
|
||||
fn new(workspaces: Vec<String>) -> Self {
|
||||
Self(workspaces.into_iter().collect())
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> tracing_subscriber::layer::Filter<S> for AuditWorkspaceFilter {
|
||||
fn enabled(&self, _: &tracing::Metadata<'_>, _: &Context<'_, S>) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn event_enabled(&self, event: &Event<'_>, _: &Context<'_, S>) -> bool {
|
||||
if event.metadata().target() != AUDIT_TARGET {
|
||||
return true;
|
||||
}
|
||||
struct Workspace<'a>(&'a std::collections::HashSet<String>, Option<bool>);
|
||||
impl tracing::field::Visit for Workspace<'_> {
|
||||
fn record_str(&mut self, field: &tracing::field::Field, value: &str) {
|
||||
if field.name() == "workspace_id" {
|
||||
self.1 = Some(value == "global" || self.0.contains(value));
|
||||
}
|
||||
}
|
||||
fn record_debug(&mut self, _: &tracing::field::Field, _: &dyn std::fmt::Debug) {}
|
||||
}
|
||||
let mut ws = Workspace(&self.0, None);
|
||||
event.record(&mut ws);
|
||||
ws.1.unwrap_or(true)
|
||||
}
|
||||
}
|
||||
|
||||
/// The workspace scope of the audit export, `None` for every workspace.
|
||||
fn audit_workspace_filter() -> Option<AuditWorkspaceFilter> {
|
||||
crate::OTEL_AUDIT_LOGS_EXPORT
|
||||
.read()
|
||||
.ok()
|
||||
.and_then(|e| e.as_ref().and_then(|e| e.workspaces.clone()))
|
||||
.map(AuditWorkspaceFilter::new)
|
||||
}
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
pub static ref LOG_COUNTING_BY_MIN: Arc<RwLock<HashMap<String, LogCounter>>> = Arc::new(RwLock::new(HashMap::new()));
|
||||
}
|
||||
@@ -290,3 +365,54 @@ where
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::sync::Mutex;
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
struct Seen(Arc<Mutex<Vec<String>>>);
|
||||
|
||||
impl<S: tracing::Subscriber> tracing_subscriber::Layer<S> for Seen {
|
||||
fn on_event(&self, event: &Event<'_>, _: Context<'_, S>) {
|
||||
struct Msg(String);
|
||||
impl tracing::field::Visit for Msg {
|
||||
fn record_debug(&mut self, f: &tracing::field::Field, v: &dyn std::fmt::Debug) {
|
||||
if f.name() == "message" {
|
||||
self.0 = format!("{v:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut m = Msg(String::new());
|
||||
event.record(&mut m);
|
||||
self.0.lock().unwrap().push(m.0);
|
||||
}
|
||||
}
|
||||
|
||||
/// The two exports as `initialize_tracing` filters them: the logs export without audit
|
||||
/// events, and the audit export with audit events of the listed workspaces only.
|
||||
#[test]
|
||||
fn audit_and_logs_exports_split_events() {
|
||||
let logs = Seen::default();
|
||||
let audit = Seen::default();
|
||||
tracing::subscriber::with_default(
|
||||
tracing_subscriber::registry()
|
||||
.with(logs.clone().with_filter(Some(not_audit_filter())))
|
||||
.with(
|
||||
audit
|
||||
.clone()
|
||||
.with_filter(audit_filter())
|
||||
.with_filter(Some(AuditWorkspaceFilter::new(vec!["kept".to_string()]))),
|
||||
),
|
||||
|| {
|
||||
tracing::info!(target: AUDIT_TARGET, workspace_id = "kept", "a");
|
||||
tracing::info!(target: AUDIT_TARGET, workspace_id = "dropped", "b");
|
||||
tracing::info!(target: AUDIT_TARGET, workspace_id = "global", "c");
|
||||
tracing::info!(workspace_id = "kept", "d");
|
||||
},
|
||||
);
|
||||
assert_eq!(*logs.0.lock().unwrap(), ["d"]);
|
||||
assert_eq!(*audit.0.lock().unwrap(), ["a", "c"]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
import RetentionPeriodOverrides from './instanceSettings/RetentionPeriodOverrides.svelte'
|
||||
import AgentWorkloadIdentityIssuers from './instanceSettings/AgentWorkloadIdentityIssuers.svelte'
|
||||
import McpExternalIdp from './instanceSettings/McpExternalIdp.svelte'
|
||||
import OtelAuditLogsSettings from './instanceSettings/OtelAuditLogsSettings.svelte'
|
||||
import WorkspaceRolesSetting from './instanceSettings/WorkspaceRolesSetting.svelte'
|
||||
import SmtpSettings from './instanceSettings/SmtpSettings.svelte'
|
||||
import SecretBackendConfig from './instanceSettings/SecretBackendConfig.svelte'
|
||||
@@ -725,6 +726,7 @@
|
||||
Service name, environment, resource attributes, metrics temporality and other
|
||||
options are set with environment variables.
|
||||
</Description>
|
||||
<OtelAuditLogsSettings {values} disabled={!$enterpriseLicense} />
|
||||
{/if}
|
||||
</div>
|
||||
{:else if setting.fieldType == 'otel_tracing_proxy'}
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
<script lang="ts">
|
||||
import type { Writable } from 'svelte/store'
|
||||
import Toggle from '../Toggle.svelte'
|
||||
import TextInput from '../text_input/TextInput.svelte'
|
||||
import Select from '../select/Select.svelte'
|
||||
import OtelAuditWorkspaces from './OtelAuditWorkspaces.svelte'
|
||||
|
||||
interface Props {
|
||||
values: Writable<Record<string, any>>
|
||||
disabled?: boolean
|
||||
}
|
||||
|
||||
let { values, disabled = false }: Props = $props()
|
||||
</script>
|
||||
|
||||
{#if $values.otel}
|
||||
{#if $values.otel.logs_enabled}
|
||||
<Toggle
|
||||
{disabled}
|
||||
id="logs_exclude_audit"
|
||||
bind:checked={$values.otel.logs_exclude_audit}
|
||||
options={{
|
||||
right: 'Leave audit logs out of the logs export',
|
||||
rightTooltip: 'For when the audit logs export below carries them.'
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
|
||||
<div class="flex flex-col gap-4 pt-4 border-t">
|
||||
<div class="flex flex-col gap-1">
|
||||
<span class="text-xs font-semibold text-emphasis">Audit logs export</span>
|
||||
<span class="text-2xs text-secondary">
|
||||
A second logs exporter that receives audit logs only, whatever the log level, for example to
|
||||
keep them in long-term storage. It has its own endpoint and headers.
|
||||
</span>
|
||||
</div>
|
||||
<Toggle
|
||||
{disabled}
|
||||
id="audit_logs_enabled"
|
||||
bind:checked={$values.otel.audit_logs_enabled}
|
||||
options={{ right: 'Export audit logs' }}
|
||||
/>
|
||||
{#if $values.otel.audit_logs_enabled}
|
||||
<div class="flex flex-col gap-1">
|
||||
<label for="OTEL_AUDIT_LOGS_ENDPOINT" class="block text-xs font-semibold text-emphasis"
|
||||
>Endpoint</label
|
||||
>
|
||||
<TextInput
|
||||
inputProps={{
|
||||
type: 'text',
|
||||
placeholder: 'https://audit-collector.example.com:4317',
|
||||
id: 'OTEL_AUDIT_LOGS_ENDPOINT',
|
||||
disabled
|
||||
}}
|
||||
bind:value={$values.otel.audit_logs_endpoint}
|
||||
/>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1">
|
||||
<label for="OTEL_AUDIT_LOGS_HEADERS" class="block text-xs font-semibold text-emphasis"
|
||||
>Headers</label
|
||||
>
|
||||
<TextInput
|
||||
inputProps={{
|
||||
type: 'text',
|
||||
placeholder: 'Authorization=Bearer my-secret-token',
|
||||
id: 'OTEL_AUDIT_LOGS_HEADERS',
|
||||
disabled
|
||||
}}
|
||||
bind:value={$values.otel.audit_logs_headers}
|
||||
/>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1">
|
||||
<label for="OTEL_AUDIT_LOGS_PROTOCOL" class="block text-xs font-semibold text-emphasis"
|
||||
>Protocol</label
|
||||
>
|
||||
<Select
|
||||
id="OTEL_AUDIT_LOGS_PROTOCOL"
|
||||
{disabled}
|
||||
clearable
|
||||
placeholder="grpc (default)"
|
||||
items={[{ label: 'http/protobuf', value: 'http/protobuf' }]}
|
||||
bind:value={$values.otel.audit_logs_protocol}
|
||||
/>
|
||||
</div>
|
||||
<div class="flex flex-col gap-1">
|
||||
<span class="block text-xs font-semibold text-emphasis">Workspaces</span>
|
||||
<span class="text-2xs text-secondary">
|
||||
Export the audit logs of these workspaces only. Instance-level entries are always
|
||||
exported. Leave empty for all workspaces.
|
||||
</span>
|
||||
<OtelAuditWorkspaces bind:value={$values.otel.audit_logs_workspaces} {disabled} />
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
@@ -0,0 +1,40 @@
|
||||
<script lang="ts">
|
||||
import { WorkspaceService } from '$lib/gen'
|
||||
import MultiSelect from '$lib/components/select/MultiSelect.svelte'
|
||||
import { safeSelectItems } from '$lib/components/select/utils.svelte'
|
||||
import { resource } from 'runed'
|
||||
|
||||
interface Props {
|
||||
/** Empty exports every workspace's audit events. Cleared to `[]`, not unset: unset
|
||||
* falls back to the OTEL_AUDIT_LOGS_WORKSPACES environment variable. */
|
||||
value: string[] | undefined
|
||||
disabled?: boolean
|
||||
}
|
||||
|
||||
let { value = $bindable(), disabled = false }: Props = $props()
|
||||
|
||||
const workspaces = resource(
|
||||
() => undefined,
|
||||
async () => {
|
||||
const all: string[] = []
|
||||
for (let page = 1; ; page++) {
|
||||
const batch = await WorkspaceService.listWorkspacesAsSuperAdmin({ page, perPage: 100 })
|
||||
all.push(...batch.map((w) => w.id))
|
||||
if (batch.length < 100) break
|
||||
}
|
||||
return all
|
||||
}
|
||||
)
|
||||
|
||||
// Workspaces already listed stay selectable even when they no longer exist.
|
||||
let items = $derived(
|
||||
safeSelectItems([...new Set([...(workspaces.current ?? []), ...(value ?? [])])])
|
||||
)
|
||||
</script>
|
||||
|
||||
<MultiSelect
|
||||
{items}
|
||||
{disabled}
|
||||
placeholder="All workspaces"
|
||||
bind:value={() => value ?? [], (v) => (value = v)}
|
||||
/>
|
||||
Reference in New Issue
Block a user