@@ -322,21 +322,36 @@ def stacktrace_from_traceback(tb, with_locals=True):
322
322
return {"frames" : [frame_from_traceback (tb , with_locals ) for tb in iter_stacks (tb )]}
323
323
324
324
325
- def single_exception_from_error_tuple (exc_type , exc_value , tb , with_locals = True ):
325
+ def get_errno (exc_value ):
326
+ return getattr (exc_value , "errno" , None )
327
+
328
+
329
+ def single_exception_from_error_tuple (
330
+ exc_type , exc_value , tb , with_locals = True , mechanism = None
331
+ ):
332
+ errno = get_errno (exc_value )
333
+ if errno is not None :
334
+ mechanism = mechanism or {}
335
+ mechanism_meta = mechanism .setdefault ("meta" , {})
336
+ mechanism_meta .setdefault ("errno" , {"code" : errno })
337
+
326
338
return {
327
339
"module" : get_type_module (exc_type ),
328
340
"type" : get_type_name (exc_type ),
329
341
"value" : safe_str (exc_value ),
330
342
"stacktrace" : stacktrace_from_traceback (tb , with_locals ),
343
+ "mechanism" : mechanism ,
331
344
}
332
345
333
346
334
- def exceptions_from_error_tuple (exc_info , with_locals = True ):
347
+ def exceptions_from_error_tuple (exc_info , with_locals = True , mechanism = None ):
335
348
exc_type , exc_value , tb = exc_info
336
349
rv = []
337
350
while exc_type is not None :
338
351
rv .append (
339
- single_exception_from_error_tuple (exc_type , exc_value , tb , with_locals )
352
+ single_exception_from_error_tuple (
353
+ exc_type , exc_value , tb , with_locals , mechanism
354
+ )
340
355
)
341
356
cause = getattr (exc_value , "__cause__" , None )
342
357
if cause is None :
@@ -414,13 +429,15 @@ def exc_info_from_error(error):
414
429
return exc_type , exc_value , tb
415
430
416
431
417
- def event_from_exception (exc_info , with_locals = False , processors = None ):
432
+ def event_from_exception (exc_info , with_locals = False , processors = None , mechanism = None ):
418
433
exc_info = exc_info_from_error (exc_info )
419
434
hint = event_hint_with_exc_info (exc_info )
420
435
return (
421
436
{
422
437
"level" : "error" ,
423
- "exception" : {"values" : exceptions_from_error_tuple (exc_info , with_locals )},
438
+ "exception" : {
439
+ "values" : exceptions_from_error_tuple (exc_info , with_locals , mechanism )
440
+ },
424
441
},
425
442
hint ,
426
443
)
0 commit comments