client: Add some tracing spans
This commit is contained in:
parent
cd905e01fd
commit
4d1ff8de23
@ -48,6 +48,7 @@ ruma-identifiers = { version = "0.20.0", path = "../ruma-identifiers" }
|
|||||||
ruma-serde = { version = "0.5.0", path = "../ruma-serde" }
|
ruma-serde = { version = "0.5.0", path = "../ruma-serde" }
|
||||||
serde = { version = "1.0.118", features = ["derive"] }
|
serde = { version = "1.0.118", features = ["derive"] }
|
||||||
serde_json = "1.0.61"
|
serde_json = "1.0.61"
|
||||||
|
tracing = { version = "0.1.30", default-features = false, features = ["std"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
ruma-client-api = { version = "0.12.3", path = "../ruma-client-api", features = ["client"] }
|
ruma-client-api = { version = "0.12.3", path = "../ruma-client-api", features = ["client"] }
|
||||||
|
@ -94,12 +94,14 @@
|
|||||||
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
|
any::type_name,
|
||||||
future::Future,
|
future::Future,
|
||||||
sync::{Arc, Mutex},
|
sync::{Arc, Mutex},
|
||||||
};
|
};
|
||||||
|
|
||||||
use ruma_api::{MatrixVersion, OutgoingRequest, SendAccessToken};
|
use ruma_api::{MatrixVersion, OutgoingRequest, SendAccessToken};
|
||||||
use ruma_identifiers::UserId;
|
use ruma_identifiers::UserId;
|
||||||
|
use tracing::{info_span, Instrument};
|
||||||
|
|
||||||
// "Undo" rename from `Cargo.toml` that only serves to make crate names available as a Cargo
|
// "Undo" rename from `Cargo.toml` that only serves to make crate names available as a Cargo
|
||||||
// feature names.
|
// feature names.
|
||||||
@ -244,17 +246,36 @@ where
|
|||||||
R: OutgoingRequest,
|
R: OutgoingRequest,
|
||||||
F: FnOnce(&mut http::Request<C::RequestBody>) -> Result<(), ResponseError<C, R>>,
|
F: FnOnce(&mut http::Request<C::RequestBody>) -> Result<(), ResponseError<C, R>>,
|
||||||
{
|
{
|
||||||
let http_req = request
|
let http_req =
|
||||||
.try_into_http_request(homeserver_url, send_access_token, for_versions)
|
info_span!("serialize_request", request_type = type_name::<R>()).in_scope(move || {
|
||||||
.map_err(ResponseError::<C, R>::from)
|
request
|
||||||
.and_then(|mut req| {
|
.try_into_http_request(homeserver_url, send_access_token, for_versions)
|
||||||
customize(&mut req)?;
|
.map_err(ResponseError::<C, R>::from)
|
||||||
Ok(req)
|
.and_then(|mut req| {
|
||||||
|
customize(&mut req)?;
|
||||||
|
Ok(req)
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let send_span = info_span!(
|
||||||
|
"send_request",
|
||||||
|
request_type = type_name::<R>(),
|
||||||
|
http_client = type_name::<C>(),
|
||||||
|
homeserver_url,
|
||||||
|
);
|
||||||
|
|
||||||
async move {
|
async move {
|
||||||
let http_res = http_client.send_http_request(http_req?).await.map_err(Error::Response)?;
|
let http_res = http_client
|
||||||
Ok(ruma_api::IncomingResponse::try_from_http_response(http_res)?)
|
.send_http_request(http_req?)
|
||||||
|
.instrument(send_span)
|
||||||
|
.await
|
||||||
|
.map_err(Error::Response)?;
|
||||||
|
|
||||||
|
let res =
|
||||||
|
info_span!("deserialize_response", response_type = type_name::<R::IncomingResponse>())
|
||||||
|
.in_scope(move || ruma_api::IncomingResponse::try_from_http_response(http_res))?;
|
||||||
|
|
||||||
|
Ok(res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user