Skip to content

Implement PEP3134 to discover underlying problems with python3 #355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions aws_xray_sdk/core/async_recorder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import time
import six

from aws_xray_sdk.core.recorder import AWSXRayRecorder
from aws_xray_sdk.core.utils import stacktrace
Expand Down Expand Up @@ -81,10 +82,10 @@ async def record_subsegment_async(self, wrapped, instance, args, kwargs, name,
try:
return_value = await wrapped(*args, **kwargs)
return return_value
except Exception as e:
exception = e
except Exception as exc:
exception = exc
stack = stacktrace.get_stacktrace(limit=self._max_trace_back)
raise
six.raise_from(exc, exc)
finally:
# No-op if subsegment is `None` due to `LOG_ERROR`.
if subsegment is not None:
Expand Down
5 changes: 3 additions & 2 deletions aws_xray_sdk/core/patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import re
import sys
import wrapt
import six

from aws_xray_sdk import global_sdk_config
from .utils.compat import PY2, is_classmethod, is_instance_method
Expand Down Expand Up @@ -107,9 +108,9 @@ def patch(modules_to_patch, raise_errors=True, ignore_module_patterns=None):
def _patch_module(module_to_patch, raise_errors=True):
try:
_patch(module_to_patch)
except Exception:
except Exception as exc:
if raise_errors:
raise
six.raise_from(exc, exc)
log.debug('failed to patch module %s', module_to_patch)


Expand Down
7 changes: 4 additions & 3 deletions aws_xray_sdk/core/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import platform
import time
import six

from aws_xray_sdk import global_sdk_config
from aws_xray_sdk.version import VERSION
Expand Down Expand Up @@ -435,10 +436,10 @@ def record_subsegment(self, wrapped, instance, args, kwargs, name,
try:
return_value = wrapped(*args, **kwargs)
return return_value
except Exception as e:
exception = e
except Exception as exc:
exception = exc
stack = stacktrace.get_stacktrace(limit=self.max_trace_back)
raise
six.raise_from(exc, exc)
finally:
# No-op if subsegment is `None` due to `LOG_ERROR`.
if subsegment is not None:
Expand Down
10 changes: 6 additions & 4 deletions aws_xray_sdk/ext/aiohttp/middleware.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import six

"""
AioHttp Middleware
"""
Expand Down Expand Up @@ -64,14 +66,14 @@ async def middleware(request, handler):
except HTTPException as exc:
# Non 2XX responses are raised as HTTPExceptions
response = exc
raise
except Exception as err:
six.raise_from(exc, exc)
except Exception as exc:
# Store exception information including the stacktrace to the segment
response = None
segment.put_http_meta(http.STATUS, 500)
stack = stacktrace.get_stacktrace(limit=xray_recorder.max_trace_back)
segment.add_exception(err, stack)
raise
segment.add_exception(exc, stack)
six.raise_from(exc, exc)
finally:
if response is not None:
segment.put_http_meta(http.STATUS, response.status)
Expand Down
7 changes: 4 additions & 3 deletions aws_xray_sdk/ext/sqlalchemy_core/patch.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import logging
import sys
import wrapt
import six

if sys.version_info >= (3, 0, 0):
from urllib.parse import urlparse, uses_netloc
else:
from urlparse import urlparse, uses_netloc

import wrapt
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just moved upwards to remove pylint:C0413


from aws_xray_sdk.core import xray_recorder
from aws_xray_sdk.core.patcher import _PATCHED_MODULES
Expand Down Expand Up @@ -72,12 +73,12 @@ def _process_request(wrapped, engine_instance, args, kwargs):
subsegment = None
try:
res = wrapped(*args, **kwargs)
except Exception:
except Exception as exc:
if subsegment is not None:
exception = sys.exc_info()[1]
stack = stacktrace.get_stacktrace(limit=xray_recorder._max_trace_back)
subsegment.add_exception(exception, stack)
raise
six.raise_from(exc, exc)
finally:
if subsegment is not None:
subsegment.set_sql(sql)
Expand Down