Crate tower_http_tracing

Crate tower_http_tracing 

Source
Expand description

Tower tracing middleware to annotate every HTTP request with tracing’s span.

§Span creation

Use macro to declare function that creates desirable span

§Example

Below is illustration of how to initialize request layer for passing into your service

use std::net::IpAddr;

use tower_http_tracing::{http, HttpRequestLayer};

#[derive(Clone)]
pub struct MyContext;

impl tower_http_tracing::LayerContext for MyContext {
    const INSPECT_HEADERS: &'static [&'static http::HeaderName] = &[&http::header::FORWARDED];

    //Logic to extract client ip has to be written by user
    //You can use utilities in separate crate to design this logic:
    //https://docs.rs/http-ip/latest/http_ip/
    fn extract_client_ip(&self, span: &tracing::Span, parts: &http::request::Parts) -> Option<IpAddr> {
        None
    }
}
tower_http_tracing::make_request_spanner!(make_my_request_span("my_request", tracing::Level::INFO));
let layer = HttpRequestLayer::new(make_my_request_span, MyContext);
//Use above layer in your service

§Features

  • opentelemetry - Enables integration with opentelemetry to propagate context from requests and into responses
  • datadog - Enables integration with specialized datadog tracing layer to propagate context from requests and into responses

Re-exports§

pub use http;
pub use tracing;

Modules§

datadog
datadog integration
opentelemetry
opentelemetry integration

Macros§

make_request_spanner
Declares fn function compatible with MakeSpan using provided parameters

Structs§

HttpRequestLayer
Tower layer
HttpRequestService
Tower service to annotate requests with span
Noop
Default context that does nothing by default
RequestId
Request’s id
RequestInfo
Request’s information
RequestSpan
Request’s span information
ResponseFut
Middleware’s response future

Enums§

Protocol
Possible request protocol

Constants§

REQUEST_ID
RequestId’s header name

Traits§

LayerContext
HttpRequestLayer context interface

Type Aliases§

MakeSpan
Alias to function signature required to create span