diff --git a/async-nats/src/service/endpoint.rs b/async-nats/src/service/endpoint.rs index 7c17a97ae..6f3b4fdf0 100644 --- a/async-nats/src/service/endpoint.rs +++ b/async-nats/src/service/endpoint.rs @@ -130,7 +130,7 @@ pub(crate) struct Inner { /// Last error that occurred. pub(crate) last_error: Option, /// Custom data added by [Config::stats_handler] - pub(crate) data: Option, + pub(crate) data: Option, /// Queue group to which this endpoint is assigned to. pub(crate) queue_group: String, } @@ -173,7 +173,7 @@ pub struct Stats { #[serde(with = "serde_error_string")] pub last_error: Option, /// Custom data added by [crate::service::Config::stats_handler] - pub data: Option, + pub data: Option, /// Queue group to which this endpoint is assigned to. pub queue_group: String, } diff --git a/async-nats/src/service/mod.rs b/async-nats/src/service/mod.rs index a66456d0d..a938fde1d 100644 --- a/async-nats/src/service/mod.rs +++ b/async-nats/src/service/mod.rs @@ -163,7 +163,7 @@ impl ServiceBuilder { /// Handler for custom service statistics. pub fn stats_handler(mut self, handler: F) -> Self where - F: FnMut(String, endpoint::Stats) -> String + Send + Sync + 'static, + F: FnMut(String, endpoint::Stats) -> serde_json::Value + Send + Sync + 'static, { self.stats_handler = Some(StatsHandler(Box::new(handler))); self @@ -265,7 +265,7 @@ pub trait ServiceExt { /// let mut service = client /// .service_builder() /// .description("some service") - /// .stats_handler(|endpoint, stats| format!("customstats")) + /// .stats_handler(|endpoint, stats| serde_json::json!({ "endpoint": endpoint })) /// .start("products", "1.0.0") /// .await?; /// @@ -870,7 +870,7 @@ impl EndpointBuilder { } } -pub struct StatsHandler(pub Box String + Send>); +pub struct StatsHandler(pub Box serde_json::Value + Send>); impl std::fmt::Debug for StatsHandler { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { diff --git a/async-nats/tests/service_tests.rs b/async-nats/tests/service_tests.rs index 2cea4eb16..0c0999f54 100644 --- a/async-nats/tests/service_tests.rs +++ b/async-nats/tests/service_tests.rs @@ -517,7 +517,7 @@ mod service { let service = client .service_builder() - .stats_handler(|endpoint, _| format!("custom data for {endpoint}")) + .stats_handler(|endpoint, _| serde_json::json!({ "endpoint": endpoint })) .description("a cross service") .start("cross", "1.0.0") .await