1
1
use std:: collections:: BTreeMap ;
2
2
use std:: error:: Error ;
3
3
4
- use sentry_core:: protocol:: { Event , Exception , Mechanism , Thread , Value } ;
4
+ use sentry_core:: protocol:: { Event , Exception , Mechanism , Value } ;
5
5
use sentry_core:: { event_from_error, Breadcrumb , Level , TransactionOrSpan } ;
6
6
use tracing_core:: field:: { Field , Visit } ;
7
7
use tracing_core:: Subscriber ;
@@ -21,6 +21,7 @@ fn convert_tracing_level(level: &tracing_core::Level) -> Level {
21
21
}
22
22
}
23
23
24
+ #[ allow( unused) ]
24
25
fn level_to_exception_type ( level : & tracing_core:: Level ) -> & ' static str {
25
26
match * level {
26
27
tracing_core:: Level :: TRACE => "tracing::trace!" ,
@@ -248,41 +249,38 @@ where
248
249
// proper grouping and issue metadata generation. tracing_core::Record does not contain sufficient
249
250
// information for this. However, it may contain a serialized error which we can parse to emit
250
251
// an exception record.
252
+ #[ allow( unused_mut) ]
251
253
let ( mut message, visitor) = extract_event_data_with_context ( event, ctx. into ( ) ) ;
252
254
let FieldVisitor {
253
255
mut exceptions,
254
256
mut json_values,
255
257
} = visitor;
256
258
257
- // If there are both a message and an exception, then add the message as synthetic wrapper
258
- // around the exception to support proper grouping. If configured, also add the current stack
259
- // trace to this exception directly, since it points to the place where the exception is
260
- // captured.
259
+ // If there are a message, an exception, and we are capturing stack traces, then add the message
260
+ // as synthetic wrapper around the exception to support proper grouping. The stack trace to
261
+ // attach is the current one, since it points to the place where the exception is captured.
262
+ // We should only do this if we're capturing stack traces, otherwise the issue title will be `<unknown>`
263
+ // as Sentry will attempt to use missing stack trace to determine the title.
264
+ #[ cfg( feature = "backtrace" ) ]
261
265
if !exceptions. is_empty ( ) && message. is_some ( ) {
262
- #[ allow( unused_mut) ]
263
- let mut thread = Thread :: default ( ) ;
264
-
265
- #[ cfg( feature = "backtrace" ) ]
266
266
if let Some ( client) = sentry_core:: Hub :: current ( ) . client ( ) {
267
267
if client. options ( ) . attach_stacktrace {
268
- thread = sentry_backtrace:: current_thread ( true ) ;
268
+ let thread = sentry_backtrace:: current_thread ( true ) ;
269
+ let exception = Exception {
270
+ ty : level_to_exception_type ( event. metadata ( ) . level ( ) ) . to_owned ( ) ,
271
+ value : message. take ( ) ,
272
+ module : event. metadata ( ) . module_path ( ) . map ( str:: to_owned) ,
273
+ stacktrace : thread. stacktrace ,
274
+ raw_stacktrace : thread. raw_stacktrace ,
275
+ thread_id : thread. id ,
276
+ mechanism : Some ( Mechanism {
277
+ synthetic : Some ( true ) ,
278
+ ..Mechanism :: default ( )
279
+ } ) ,
280
+ } ;
281
+ exceptions. push ( exception)
269
282
}
270
283
}
271
-
272
- let exception = Exception {
273
- ty : level_to_exception_type ( event. metadata ( ) . level ( ) ) . to_owned ( ) ,
274
- value : message. take ( ) ,
275
- module : event. metadata ( ) . module_path ( ) . map ( str:: to_owned) ,
276
- stacktrace : thread. stacktrace ,
277
- raw_stacktrace : thread. raw_stacktrace ,
278
- thread_id : thread. id ,
279
- mechanism : Some ( Mechanism {
280
- synthetic : Some ( true ) ,
281
- ..Mechanism :: default ( )
282
- } ) ,
283
- } ;
284
-
285
- exceptions. push ( exception) ;
286
284
}
287
285
288
286
if let Some ( exception) = exceptions. last_mut ( ) {
0 commit comments