Skip to main content

Crate rlg_tower

Crate rlg_tower 

Source
Expand description

Tower middleware that emits structured rlg records for every HTTP request that passes through it.

Compatible with any service that satisfies tower::Service<http::Request<B>> — axum, tonic, hyper services, lambda_runtime, custom stacks.

§Example (axum)

ⓘ
use axum::{Router, routing::get};
use rlg::log_format::LogFormat;
use rlg::log_level::LogLevel;
use rlg_tower::RlgLayer;

let app: Router = Router::new()
    .route("/", get(|| async { "hello" }))
    .layer(
        RlgLayer::new()
            .level(LogLevel::INFO)
            .format(LogFormat::JSON)
            .header("x-request-id"),
    );

One record is emitted per response, with the following fields:

AttributeSource
component"rlg-tower" (override with .component(...))
description"<METHOD> <path> -> <status>"
http.methodrequest method
http.pathrequest URI path
http.statusresponse status code
http.latency_mswall-clock milliseconds from poll-ready to ready response
trace_id, span_idextracted from configured request headers (W3C / b3) if present

Structs§

RlgFuture
Future returned by RlgService::call.
RlgLayer
Tower [Layer] that wraps a service with rlg request logging.
RlgService
Service wrapper produced by RlgLayer.