@@ -322,21 +322,36 @@ def stacktrace_from_traceback(tb, with_locals=True):
322322 return {"frames" : [frame_from_traceback (tb , with_locals ) for tb in iter_stacks (tb )]}
323323
324324
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+
326338 return {
327339 "module" : get_type_module (exc_type ),
328340 "type" : get_type_name (exc_type ),
329341 "value" : safe_str (exc_value ),
330342 "stacktrace" : stacktrace_from_traceback (tb , with_locals ),
343+ "mechanism" : mechanism ,
331344 }
332345
333346
334- def exceptions_from_error_tuple (exc_info , with_locals = True ):
347+ def exceptions_from_error_tuple (exc_info , with_locals = True , mechanism = None ):
335348 exc_type , exc_value , tb = exc_info
336349 rv = []
337350 while exc_type is not None :
338351 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+ )
340355 )
341356 cause = getattr (exc_value , "__cause__" , None )
342357 if cause is None :
@@ -414,13 +429,15 @@ def exc_info_from_error(error):
414429 return exc_type , exc_value , tb
415430
416431
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 ):
418433 exc_info = exc_info_from_error (exc_info )
419434 hint = event_hint_with_exc_info (exc_info )
420435 return (
421436 {
422437 "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+ },
424441 },
425442 hint ,
426443 )
0 commit comments