mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-15 03:25:46 -04:00
chore(sdk): Log the response/request sizes as well
This commit is contained in:
7
Cargo.lock
generated
7
Cargo.lock
generated
@@ -517,6 +517,12 @@ version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c"
|
||||
|
||||
[[package]]
|
||||
name = "bytesize"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6c58ec36aac5066d5ca17df51b3e70279f5670a72102f5752cb7e7c856adfc70"
|
||||
|
||||
[[package]]
|
||||
name = "camino"
|
||||
version = "1.1.2"
|
||||
@@ -2576,6 +2582,7 @@ dependencies = [
|
||||
"async-trait",
|
||||
"backoff",
|
||||
"bytes",
|
||||
"bytesize",
|
||||
"chrono",
|
||||
"ctor",
|
||||
"dashmap",
|
||||
|
||||
@@ -64,6 +64,7 @@ anymap2 = "0.13.0"
|
||||
async-stream = { workspace = true }
|
||||
async-trait = { workspace = true }
|
||||
bytes = "1.1.0"
|
||||
bytesize = "1.1"
|
||||
chrono = { version = "0.4.23", optional = true }
|
||||
dashmap = { workspace = true }
|
||||
derive_builder = { version = "0.11.2", optional = true }
|
||||
|
||||
@@ -24,6 +24,7 @@ use std::{
|
||||
|
||||
use async_trait::async_trait;
|
||||
use bytes::{Bytes, BytesMut};
|
||||
use bytesize::ByteSize;
|
||||
use matrix_sdk_common::AsyncTraitDeps;
|
||||
use ruma::{
|
||||
api::{
|
||||
@@ -164,7 +165,7 @@ impl HttpClient {
|
||||
&self,
|
||||
request: http::Request<Bytes>,
|
||||
config: RequestConfig,
|
||||
) -> Result<(http::StatusCode, R::IncomingResponse), HttpError>
|
||||
) -> Result<(http::StatusCode, ByteSize, R::IncomingResponse), HttpError>
|
||||
where
|
||||
R: OutgoingRequest + Debug,
|
||||
HttpError: From<FromHttpResponseError<R::EndpointError>>,
|
||||
@@ -230,11 +231,12 @@ impl HttpClient {
|
||||
.map_err(error_type)?;
|
||||
|
||||
let status_code = response.status();
|
||||
let response_size = ByteSize(response.body().len().try_into().unwrap_or(u64::MAX));
|
||||
|
||||
let response = R::IncomingResponse::try_from_http_response(response)
|
||||
.map_err(|e| error_type(HttpError::from(e)))?;
|
||||
|
||||
Ok((status_code, response))
|
||||
Ok((status_code, response_size, response))
|
||||
};
|
||||
|
||||
retry::<_, HttpError, _, _, _>(backoff, send_request).await?
|
||||
@@ -244,8 +246,9 @@ impl HttpClient {
|
||||
let ret = {
|
||||
let response = self.inner.send_request(request, config.timeout).await?;
|
||||
let status_code = response.status();
|
||||
let response_size = ByteSize(response.body().len().try_into().unwrap_or(u64::MAX));
|
||||
|
||||
(status_code, R::IncomingResponse::try_from_http_response(response)?)
|
||||
(status_code, response_size, R::IncomingResponse::try_from_http_response(response)?)
|
||||
};
|
||||
|
||||
Ok(ret)
|
||||
@@ -253,7 +256,16 @@ impl HttpClient {
|
||||
|
||||
#[instrument(
|
||||
skip(self, access_token, config, request, user_id),
|
||||
fields(config, path, user_id, request_body, request_id, status)
|
||||
fields(
|
||||
config,
|
||||
path,
|
||||
user_id,
|
||||
request_size,
|
||||
request_body,
|
||||
request_id,
|
||||
status,
|
||||
response_size,
|
||||
)
|
||||
)]
|
||||
pub async fn send<R>(
|
||||
&self,
|
||||
@@ -300,7 +312,9 @@ impl HttpClient {
|
||||
server_versions,
|
||||
)?;
|
||||
|
||||
span.record("path", request.uri().path());
|
||||
let request_size = ByteSize(request.body().len().try_into().unwrap_or(u64::MAX));
|
||||
span.record("path", request.uri().path())
|
||||
.record("request_size", request_size.to_string_as(true));
|
||||
|
||||
// Since sliding sync is experimental, and the proxy might not do what we expect
|
||||
// it to do given a specific request body, it's useful to log the
|
||||
@@ -313,8 +327,9 @@ impl HttpClient {
|
||||
|
||||
debug!("Sending request");
|
||||
match self.send_request::<R>(request, config).await {
|
||||
Ok((status_code, response)) => {
|
||||
span.record("status", status_code.as_u16());
|
||||
Ok((status_code, response_size, response)) => {
|
||||
span.record("status", status_code.as_u16())
|
||||
.record("response_size", response_size.to_string_as(true));
|
||||
debug!("Got response");
|
||||
|
||||
Ok(response)
|
||||
|
||||
Reference in New Issue
Block a user