Skip to main content

typeway_client/
tracing_interceptor.rs

1//! Built-in tracing support for the [`Client`](crate::Client).
2//!
3//! Enable request/response tracing by calling
4//! [`ClientConfig::enable_tracing`](crate::ClientConfig::enable_tracing) or
5//! by using the [`with_tracing`] convenience function.
6//!
7//! When tracing is enabled, every request logs the HTTP method, URL, response
8//! status, and elapsed duration at `DEBUG` level via the [`tracing`] crate.
9//!
10//! # Example
11//!
12//! ```
13//! use typeway_client::{ClientConfig, with_tracing};
14//!
15//! // Option 1: builder method
16//! let config = ClientConfig::default().enable_tracing();
17//!
18//! // Option 2: convenience function
19//! let config = with_tracing(ClientConfig::default());
20//! ```
21
22use crate::config::ClientConfig;
23
24/// Enable built-in tracing on the given [`ClientConfig`].
25///
26/// This is a convenience wrapper around
27/// [`ClientConfig::enable_tracing`](ClientConfig::enable_tracing) for use in
28/// a functional pipeline.
29///
30/// # Example
31///
32/// ```
33/// use typeway_client::{ClientConfig, RetryPolicy, with_tracing};
34///
35/// let config = with_tracing(
36///     ClientConfig::default()
37///         .retry_policy(RetryPolicy::none()),
38/// );
39/// ```
40pub fn with_tracing(config: ClientConfig) -> ClientConfig {
41    config.enable_tracing()
42}