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 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.
|
||||
///
|
||||
/// It provides methods to perform actions like signing in, signing out, refreshing tokens,
|
||||
|
|
@ -1170,6 +1171,7 @@ impl Client {
|
|||
let request_builder = self
|
||||
.cloud_client
|
||||
.request(method, url)
|
||||
.header("client-version", CLIENT_API_VERSION)
|
||||
.bearer_auth(access_token);
|
||||
Ok(request_builder)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,10 +59,12 @@ where
|
|||
request_id
|
||||
});
|
||||
|
||||
let span = match get_payload_size(&req) {
|
||||
Some(size) => span!(Level::INFO, "request", request_id = %request_id, payload_size = size),
|
||||
None => span!(Level::INFO, "request", request_id = %request_id),
|
||||
};
|
||||
let client_info = get_client_info(&req);
|
||||
let span = span!(Level::INFO, "request",
|
||||
request_id = %request_id,
|
||||
client_version = client_info.client_version,
|
||||
payload_size = client_info.payload_size
|
||||
);
|
||||
|
||||
let fut = self.service.call(req);
|
||||
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> {
|
||||
req
|
||||
#[inline]
|
||||
fn get_client_info(req: &ServiceRequest) -> ClientInfo {
|
||||
let payload_size = req
|
||||
.headers()
|
||||
.get("content-length")
|
||||
.and_then(|val| val.to_str().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