1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-02-23 10:53:02 +01:00

Add error details.

This commit is contained in:
Luca Palmieri 2021-04-28 21:23:53 +01:00
parent f6586edb85
commit e110e6cf8d
2 changed files with 10 additions and 0 deletions

View File

@ -24,6 +24,8 @@ pub trait RootSpanBuilder {
/// - Request path (`http.target`); /// - Request path (`http.target`);
/// - Status code (`http.status_code`); /// - Status code (`http.status_code`);
/// - [Request id](crate::RequestId) (`request_id`); /// - [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 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`). /// - OpenTelemetry span kind, set to `server` (`otel.kind`).
/// ///
@ -45,6 +47,11 @@ impl RootSpanBuilder for DefaultRootSpanBuilder {
} }
Err(error) => { Err(error) => {
let response_error = error.as_response_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(); let status_code = response_error.status_code();
span.record("http.status_code", &status_code.as_u16()); span.record("http.status_code", &status_code.as_u16());

View File

@ -90,6 +90,9 @@ macro_rules! root_span {
otel.status_code = $crate::root_span_macro::private::tracing::field::Empty, otel.status_code = $crate::root_span_macro::private::tracing::field::Empty,
trace_id = $crate::root_span_macro::private::tracing::field::Empty, trace_id = $crate::root_span_macro::private::tracing::field::Empty,
request_id = %request_id, 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)* $($field)*
); );
std::mem::drop(connection_info); std::mem::drop(connection_info);