diff --git a/Cargo.toml b/Cargo.toml index 6985ae2..8712c54 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,6 +41,7 @@ serde_repr = "0.1" strum = "0.20" strum_macros = "0.20" tokio = { version = "1", default-features = false, features = [ "time", "macros", "parking_lot" ] } +tracing = { version = "0.1", optional = true } [dev-dependencies] colored = "2" diff --git a/README.md b/README.md index c005477..37cc14a 100644 --- a/README.md +++ b/README.md @@ -71,12 +71,28 @@ Output: 9) Irelia 46465 (5) 10) Vladimir 37176 (5) ``` +### Feature Flags -### Nightly vs Stable +#### Nightly vs Stable -Enable the `nightly` feature to use nightly-only functionality. Mainly enables +Enable the `nightly` feature to use nightly-only functionality. This enables [nightly optimizations in the `parking_lot` crate](https://github.com/Amanieu/parking_lot#nightly-vs-stable). -Also required for running async integration tests. + +```toml +riven = { version = "...", features = [ "nightly" ] } +``` + +#### rustls + +Riven uses [reqwest](https://github.com/seanmonstar/reqwest) for making requests. By default, reqwest uses the native TLS library. +If you prefer using [rustls](https://github.com/ctz/rustls) you can do so by turning off the Riven default features +and specifying the `rustls-tls` feature: + +```toml +riven = { version = "...", default-features = false, features = [ "rustls-tls" ] } +``` + +Riven is additionally able to produce [tracing](https://docs.rs/tracing) spans for requests if the `tracing` feature is enabled. This feature is disabled by default. ### Docs diff --git a/src/req/regional_requester.rs b/src/req/regional_requester.rs index af3d513..df47c9a 100644 --- a/src/req/regional_requester.rs +++ b/src/req/regional_requester.rs @@ -3,12 +3,14 @@ use std::sync::Arc; use log; use reqwest::{ StatusCode, RequestBuilder }; +#[cfg(feature = "tracing")] +use tracing::Instrument; -use crate::Result; -use crate::ResponseInfo; -use crate::RiotApiError; -use crate::RiotApiConfig; use crate::util::InsertOnlyCHashMap; +use crate::ResponseInfo; +use crate::Result; +use crate::RiotApiConfig; +use crate::RiotApiError; use super::RateLimit; use super::RateLimitType; @@ -46,11 +48,20 @@ impl RegionalRequester { .get_or_insert_with(method_id, || RateLimit::new(RateLimitType::Method)); // Rate limit. - RateLimit::acquire_both(&self.app_rate_limit, &*method_rate_limit).await; + let rate_limit = RateLimit::acquire_both(&self.app_rate_limit, &*method_rate_limit); + #[cfg(feature = "tracing")] + let rate_limit = rate_limit.instrument(tracing::info_span!("rate_limit")); + rate_limit.await; // Send request. - let request_clone = request.try_clone().expect("Failed to clone request."); - let response = request_clone.send().await + let request_clone = request + .try_clone() + .expect("Failed to clone request.") + .send(); + #[cfg(feature = "tracing")] + let request_clone = request_clone.instrument(tracing::info_span!("request")); + let response = request_clone + .await .map_err(|e| RiotApiError::new(e, retries, None, None))?; // Maybe update rate limits (based on response headers). diff --git a/srcgen/endpoints.rs.dt b/srcgen/endpoints.rs.dt index 50233f0..d90eddc 100644 --- a/srcgen/endpoints.rs.dt +++ b/srcgen/endpoints.rs.dt @@ -13,6 +13,8 @@ use crate::models::*; use std::future::Future; use std::vec::Vec; +#[cfg(feature="tracing")] +use tracing::Instrument; use reqwest::Method; use crate::Result; @@ -197,7 +199,14 @@ impl<'a> {{= endpoint }}<'a> { {{? bodyType }} let request = request.body(serde_json::ser::to_vec(body).unwrap()); {{?}} - self.base.execute{{= hasReturn ? (returnOptional ? '_opt' : '_val') : '' }}{{= returnTypeTurbofish }}("{{= operationId }}", route_str, request) + let future = self + .base + .execute{{= hasReturn ? (returnOptional ? '_opt' : '_val') : '' }}{{= returnTypeTurbofish }}("{{= operationId }}", route_str, request); + + #[cfg(feature = "tracing")] + let future = future.instrument(tracing::info_span!("{{= operationId }}")); + + future } {{