mirror of
https://github.com/zaphar/tower-trace-metrics.git
synced 2025-07-22 20:09:54 -04:00
Add an example to the description and update docs
This commit is contained in:
parent
2d714d3c45
commit
ff34d0474c
13
README.md
13
README.md
@ -27,6 +27,15 @@ fn main() {
|
|||||||
let service = ServiceBuilder::new()
|
let service = ServiceBuilder::new()
|
||||||
// Make a trace layer where the chunks are bytes::Bytes
|
// Make a trace layer where the chunks are bytes::Bytes
|
||||||
.layer(make_layer(|b: &bytes::Bytes| b.len() as u64));
|
.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.
|
@ -58,7 +58,7 @@ where
|
|||||||
pub labels: Arc<Mutex<Vec<Label>>>,
|
pub labels: Arc<Mutex<Vec<Label>>>,
|
||||||
/// The accumulator for the number of bytes on this request.
|
/// The accumulator for the number of bytes on this request.
|
||||||
pub size: Arc<AtomicU64>,
|
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>,
|
pub chunk_len: Arc<F>,
|
||||||
_phantom: PhantomData<B>,
|
_phantom: PhantomData<B>,
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@ where
|
|||||||
F: Fn(&B) -> u64,
|
F: Fn(&B) -> u64,
|
||||||
{
|
{
|
||||||
/// Construct a new [MetricsRecorder] using the installed [metrics::Recorder].
|
/// 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.
|
/// response for all [OnBodyChunk] calls.
|
||||||
pub fn new(f: F) -> Self {
|
pub fn new(f: F) -> Self {
|
||||||
Self {
|
Self {
|
||||||
@ -169,7 +169,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Construct a [TraceLayer] that will use an installed [metrics::Recorder] to record metrics per request.
|
/// 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.
|
/// response for all [OnBodyChunk] calls.
|
||||||
pub fn make_layer<B, F>(f: F) -> MetricsTraceLayer<B, F>
|
pub fn make_layer<B, F>(f: F) -> MetricsTraceLayer<B, F>
|
||||||
where
|
where
|
||||||
|
Loading…
x
Reference in New Issue
Block a user