use std::sync::Arc;
use camel_api::{ComponentMetrics, MetricsCollector};
use crate::{ComponentContext, HealthCheckRegistry};
pub trait RuntimeObservability: Send + Sync {
fn metrics(&self) -> Arc<dyn MetricsCollector>;
fn health(&self) -> Arc<dyn HealthCheckRegistry>;
fn component_metrics(&self) -> ComponentMetrics {
ComponentMetrics::new(self.metrics(), false)
}
}
impl<T: ComponentContext> RuntimeObservability for T {
fn metrics(&self) -> Arc<dyn MetricsCollector> {
<Self as ComponentContext>::metrics(self)
}
fn health(&self) -> Arc<dyn HealthCheckRegistry> {
<Self as ComponentContext>::health(self)
}
fn component_metrics(&self) -> ComponentMetrics {
ComponentMetrics::new(
<Self as ComponentContext>::metrics(self),
<Self as ComponentContext>::component_metrics_enabled(self),
)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn runtime_observability_is_send_sync() {
fn assert_send_sync<T: Send + Sync + ?Sized>() {}
assert_send_sync::<dyn RuntimeObservability>();
}
}