chore: add client api version (#248)
* chore: add client api version * chore: update * chore: update * chore: log client version
This commit is contained in:
parent
4886d3d474
commit
2159c68688
|
|
@ -52,6 +52,7 @@ use gotrue_entity::dto::SignUpResponse::{Authenticated, NotAuthenticated};
|
||||||
use gotrue_entity::dto::{GotrueTokenResponse, UpdateGotrueUserParams, User};
|
use gotrue_entity::dto::{GotrueTokenResponse, UpdateGotrueUserParams, User};
|
||||||
use realtime_entity::realtime_proto::HttpRealtimeMessage;
|
use realtime_entity::realtime_proto::HttpRealtimeMessage;
|
||||||
|
|
||||||
|
pub const CLIENT_API_VERSION: &str = "0.0.2";
|
||||||
/// `Client` is responsible for managing communication with the GoTrue API and cloud storage.
|
/// `Client` is responsible for managing communication with the GoTrue API and cloud storage.
|
||||||
///
|
///
|
||||||
/// It provides methods to perform actions like signing in, signing out, refreshing tokens,
|
/// It provides methods to perform actions like signing in, signing out, refreshing tokens,
|
||||||
|
|
@ -1170,6 +1171,7 @@ impl Client {
|
||||||
let request_builder = self
|
let request_builder = self
|
||||||
.cloud_client
|
.cloud_client
|
||||||
.request(method, url)
|
.request(method, url)
|
||||||
|
.header("client-version", CLIENT_API_VERSION)
|
||||||
.bearer_auth(access_token);
|
.bearer_auth(access_token);
|
||||||
Ok(request_builder)
|
Ok(request_builder)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,10 +59,12 @@ where
|
||||||
request_id
|
request_id
|
||||||
});
|
});
|
||||||
|
|
||||||
let span = match get_payload_size(&req) {
|
let client_info = get_client_info(&req);
|
||||||
Some(size) => span!(Level::INFO, "request", request_id = %request_id, payload_size = size),
|
let span = span!(Level::INFO, "request",
|
||||||
None => span!(Level::INFO, "request", request_id = %request_id),
|
request_id = %request_id,
|
||||||
};
|
client_version = client_info.client_version,
|
||||||
|
payload_size = client_info.payload_size
|
||||||
|
);
|
||||||
|
|
||||||
let fut = self.service.call(req);
|
let fut = self.service.call(req);
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
|
|
@ -93,10 +95,27 @@ pub fn get_request_id(req: &ServiceRequest) -> Option<String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_payload_size(req: &ServiceRequest) -> Option<usize> {
|
#[inline]
|
||||||
req
|
fn get_client_info(req: &ServiceRequest) -> ClientInfo {
|
||||||
|
let payload_size = req
|
||||||
.headers()
|
.headers()
|
||||||
.get("content-length")
|
.get("content-length")
|
||||||
.and_then(|val| val.to_str().ok())
|
.and_then(|val| val.to_str().ok())
|
||||||
.and_then(|val| val.parse::<usize>().ok())
|
.and_then(|val| val.parse::<usize>().ok())
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
let client_version = req
|
||||||
|
.headers()
|
||||||
|
.get("client-version")
|
||||||
|
.and_then(|val| val.to_str().ok());
|
||||||
|
|
||||||
|
ClientInfo {
|
||||||
|
payload_size,
|
||||||
|
client_version,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ClientInfo<'a> {
|
||||||
|
payload_size: usize,
|
||||||
|
client_version: Option<&'a str>,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue