Skip to content

Signature of the on_response closure #430

@zrll12

Description

@zrll12

The documents about trace layer gives the following example:

.on_response(|response: &Response<Body>, latency: Duration, _span: &Span| {
    tracing::debug!("response generated in {:?}", latency)
})

This will generate a error

expected closure signature `for<'a, 'b> fn(&'a Response<http_body::combinators::box_body::UnsyncBoxBody<axum::body::Bytes, axum::Error>>, Duration, &'b Span) -> _`
   found closure signature `for<'a, 'b> fn(&'a Response<Body>, Duration, &'b Span) -> _`

And could run if change to

.on_response(|response: &Response<http_body::combinators::UnsyncBoxBody<axum::body::Bytes, axum::Error>>, latency: Duration, _span: &Span| {
    //something
});

I wonder if there is a feature that make these two types compatible.

Also, is there a way to get the method and uri in the on_ response closure?

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