1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
use std::thread;
use sentry_core::protocol::{Event, Thread};
use sentry_core::{ClientOptions, Integration};
use crate::current_stacktrace;
use crate::process::process_event_stacktrace;
#[derive(Default)]
pub struct ProcessStacktraceIntegration;
impl ProcessStacktraceIntegration {
pub fn new() -> Self {
Self::default()
}
}
impl Integration for ProcessStacktraceIntegration {
fn name(&self) -> &'static str {
"process-stacktrace"
}
fn process_event(
&self,
mut event: Event<'static>,
options: &ClientOptions,
) -> Option<Event<'static>> {
for exc in &mut event.exception {
if let Some(ref mut stacktrace) = exc.stacktrace {
process_event_stacktrace(stacktrace, &options);
}
}
Some(event)
}
}
#[derive(Default)]
pub struct AttachStacktraceIntegration;
impl AttachStacktraceIntegration {
pub fn new() -> Self {
Self::default()
}
}
impl Integration for AttachStacktraceIntegration {
fn name(&self) -> &'static str {
"attach-stacktrace"
}
fn process_event(
&self,
mut event: Event<'static>,
options: &ClientOptions,
) -> Option<Event<'static>> {
if options.attach_stacktrace && event.exception.is_empty() {
let thread = current_thread(true);
if thread.stacktrace.is_some() {
event.threads.values.push(thread);
}
}
Some(event)
}
}
pub fn current_thread(with_stack: bool) -> Thread {
let thread_id: u64 = unsafe { std::mem::transmute(thread::current().id()) };
Thread {
id: Some(thread_id.to_string().into()),
name: thread::current().name().map(str::to_owned),
current: true,
stacktrace: if with_stack {
current_stacktrace()
} else {
None
},
..Default::default()
}
}