Skip to main content

ClientCall

Struct ClientCall 

Source
pub struct ClientCall { /* private fields */ }
Expand description

One outgoing HTTP request, recorded as HttpClientLayer records it: a client span, trace context for the request’s headers, and http.client.request.duration. For instrumenting an HTTP client that isn’t a tower service:

use http::{HeaderMap, Method, StatusCode, Version};
use oxtel_tower::{ClientCall, ClientRequestInfo};

let call = ClientCall::start(&ClientRequestInfo {
    method: &Method::GET,
    scheme: "https",
    server_address: Some("api.example"),
    server_port: None,
    path: "/items",
    protocol_version: Version::HTTP_11,
});
let mut headers = HeaderMap::new();
call.inject_trace_context(&mut headers);
// Send the request inside the span, so what it logs is part of it.
match call.span().in_scope(|| send(&headers)) {
    Ok(status) => call.finish(status, Version::HTTP_11),
    Err(_) => call.fail("connect"),
}

A call dropped without finish or fail, as when its future is cancelled, ends its span without a status and records no duration.

Implementations§

Source§

impl ClientCall

Source

pub fn start(info: &ClientRequestInfo<'_>) -> ClientCall

Starts the request’s span and its clock. Make the HttpClientLayer or call describe_metrics once first, so the duration is recorded in seconds with the conventions’ buckets.

Source

pub fn without_metrics(self) -> Self

Don’t record http.client.request.duration for this request.

Source

pub fn span(&self) -> &Span

The request’s span. Send the request inside it.

Source

pub fn inject_trace_context(&self, headers: &mut HeaderMap)

Adds W3C traceparent and tracestate to the request’s headers, so the server continues the trace: the client span’s context, or the caller’s when the span is filtered out.

Source

pub fn finish(self, status: StatusCode, version: Version)

The response came back: records its status and HTTP version, marks 4xx and 5xx as errors, and records the duration.

Source

pub fn fail(self, error_type: &str)

No response came back. error_type names what went wrong, with few enough values to be a metric label, such as timeout or connect.

Trait Implementations§

Source§

impl Debug for ClientCall

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<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