diff --git a/src/layer.rs b/src/layer.rs index 1171ac8..164f4a3 100644 --- a/src/layer.rs +++ b/src/layer.rs @@ -35,6 +35,7 @@ const SPAN_EVENT_COUNT_FIELD: &str = "otel.tracing_event_count"; const EVENT_EXCEPTION_NAME: &str = "exception"; const FIELD_EXCEPTION_MESSAGE: &str = "exception.message"; const FIELD_EXCEPTION_STACKTRACE: &str = "exception.stacktrace"; +const FIELD_EXCEPTION_TYPE: &str = "exception.type"; /// An [OpenTelemetry] propagation layer for use in a project that uses /// [tracing]. @@ -287,6 +288,9 @@ impl field::Visit for SpanEventVisitor<'_, '_> { self.event_builder .attributes .push(KeyValue::new(FIELD_EXCEPTION_MESSAGE, format!("{value:?}"))); + self.event_builder + .attributes + .push(KeyValue::new(FIELD_EXCEPTION_TYPE, "Unknown")); } else { self.event_builder .attributes @@ -326,6 +330,9 @@ impl field::Visit for SpanEventVisitor<'_, '_> { self.event_builder .attributes .push(KeyValue::new(FIELD_EXCEPTION_MESSAGE, format!("{value:?}"))); + self.event_builder + .attributes + .push(KeyValue::new(FIELD_EXCEPTION_TYPE, "Unknown")); } else { self.event_builder .attributes @@ -367,6 +374,9 @@ impl field::Visit for SpanEventVisitor<'_, '_> { Key::new(FIELD_EXCEPTION_MESSAGE), Value::String(StringValue::from(error_msg.clone())), )); + self.event_builder + .attributes + .push(KeyValue::new(Key::new(FIELD_EXCEPTION_TYPE), "Unkonwn")); // NOTE: This is actually not the stacktrace of the exception. This is // the "source chain". It represents the heirarchy of errors from the @@ -391,6 +401,7 @@ impl field::Visit for SpanEventVisitor<'_, '_> { FIELD_EXCEPTION_MESSAGE, Value::String(error_msg.clone().into()), )); + attributes.push(KeyValue::new(FIELD_EXCEPTION_TYPE, "Unknown")); // NOTE: This is actually not the stacktrace of the exception. This is // the "source chain". It represents the heirarchy of errors from the @@ -548,6 +559,7 @@ impl field::Visit for SpanAttributeVisitor<'_> { Key::new(FIELD_EXCEPTION_MESSAGE), Value::from(error_msg.clone()), )); + self.record(KeyValue::new(Key::new(FIELD_EXCEPTION_TYPE), "Unknown")); // NOTE: This is actually not the stacktrace of the exception. This is // the "source chain". It represents the heirarchy of errors from the @@ -1737,6 +1749,7 @@ mod tests { ); assert_eq!(attributes[FIELD_EXCEPTION_MESSAGE].as_str(), "user error"); + assert_eq!(attributes[FIELD_EXCEPTION_TYPE].as_str(), "Unknown"); assert_eq!( attributes[FIELD_EXCEPTION_STACKTRACE], Value::Array( @@ -1881,6 +1894,7 @@ mod tests { ); assert_eq!(attributes[FIELD_EXCEPTION_MESSAGE].as_str(), "user error"); + assert_eq!(attributes[FIELD_EXCEPTION_TYPE].as_str(), "Unknown"); assert_eq!( attributes[FIELD_EXCEPTION_STACKTRACE], Value::Array( @@ -2137,6 +2151,7 @@ mod tests { let attributes = tracer.attributes(); assert_eq!(attributes[FIELD_EXCEPTION_MESSAGE].as_str(), "user error"); + assert_eq!(attributes[FIELD_EXCEPTION_TYPE].as_str(), "Unknown"); assert_eq!( attributes[FIELD_EXCEPTION_STACKTRACE], Value::Array( @@ -2184,6 +2199,7 @@ mod tests { let attributes = tracer.attributes(); assert_eq!(attributes[FIELD_EXCEPTION_MESSAGE].as_str(), "user error"); + assert_eq!(attributes[FIELD_EXCEPTION_TYPE].as_str(), "Unknown"); assert_eq!( attributes[FIELD_EXCEPTION_STACKTRACE], Value::Array( diff --git a/src/layer/filtered.rs b/src/layer/filtered.rs index 131cfb4..6844e3b 100644 --- a/src/layer/filtered.rs +++ b/src/layer/filtered.rs @@ -144,8 +144,10 @@ where OtelDataState::Builder { builder, parent_cx: _, + status, } => { builder.attributes.get_or_insert(Vec::new()).push(key_value); + builder.status = status.clone(); } OtelDataState::Context { current_cx } => { let span = current_cx.span();