LukeMathWalker/tracing-actix-web

Compile errors with tracing v0.1.35

nsclass opened this issue · 4 comments

v0.7.1 has following compile errors with tracing v0.1.35.

   Compiling tracing-actix-web v0.7.1
error[E0308]: mismatched types
    --> .cargo/registry/src/github.com-1ecc6299db9ec823/tracing-actix-web-0.7.1/src/root_span_builder.rs:52:53
     |
52   |                     span.record("http.status_code", code);
     |                          ------                     ^^^^
     |                          |                          |
     |                          |                          expected reference, found `i32`
     |                          |                          help: consider borrowing here: `&code`
     |                          arguments to this function are incorrect
     |
     = note: expected reference `&_`
                     found type `i32`
note: associated function defined here
    --> .cargo/registry/src/github.com-1ecc6299db9ec823/tracing-0.1.35/src/span.rs:1194:12
     |
1194 |     pub fn record<Q: ?Sized, V>(&self, field: &Q, value: &V) -> &Self
     |            ^^^^^^

error[E0277]: the size for values of type `str` cannot be known at compilation time
    --> .cargo/registry/src/github.com-1ecc6299db9ec823/tracing-actix-web-0.7.1/src/root_span_builder.rs:53:26
     |
53   |                     span.record("otel.status_code", "OK");
     |                          ^^^^^^ doesn't have a size known at compile-time
     |
     = help: the trait `std::marker::Sized` is not implemented for `str`
note: required by a bound in `Span::record`
    --> .cargo/registry/src/github.com-1ecc6299db9ec823/tracing-0.1.35/src/span.rs:1194:30
     |
1194 |     pub fn record<Q: ?Sized, V>(&self, field: &Q, value: &V) -> &Self
     |                              ^ required by this bound in `Span::record`

error[E0308]: mismatched types
    --> .cargo/registry/src/github.com-1ecc6299db9ec823/tracing-actix-web-0.7.1/src/root_span_builder.rs:72:37
     |
72   |     span.record("http.status_code", code);
     |          ------                     ^^^^
     |          |                          |
     |          |                          expected reference, found `i32`
     |          |                          help: consider borrowing here: `&code`
     |          arguments to this function are incorrect
     |
     = note: expected reference `&_`
                     found type `i32`
note: associated function defined here
    --> .cargo/registry/src/github.com-1ecc6299db9ec823/tracing-0.1.35/src/span.rs:1194:12
     |
1194 |     pub fn record<Q: ?Sized, V>(&self, field: &Q, value: &V) -> &Self
     |            ^^^^^^

error[E0277]: the size for values of type `str` cannot be known at compilation time
    --> .cargo/registry/src/github.com-1ecc6299db9ec823/tracing-actix-web-0.7.1/src/root_span_builder.rs:75:14
     |
75   |         span.record("otel.status_code", "OK");
     |              ^^^^^^ doesn't have a size known at compile-time
     |
     = help: the trait `std::marker::Sized` is not implemented for `str`
note: required by a bound in `Span::record`
    --> .cargo/registry/src/github.com-1ecc6299db9ec823/tracing-0.1.35/src/span.rs:1194:30
     |
1194 |     pub fn record<Q: ?Sized, V>(&self, field: &Q, value: &V) -> &Self
     |                              ^ required by this bound in `Span::record`

error[E0277]: the size for values of type `str` cannot be known at compilation time
    --> .cargo/registry/src/github.com-1ecc6299db9ec823/tracing-actix-web-0.7.1/src/root_span_builder.rs:77:14
     |
77   |         span.record("otel.status_code", "ERROR");
     |              ^^^^^^ doesn't have a size known at compile-time
     |
     = help: the trait `std::marker::Sized` is not implemented for `str`
note: required by a bound in `Span::record`
    --> .cargo/registry/src/github.com-1ecc6299db9ec823/tracing-0.1.35/src/span.rs:1194:30
     |
1194 |     pub fn record<Q: ?Sized, V>(&self, field: &Q, value: &V) -> &Self
     |                              ^ required by this bound in `Span::record`

I'm afraid I can't reproduce the issue.

It might be wrong but I can see the difference between v0.6.2 and v0.7.1 in root_span_builder.rs. It used to pass the code in reference(span.record("http.status_code", &code);) but v0.7.1 is passing as a value.

v0.6.2

    fn on_request_end<B>(span: Span, outcome: &Result<ServiceResponse<B>, Error>) {
        match &outcome {
            Ok(response) => {
                if let Some(error) = response.response().error() {
                    // use the status code already constructed for the outgoing HTTP response
                    handle_error(span, response.status(), error.as_response_error());
                } else {
                    let code: i32 = response.response().status().as_u16().into();
                    span.record("http.status_code", &code);
                    span.record("otel.status_code", &"OK");
                }
            }
            Err(error) => {
                let response_error = error.as_response_error();
                handle_error(span, response_error.status_code(), response_error);
            }
        };
    }

v0.7.1

    fn on_request_end<B: MessageBody>(span: Span, outcome: &Result<ServiceResponse<B>, Error>) {
        match &outcome {
            Ok(response) => {
                if let Some(error) = response.response().error() {
                    // use the status code already constructed for the outgoing HTTP response
                    handle_error(span, response.status(), error.as_response_error());
                } else {
                    let code: i32 = response.response().status().as_u16().into();
                    span.record("http.status_code", code);
                    span.record("otel.status_code", "OK");
                }
            }
            Err(error) => {
                let response_error = error.as_response_error();
                handle_error(span, response_error.status_code(), response_error);
            }
        };
    }

There is indeed a difference there. I managed to reproduce the issue by pinning tracing to 0.1.35. It doesn't happen on 0.1.36 or 0.1.37.
It smells like a regression in that version of tracing, but I'll bump the minimum required version to make sure other people don't experience this issue.

Released the fix in 0.7.2 👍🏻