From e1b272ec4c8f2009e1eafeac920ac52071c709b9 Mon Sep 17 00:00:00 2001 From: Riley Date: Tue, 21 Sep 2021 03:33:32 -0500 Subject: [PATCH] Tracing error workaround (#38) * Allow root_span to wrap the full middlware chain, not just the output future * Build error string outside of span.record This is a workaround for https://github.com/tokio-rs/tracing/issues/1565 * Reference issue being worked-around as comment --- src/root_span_builder.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/root_span_builder.rs b/src/root_span_builder.rs index b14919187..58699304b 100644 --- a/src/root_span_builder.rs +++ b/src/root_span_builder.rs @@ -56,11 +56,13 @@ impl RootSpanBuilder for DefaultRootSpanBuilder { fn handle_error(span: Span, error: &actix_web::Error) { let response_error = error.as_response_error(); - span.record( - "exception.message", - &tracing::field::display(response_error), - ); - span.record("exception.details", &tracing::field::debug(response_error)); + + // pre-formatting errors is a workaround for https://github.com/tokio-rs/tracing/issues/1565 + let display = format!("{}", response_error); + let debug = format!("{:?}", response_error); + span.record("exception.message", &tracing::field::display(display)); + span.record("exception.details", &tracing::field::display(debug)); + let status_code = response_error.status_code(); span.record("http.status_code", &status_code.as_u16());