tower-rs / tower-http

HTTP specific Tower utilities.
675 stars 156 forks source link

Add ability to customize span names for TraceLayer #469

Closed horseinthesky closed 6 months ago

horseinthesky commented 6 months ago

Feature Request

At the moment addition of TraceLayer provides you no ability to name your span

let app = Router::new()
    .route("/api/devices", get(devices))
    .layer(
        TraceLayer::new_for_http()
            .make_span_with(DefaultMakeSpan::new().include_headers(true)),
    )
    .route(
        "/metrics",
        get(|| async { "metrics" }),
    );

As the result all spans are named request.

Motivation

It would be nice see method+endpoint uri instead. Something like GET /api/devices. This would simplify working with spans on a collector side.

Proposal

I'm very new to Rust. If I'm not mistaken this is the place where request name code from https://github.com/tower-rs/tower-http/blob/main/tower-http/src/trace/make_span.rs#L84-L101

Not sure how to achieve this.