Skip to main content

Module hyper

Module hyper 

Source
Expand description

Async hyper connection instrumentation helpers.

This module instruments hyper::client::conn::http1::SendRequest, hyper::client::conn::http2::SendRequest, and, with the hyper-client-legacy feature, hyper_util::client::legacy::Client.

§Example

use bytes::Bytes;
use http_body_util::Empty;
use hyper::{Request, header::HOST};
use hyper_util::rt::TokioIo;
use telemetry_rust::instrumentations::http::hyper::HyperSendRequestInstrument;
use tokio::net::TcpStream;

let stream = TcpStream::connect("127.0.0.1:3000").await?;
let io = TokioIo::new(stream);
let (send_request, connection) = hyper::client::conn::http1::handshake(io).await?;
tokio::spawn(async move {
    let _ = connection.await;
});

// Create an instrumented sender once and reuse it for requests on this connection.
let mut instrumented_sender = send_request.instrument();
let request = Request::builder()
    .uri("/health")
    .header(HOST, "127.0.0.1:3000")
    .body(Empty::<Bytes>::new())?;
let response = instrumented_sender.send_request(request).await?;

Re-exports§

pub use legacy_client::HyperLegacyClientInstrument;

Modules§

legacy_client
Async instrumentation helpers for hyper_util::client::legacy::Client. Async hyper-util legacy client instrumentation helpers.

Structs§

InstrumentedSendRequest
A reusable wrapper around hyper SendRequest that records client spans for each request sent through the connection.

Traits§

HyperSendRequestInstrument
A trait for creating instrumented hyper connection senders with OpenTelemetry tracing.