Add an example to the description and update docs

This commit is contained in:
Jeremy Wall 2023-02-04 10:27:57 -05:00
parent 2d714d3c45
commit ff34d0474c
2 changed files with 14 additions and 5 deletions

View File

@ -27,6 +27,15 @@ fn main() {
let service = ServiceBuilder::new()
// Make a trace layer where the chunks are bytes::Bytes
.layer(make_layer(|b: &bytes::Bytes| b.len() as u64));
// ... Use this service in a Tower Middleware stack.
// ... Use this service in a Tower middleware stack.
}
```
```
## Recorded Metrics
* http_request_counter The total count of all requests
* http_request_failure_counter The total count of all request failures
* http_request_size_bytes_hist A histogram of request size in bytes
* http_request_request_time_micros_hist A histogram of request time in microseconds
Each metric is faceted by `path`, `method`, and `host` for the request.

View File

@ -58,7 +58,7 @@ where
pub labels: Arc<Mutex<Vec<Label>>>,
/// The accumulator for the number of bytes on this request.
pub size: Arc<AtomicU64>,
/// The mapper function to extract the size from a chunk in [OnBodyChunk<B>],
/// The mapper function to extract the size in bytes from a chunk in [OnBodyChunk<B>],
pub chunk_len: Arc<F>,
_phantom: PhantomData<B>,
}
@ -82,7 +82,7 @@ where
F: Fn(&B) -> u64,
{
/// Construct a new [MetricsRecorder] using the installed [metrics::Recorder].
/// The function passed in is used to extract the size from the chunks in a
/// The function passed in is used to extract the size in bytes from the chunks in a
/// response for all [OnBodyChunk] calls.
pub fn new(f: F) -> Self {
Self {
@ -169,7 +169,7 @@ where
}
/// Construct a [TraceLayer] that will use an installed [metrics::Recorder] to record metrics per request.
/// The provided [Fn] is used to extract the size from the chunks in a
/// The provided [Fn] is used to extract the size in bytes from the chunks in a
/// response for all [OnBodyChunk] calls.
pub fn make_layer<B, F>(f: F) -> MetricsTraceLayer<B, F>
where