Skip to content
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- The minium supported Rust version was bumped to **1.46.0** due to requirements from dependencies.

**Fixes**:

- Honor the `attach_stacktrace` option correctly when capturing errors.

## 0.22.0

**Breaking Changes**:
Expand Down
8 changes: 7 additions & 1 deletion sentry-backtrace/src/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Integration for AttachStacktraceIntegration {
mut event: Event<'static>,
options: &ClientOptions,
) -> Option<Event<'static>> {
if options.attach_stacktrace && event.exception.is_empty() {
if options.attach_stacktrace && !has_stacktrace(&event) {
let thread = current_thread(true);
if thread.stacktrace.is_some() {
event.threads.values.push(thread);
Expand All @@ -83,6 +83,12 @@ impl Integration for AttachStacktraceIntegration {
}
}

fn has_stacktrace(event: &Event) -> bool {
event.stacktrace.is_some()
|| event.exception.iter().any(|exc| exc.stacktrace.is_some())
|| event.threads.iter().any(|thrd| thrd.stacktrace.is_some())
}

/// Captures information about the current thread.
///
/// If `with_stack` is set to `true` the current stacktrace is
Expand Down
35 changes: 35 additions & 0 deletions sentry/tests/test_basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,38 @@ fn test_reentrant_configure_scope() {
// well, the "outer" `configure_scope` wins
assert_eq!(events[0].tags["which_scope"], "scope1");
}

#[test]
fn test_attached_stacktrace() {
use log_ as log;

let logger = sentry_log::SentryLogger::new();

log::set_boxed_logger(Box::new(logger))
.map(|()| log::set_max_level(log::LevelFilter::Info))
.unwrap();

let options = sentry::apply_defaults(sentry::ClientOptions {
attach_stacktrace: true,
..Default::default()
});
let events = sentry::test::with_captured_events_options(
|| {
let error = "thisisnotanumber".parse::<u32>().unwrap_err();
sentry::capture_error(&error);

sentry::capture_message("some kind of message", sentry::Level::Info);

log::error!("Shit's on fire yo");
},
options,
);

assert_eq!(events.len(), 3);

let stacktraces: Vec<_> = events
.into_iter()
.flat_map(|ev| ev.threads.into_iter().filter_map(|thrd| thrd.stacktrace))
.collect();
assert_eq!(stacktraces.len(), 3);
}