diff --git a/crates/obs/Cargo.toml b/crates/obs/Cargo.toml index 03aa44b81..7a00bc879 100644 --- a/crates/obs/Cargo.toml +++ b/crates/obs/Cargo.toml @@ -56,7 +56,7 @@ dial9-tokio-telemetry = { workspace = true } thiserror = { workspace = true } zstd = { workspace = true, features = ["zstdmt"] } -[target.'cfg(unix)'.dependencies] +[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies] pyroscope = { workspace = true, features = ["backend-pprof-rs"] } diff --git a/crates/obs/src/telemetry/guard.rs b/crates/obs/src/telemetry/guard.rs index f91d25ce7..26c868d50 100644 --- a/crates/obs/src/telemetry/guard.rs +++ b/crates/obs/src/telemetry/guard.rs @@ -41,7 +41,7 @@ pub struct OtelGuard { pub(crate) meter_provider: Option, /// Optional logger provider for OTLP log export. pub(crate) logger_provider: Option, - #[cfg(unix)] + #[cfg(any(target_os = "linux", target_os = "macos"))] pub(crate) profiling_agent: Option>, /// Handle to the background log-cleanup task; aborted on drop. pub(crate) cleanup_handle: Option>, @@ -58,7 +58,7 @@ impl std::fmt::Debug for OtelGuard { s.field("tracer_provider", &self.tracer_provider.is_some()) .field("meter_provider", &self.meter_provider.is_some()) .field("logger_provider", &self.logger_provider.is_some()); - #[cfg(unix)] + #[cfg(any(target_os = "linux", target_os = "macos"))] s.field("profiling_agent", &self.profiling_agent.is_some()); s.field("cleanup_handle", &self.cleanup_handle.is_some()) .field("tracing_guard", &self.tracing_guard.is_some()) @@ -91,7 +91,7 @@ impl Drop for OtelGuard { eprintln!("Logger shutdown error: {err:?}"); } - #[cfg(unix)] + #[cfg(any(target_os = "linux", target_os = "macos"))] if let Some(agent) = self.profiling_agent.take() { match agent.stop() { Err(err) => eprintln!("Profiling agent stop error: {err:?}"), diff --git a/crates/obs/src/telemetry/local.rs b/crates/obs/src/telemetry/local.rs index c7d8cedf6..b73d3ac23 100644 --- a/crates/obs/src/telemetry/local.rs +++ b/crates/obs/src/telemetry/local.rs @@ -155,7 +155,7 @@ fn init_stdout_only(_config: &OtelConfig, logger_level: &str, is_production: boo tracer_provider: None, meter_provider: None, logger_provider: None, - #[cfg(unix)] + #[cfg(any(target_os = "linux", target_os = "macos"))] profiling_agent: None, tracing_guard: Some(guard), stdout_guard: None, @@ -289,7 +289,7 @@ fn init_file_logging_internal( tracer_provider: None, meter_provider: None, logger_provider: None, - #[cfg(unix)] + #[cfg(any(target_os = "linux", target_os = "macos"))] profiling_agent: None, tracing_guard: Some(guard), stdout_guard, diff --git a/crates/obs/src/telemetry/otel.rs b/crates/obs/src/telemetry/otel.rs index 3d4320356..736dc0dcd 100644 --- a/crates/obs/src/telemetry/otel.rs +++ b/crates/obs/src/telemetry/otel.rs @@ -162,7 +162,7 @@ pub(super) fn init_observability_http( // ── Meter provider (HTTP) ───────────────────────────────────────────────── let meter_provider = build_meter_provider(&metric_ep, config, res.clone(), &service_name, use_stdout)?; - #[cfg(unix)] + #[cfg(any(target_os = "linux", target_os = "macos"))] let profiling_agent = init_profiler(config); // ── Logger Logic ────────────────────────────────────────────────────────── @@ -205,7 +205,7 @@ pub(super) fn init_observability_http( let file_logging_result = (|| -> Result<_, TelemetryError> { fs::create_dir_all(log_directory).map_err(|e| TelemetryError::Io(e.to_string()))?; - #[cfg(unix)] + #[cfg(any(target_os = "linux", target_os = "macos"))] crate::telemetry::local::ensure_dir_permissions(log_directory)?; let rotation_str = config @@ -312,7 +312,7 @@ pub(super) fn init_observability_http( tracer_provider, meter_provider, logger_provider, - #[cfg(unix)] + #[cfg(any(target_os = "linux", target_os = "macos"))] profiling_agent, tracing_guard, stdout_guard, @@ -462,9 +462,10 @@ fn build_logger_provider( /// Start the Pyroscope continuous profiling agent when profiling is enabled. /// -/// Returns `None` on non-Unix platforms, when the feature is disabled, or when -/// no usable profiling endpoint is configured. -#[cfg(unix)] +/// Returns `None` when profiling export is disabled, when no usable +/// profiling endpoint is configured, or when building or starting the agent +/// fails. +#[cfg(any(target_os = "linux", target_os = "macos"))] fn init_profiler(config: &OtelConfig) -> Option> { use pyroscope::backend::{BackendConfig, PprofConfig, pprof_backend}; use pyroscope::pyroscope::PyroscopeAgentBuilder;