Commit 5e01e6be authored by patrick's avatar patrick
Browse files

add id to tracing span

parent e7dc80d0
...@@ -189,7 +189,7 @@ impl ClientT for HttpClient { ...@@ -189,7 +189,7 @@ impl ClientT for HttpClient {
let guard = self.id_manager.next_request_id()?; let guard = self.id_manager.next_request_id()?;
let id = guard.inner(); let id = guard.inner();
let request = RequestSer::new(&id, method, params); let request = RequestSer::new(&id, method, params);
let trace = RpcTracing::method_call(method); let trace = RpcTracing::method_call(method, &id);
let _enter = trace.span().enter(); let _enter = trace.span().enter();
let raw = serde_json::to_string(&request).map_err(Error::ParseError)?; let raw = serde_json::to_string(&request).map_err(Error::ParseError)?;
......
...@@ -269,7 +269,7 @@ impl ClientT for Client { ...@@ -269,7 +269,7 @@ impl ClientT for Client {
let (send_back_tx, send_back_rx) = oneshot::channel(); let (send_back_tx, send_back_rx) = oneshot::channel();
let guard = self.id_manager.next_request_id()?; let guard = self.id_manager.next_request_id()?;
let id = guard.inner(); let id = guard.inner();
let trace = RpcTracing::method_call(method); let trace = RpcTracing::method_call(method, &id);
let _enter = trace.span().enter(); let _enter = trace.span().enter();
let raw = serde_json::to_string(&RequestSer::new(&id, method, params)).map_err(Error::ParseError)?; let raw = serde_json::to_string(&RequestSer::new(&id, method, params)).map_err(Error::ParseError)?;
...@@ -363,10 +363,11 @@ impl SubscriptionClientT for Client { ...@@ -363,10 +363,11 @@ impl SubscriptionClientT for Client {
let guard = self.id_manager.next_request_ids(2)?; let guard = self.id_manager.next_request_ids(2)?;
let mut ids: Vec<Id> = guard.inner(); let mut ids: Vec<Id> = guard.inner();
let trace = RpcTracing::method_call(subscribe_method); let id = ids[0].clone();
let trace = RpcTracing::method_call(subscribe_method, &id);
let _enter = trace.span().enter(); let _enter = trace.span().enter();
let id = ids[0].clone();
let raw = serde_json::to_string(&RequestSer::new(&id, subscribe_method, params)).map_err(Error::ParseError)?; let raw = serde_json::to_string(&RequestSer::new(&id, subscribe_method, params)).map_err(Error::ParseError)?;
......
use serde::Serialize; use serde::Serialize;
use tracing::Level; use tracing::Level;
use jsonrpsee_types::Id;
#[derive(Debug)] #[derive(Debug)]
/// Wrapper over [`tracing::Span`] to trace individual method calls, notifications and similar. /// Wrapper over [`tracing::Span`] to trace individual method calls, notifications and similar.
...@@ -9,8 +10,8 @@ impl RpcTracing { ...@@ -9,8 +10,8 @@ impl RpcTracing {
/// Create a `method_call` tracing target. /// Create a `method_call` tracing target.
/// ///
/// To enable this you need to call `RpcTracing::method_call("some_method").span().enable()`. /// To enable this you need to call `RpcTracing::method_call("some_method").span().enable()`.
pub fn method_call(method: &str) -> Self { pub fn method_call(method: &str, id:&Id) -> Self {
Self(tracing::span!(tracing::Level::DEBUG, "method_call", %method)) Self(tracing::span!(tracing::Level::DEBUG, "method_call", %method, id =? id))
} }
/// Create a `notification` tracing target. /// Create a `notification` tracing target.
......
...@@ -685,7 +685,8 @@ async fn process_health_request<M: Middleware>( ...@@ -685,7 +685,8 @@ async fn process_health_request<M: Middleware>(
request_start: M::Instant, request_start: M::Instant,
max_log_length: u32, max_log_length: u32,
) -> Result<hyper::Response<hyper::Body>, HyperError> { ) -> Result<hyper::Response<hyper::Body>, HyperError> {
let trace = RpcTracing::method_call(&health_api.method); let id = Id::Number(100);
let trace = RpcTracing::method_call(&health_api.method, &id);
let _enter = trace.span().enter(); let _enter = trace.span().enter();
tx_log_from_str("HTTP health API", max_log_length); tx_log_from_str("HTTP health API", max_log_length);
...@@ -805,7 +806,7 @@ where ...@@ -805,7 +806,7 @@ where
async fn process_single_request<M: Middleware>(data: Vec<u8>, call: CallData<'_, M>) -> MethodResponse { async fn process_single_request<M: Middleware>(data: Vec<u8>, call: CallData<'_, M>) -> MethodResponse {
if let Ok(req) = serde_json::from_slice::<Request>(&data) { if let Ok(req) = serde_json::from_slice::<Request>(&data) {
let trace = RpcTracing::method_call(&req.method); let trace = RpcTracing::method_call(&req.method, &req.id);
let _enter = trace.span().enter(); let _enter = trace.span().enter();
rx_log_from_json(&req, call.max_log_length); rx_log_from_json(&req, call.max_log_length);
......
...@@ -893,7 +893,7 @@ where ...@@ -893,7 +893,7 @@ where
async fn process_single_request<M: Middleware>(data: Vec<u8>, call: CallData<'_, M>) -> MethodResult { async fn process_single_request<M: Middleware>(data: Vec<u8>, call: CallData<'_, M>) -> MethodResult {
if let Ok(req) = serde_json::from_slice::<Request>(&data) { if let Ok(req) = serde_json::from_slice::<Request>(&data) {
let trace = RpcTracing::method_call(&req.method); let trace = RpcTracing::method_call(&req.method, &req.id);
let _enter = trace.span().enter(); let _enter = trace.span().enter();
rx_log_from_json(&req, call.max_log_length); rx_log_from_json(&req, call.max_log_length);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment