Skip to content

Commit 4660169

Browse files
lehmatMatti Lehmus
and
Matti Lehmus
authored
Implement PEP3134 to discover underlying problems with python3 (#355)
Co-authored-by: Matti Lehmus <[email protected]>
1 parent 5d99316 commit 4660169

File tree

5 files changed

+21
-15
lines changed

5 files changed

+21
-15
lines changed

aws_xray_sdk/core/async_recorder.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import time
2+
import six
23

34
from aws_xray_sdk.core.recorder import AWSXRayRecorder
45
from aws_xray_sdk.core.utils import stacktrace
@@ -81,10 +82,10 @@ async def record_subsegment_async(self, wrapped, instance, args, kwargs, name,
8182
try:
8283
return_value = await wrapped(*args, **kwargs)
8384
return return_value
84-
except Exception as e:
85-
exception = e
85+
except Exception as exc:
86+
exception = exc
8687
stack = stacktrace.get_stacktrace(limit=self._max_trace_back)
87-
raise
88+
six.raise_from(exc, exc)
8889
finally:
8990
# No-op if subsegment is `None` due to `LOG_ERROR`.
9091
if subsegment is not None:

aws_xray_sdk/core/patcher.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import re
77
import sys
88
import wrapt
9+
import six
910

1011
from aws_xray_sdk import global_sdk_config
1112
from .utils.compat import PY2, is_classmethod, is_instance_method
@@ -107,9 +108,9 @@ def patch(modules_to_patch, raise_errors=True, ignore_module_patterns=None):
107108
def _patch_module(module_to_patch, raise_errors=True):
108109
try:
109110
_patch(module_to_patch)
110-
except Exception:
111+
except Exception as exc:
111112
if raise_errors:
112-
raise
113+
six.raise_from(exc, exc)
113114
log.debug('failed to patch module %s', module_to_patch)
114115

115116

aws_xray_sdk/core/recorder.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import platform
66
import time
7+
import six
78

89
from aws_xray_sdk import global_sdk_config
910
from aws_xray_sdk.version import VERSION
@@ -435,10 +436,10 @@ def record_subsegment(self, wrapped, instance, args, kwargs, name,
435436
try:
436437
return_value = wrapped(*args, **kwargs)
437438
return return_value
438-
except Exception as e:
439-
exception = e
439+
except Exception as exc:
440+
exception = exc
440441
stack = stacktrace.get_stacktrace(limit=self.max_trace_back)
441-
raise
442+
six.raise_from(exc, exc)
442443
finally:
443444
# No-op if subsegment is `None` due to `LOG_ERROR`.
444445
if subsegment is not None:

aws_xray_sdk/ext/aiohttp/middleware.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import six
2+
13
"""
24
AioHttp Middleware
35
"""
@@ -64,14 +66,14 @@ async def middleware(request, handler):
6466
except HTTPException as exc:
6567
# Non 2XX responses are raised as HTTPExceptions
6668
response = exc
67-
raise
68-
except Exception as err:
69+
six.raise_from(exc, exc)
70+
except Exception as exc:
6971
# Store exception information including the stacktrace to the segment
7072
response = None
7173
segment.put_http_meta(http.STATUS, 500)
7274
stack = stacktrace.get_stacktrace(limit=xray_recorder.max_trace_back)
73-
segment.add_exception(err, stack)
74-
raise
75+
segment.add_exception(exc, stack)
76+
six.raise_from(exc, exc)
7577
finally:
7678
if response is not None:
7779
segment.put_http_meta(http.STATUS, response.status)

aws_xray_sdk/ext/sqlalchemy_core/patch.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import logging
22
import sys
3+
import wrapt
4+
import six
35

46
if sys.version_info >= (3, 0, 0):
57
from urllib.parse import urlparse, uses_netloc
68
else:
79
from urlparse import urlparse, uses_netloc
810

9-
import wrapt
1011

1112
from aws_xray_sdk.core import xray_recorder
1213
from aws_xray_sdk.core.patcher import _PATCHED_MODULES
@@ -72,12 +73,12 @@ def _process_request(wrapped, engine_instance, args, kwargs):
7273
subsegment = None
7374
try:
7475
res = wrapped(*args, **kwargs)
75-
except Exception:
76+
except Exception as exc:
7677
if subsegment is not None:
7778
exception = sys.exc_info()[1]
7879
stack = stacktrace.get_stacktrace(limit=xray_recorder._max_trace_back)
7980
subsegment.add_exception(exception, stack)
80-
raise
81+
six.raise_from(exc, exc)
8182
finally:
8283
if subsegment is not None:
8384
subsegment.set_sql(sql)

0 commit comments

Comments
 (0)