Skip to content

Commit f85dbb8

Browse files
authored
Fix: ensure transaction will have a name (#434)
1 parent 92be25b commit f85dbb8

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

sentry-tracing/src/layer.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,24 @@ where
166166
let op = span.name();
167167
let description = description.as_deref().unwrap_or("");
168168

169+
// Spans don't always have a description, this ensures our data is not empty,
170+
// therefore the Sentry UI will be a lot more valuable for navigating spans.
171+
let transaction_name = if description.is_empty() {
172+
let target = span.metadata().target();
173+
if target.is_empty() {
174+
op.to_string()
175+
} else {
176+
format!("{}::{}", target, op)
177+
}
178+
} else {
179+
description.to_string()
180+
};
181+
169182
let parent_sentry_span = sentry_core::configure_scope(|s| s.get_span());
170183
let sentry_span: sentry_core::TransactionOrSpan = match &parent_sentry_span {
171-
Some(parent) => parent.start_child(op, description).into(),
184+
Some(parent) => parent.start_child(op, &transaction_name).into(),
172185
None => {
173-
let ctx = sentry_core::TransactionContext::new(description, op);
186+
let ctx = sentry_core::TransactionContext::new(&transaction_name, op);
174187
sentry_core::start_transaction(ctx).into()
175188
}
176189
};

0 commit comments

Comments
 (0)