Skip to content

Add ability to customize span names for TraceLayer #469

@horseinthesky

Description

@horseinthesky
  • [ 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions