Skip to content

How to extract the template uri from a request #1096

@andylokandy

Description

@andylokandy

A low cardinality path is required for creating a opentelemetry trace span, which is usually a uri template like /v1/users/{user_id}. Is it possible to extract it from poem::Request?

On axum, it can be extracted like this:

fn get_request_span_name(req: &Request) -> String {
    let method = req.method().as_str();
    if let Some(target) = req.extensions().get::<MatchedPath>() {
        format!("{} {}", method, target.as_str())
    } else {
        method.to_string()
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions