use crate::Result;
#[derive(Clone, Debug)]
pub struct ServiceController<T>
where
T: super::stub::ServiceController + std::fmt::Debug + Send + Sync,
{
inner: T,
duration: gaxi::observability::DurationMetric,
}
impl<T> ServiceController<T>
where
T: super::stub::ServiceController + std::fmt::Debug + Send + Sync,
{
pub fn new(inner: T) -> Self {
Self {
inner,
duration: gaxi::observability::DurationMetric::new(&info::INSTRUMENTATION_CLIENT_INFO),
}
}
}
impl<T> super::stub::ServiceController for ServiceController<T>
where
T: super::stub::ServiceController + std::fmt::Debug + Send + Sync,
{
#[tracing::instrument(level = tracing::Level::DEBUG, ret)]
async fn check(
&self,
req: crate::model::CheckRequest,
options: crate::RequestOptions,
) -> Result<crate::Response<crate::model::CheckResponse>> {
let (_span, pending) = gaxi::client_request_signals!(
metric: self.duration.clone(),
info: *info::INSTRUMENTATION_CLIENT_INFO,
method: "client::ServiceController::check",
self.inner.check(req, options));
pending.await
}
#[tracing::instrument(level = tracing::Level::DEBUG, ret)]
async fn report(
&self,
req: crate::model::ReportRequest,
options: crate::RequestOptions,
) -> Result<crate::Response<crate::model::ReportResponse>> {
let (_span, pending) = gaxi::client_request_signals!(
metric: self.duration.clone(),
info: *info::INSTRUMENTATION_CLIENT_INFO,
method: "client::ServiceController::report",
self.inner.report(req, options));
pending.await
}
}
pub(crate) mod info {
const NAME: &str = env!("CARGO_PKG_NAME");
const VERSION: &str = env!("CARGO_PKG_VERSION");
pub(crate) static INSTRUMENTATION_CLIENT_INFO: std::sync::LazyLock<
gaxi::options::InstrumentationClientInfo,
> = std::sync::LazyLock::new(|| {
let mut info = gaxi::options::InstrumentationClientInfo::default();
info.service_name = "servicecontrol";
info.client_version = VERSION;
info.client_artifact = NAME;
info.default_host = "servicecontrol";
info
});
}