pub struct EndpointTelemetryLayer { /* private fields */ }
Expand description
Emit telemetry about the status of HTTP transactions.
This layer can be used with services that deal with http::Request
and http::Response
, and wraps them to provide
telemetry about the status of an HTTP “transaction”: a full round-trip of request and response.
§Metrics
The following metrics are emitted:
network_http_requests_failed_total
: The total number of HTTP requests that failed with a status code of 400, 403, or 413.network_http_requests_success_total
: The total number of successful HTTP requests. (any response with a non-4xx/5xx status code)network_http_requests_success_sent_bytes_total
: The total number of body bytes sent in successful HTTP requests. (see note below on how this is calculated)network_http_requests_errors_total
: The total number of HTTP requests that had an error, either during the sending of the request or in the response. This is further broken down by theerror_type
label.- For all responses with a status code greater than 400,
error_type
will beclient_error
andcode
will be a stringified version of the status code. - When there is an error during the sending of the request,
error_type
will besend_failed
.
- For all responses with a status code greater than 400,
All metrics are emitted with two base tags:
domain
: The full domain of the request, including scheme and port, but excluding any credentials.endpoint
: The endpoint name, which is derived from the URI path by default but can be customized. (SeeEndpointTelemetryLayer::with_endpoint_name_fn
for information on customization and how the endpoint name, overall, is sanitized.)
§Success bytes calculation
We calculate the number of bytes sent by examining the body length itself, which is done via Body::size_hint
.
This requires that an exact body size is known, which is not always the case. If the body size is not known, this
metric will not be emitted on a successful response.
For common body types, like FrozenChunkedBytesBuffer
, the size
hint is always exact and so this functionality should work as intended.
Implementations§
Source§impl EndpointTelemetryLayer
impl EndpointTelemetryLayer
Sourcepub fn with_metrics_builder(self, builder: MetricsBuilder) -> Self
pub fn with_metrics_builder(self, builder: MetricsBuilder) -> Self
Create a new EndpointTelemetryLayer
with the given ComponentContext
.
The component context is used when creating metrics, which ensures they are tagged in a consistent way that attributes the metrics to the component issuing the HTTP requests.
Sourcepub fn with_endpoint_name_fn<F>(self, endpoint_name_fn: F) -> Self
pub fn with_endpoint_name_fn<F>(self, endpoint_name_fn: F) -> Self
Sets the function used to extract the “endpoint name” from a URI.
The value returned by this function will be sanitized to ensure it can be used as a tag value, and is limited to: ASCII alphanumerics, hyphens, underscores, slashes, and periods. Any non-conforming character will be replaced with an underscore. Characters will be converted to lowercase.
The value returned by this function is also cached for the given URI, and so the function should not rely on non-deterministic behavior, or state, that could change the generated endpoint name for subsequent calls with the same input URI.
Trait Implementations§
Source§impl Clone for EndpointTelemetryLayer
impl Clone for EndpointTelemetryLayer
Source§fn clone(&self) -> EndpointTelemetryLayer
fn clone(&self) -> EndpointTelemetryLayer
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Default for EndpointTelemetryLayer
impl Default for EndpointTelemetryLayer
Source§fn default() -> EndpointTelemetryLayer
fn default() -> EndpointTelemetryLayer
Auto Trait Implementations§
impl Freeze for EndpointTelemetryLayer
impl !RefUnwindSafe for EndpointTelemetryLayer
impl Send for EndpointTelemetryLayer
impl Sync for EndpointTelemetryLayer
impl Unpin for EndpointTelemetryLayer
impl !UnwindSafe for EndpointTelemetryLayer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> Track for T
impl<T> Track for T
Source§fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self>
fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self>
Tracked
wrapper. Read moreSource§fn in_current_allocation_group(self) -> Tracked<Self>
fn in_current_allocation_group(self) -> Tracked<Self>
Tracked
wrapper. Read more