From e110e6cf8dfbcd0c4741a09b99bef5a5a9c07f13 Mon Sep 17 00:00:00 2001 From: Luca Palmieri Date: Wed, 28 Apr 2021 21:23:53 +0100 Subject: [PATCH] Add error details. --- src/root_span_builder.rs | 7 +++++++ src/root_span_macro.rs | 3 +++ 2 files changed, 10 insertions(+) diff --git a/src/root_span_builder.rs b/src/root_span_builder.rs index da39a3fcd..5b9a39156 100644 --- a/src/root_span_builder.rs +++ b/src/root_span_builder.rs @@ -24,6 +24,8 @@ pub trait RootSpanBuilder { /// - Request path (`http.target`); /// - Status code (`http.status_code`); /// - [Request id](crate::RequestId) (`request_id`); +/// - `Display` (`exception.message`) and `Debug` (`exception.details`) representations of the error, if there was an error; +/// - [Request id](crate::RequestId) (`request_id`); /// - [OpenTelemetry trace identifier](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/overview.md#spancontext) (`trace_id`). Empty if the feature is not enabled; /// - OpenTelemetry span kind, set to `server` (`otel.kind`). /// @@ -45,6 +47,11 @@ impl RootSpanBuilder for DefaultRootSpanBuilder { } Err(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)); let status_code = response_error.status_code(); span.record("http.status_code", &status_code.as_u16()); diff --git a/src/root_span_macro.rs b/src/root_span_macro.rs index db6217e50..2b4ee67b0 100644 --- a/src/root_span_macro.rs +++ b/src/root_span_macro.rs @@ -90,6 +90,9 @@ macro_rules! root_span { otel.status_code = $crate::root_span_macro::private::tracing::field::Empty, trace_id = $crate::root_span_macro::private::tracing::field::Empty, request_id = %request_id, + exception.message = $crate::root_span_macro::private::tracing::field::Empty, + // Not proper OpenTelemetry, but their terminology is fairly exception-centric + exception.details = $crate::root_span_macro::private::tracing::field::Empty, $($field)* ); std::mem::drop(connection_info);