tower-rs / tower-http

HTTP specific Tower utilities.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add ability to customize span names for TraceLayer

horseinthesky opened this issue · comments

  • [ x] I have looked for existing issues (including closed) about this

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.