/usr/lib/python2.7/dist-packages/aws_xray_sdk/core/models/throwable.py is in python-aws-xray-sdk 0.95-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | import copy
import os
import binascii
import logging
from ..utils.compat import string_types
log = logging.getLogger(__name__)
class Throwable(object):
"""
An object recording exception infomation under trace entity
`cause` section. The information includes the stack trace,
working directory and message from the original exception.
"""
def __init__(self, exception, stack, remote=False):
"""
:param Exception exception: the catched exception.
:param list stack: the formatted stack trace gathered
through `traceback` module.
:param bool remote: If False it means it's a client error
instead of a downstream service.
"""
self.id = binascii.b2a_hex(os.urandom(8)).decode('utf-8')
try:
message = str(exception)
# in case there is an exception cannot be converted to str
except Exception:
message = None
# do not record non-string exception message
if isinstance(message, string_types):
self.message = message
self.type = type(exception).__name__
self.remote = remote
try:
self._normalize_stack_trace(stack)
except Exception:
self.stack = None
log.warning("can not parse stack trace string, ignore stack field.")
if exception:
setattr(exception, '_recorded', True)
setattr(exception, '_cause_id', self.id)
def _normalize_stack_trace(self, stack):
if not stack:
return None
self.stack = []
for entry in stack:
path = entry[0]
line = entry[1]
label = entry[2]
if 'aws_xray_sdk/' in path:
continue
normalized = {}
normalized['path'] = os.path.basename(path).replace('\"', ' ').strip()
normalized['line'] = line
normalized['label'] = label.strip()
self.stack.append(normalized)
def __getstate__(self):
properties = copy.copy(self.__dict__)
if not self.stack:
del properties['stack']
return properties
|