EndpointTelemetryLayer

Struct EndpointTelemetryLayer 

Source
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 the error_type label.
    • For all responses with a status code greater than 400, error_type will be client_error and code will be a stringified version of the status code.
    • When there is an error during the sending of the request, error_type will be send_failed.

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. (See EndpointTelemetryLayer::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

Source

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.

Source

pub fn with_endpoint_name_fn<F>(self, endpoint_name_fn: F) -> Self
where F: Fn(&Uri) -> Option<MetaString> + Send + Sync + 'static,

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

Source§

fn clone(&self) -> EndpointTelemetryLayer

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for EndpointTelemetryLayer

Source§

fn default() -> EndpointTelemetryLayer

Returns the “default value” for a type. Read more
Source§

impl<S> Layer<S> for EndpointTelemetryLayer

Source§

type Service = EndpointTelemetry<S>

The wrapped service
Source§

fn layer(&self, service: S) -> Self::Service

Wrap the given service with the middleware, returning a new service that has been decorated with the middleware.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> Track for T

Source§

fn track_allocations(self, token: AllocationGroupToken) -> Tracked<Self>

Instruments this type by attaching the given allocation group token, returning a Tracked wrapper. Read more
Source§

fn in_current_allocation_group(self) -> Tracked<Self>

Instruments this type by attaching the current allocation group, returning a Tracked wrapper. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,