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
impl ClientCall
Sourcepub fn start(info: &ClientRequestInfo<'_>) -> ClientCall
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.
Sourcepub fn without_metrics(self) -> Self
pub fn without_metrics(self) -> Self
Don’t record http.client.request.duration for this request.
Sourcepub fn inject_trace_context(&self, headers: &mut HeaderMap)
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.
Sourcepub fn finish(self, status: StatusCode, version: Version)
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.