Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions src/layer/filtered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Comment on lines +147 to +150
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please double-check this for me. At the moment, the default branch if failing to build, because the status field isn't properly matched. I think I am doing the right thing here, but if I should rather ignore the status instead of setting it on the builder, please let me know and I will make an update.

}
OtelDataState::Context { current_cx } => {
let span = current_cx.span();
Expand Down