-
Notifications
You must be signed in to change notification settings - Fork 565
fix(aws): Inject scopes in TimeoutThread exception with AWS lambda #4914
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
Changes from 3 commits
58535a3
2f0e1f4
826f49b
b4c993e
2ff1ba2
a0b8ffc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1484,17 +1484,37 @@ class TimeoutThread(threading.Thread): | |
waiting_time and raises a custom ServerlessTimeout exception. | ||
""" | ||
|
||
def __init__(self, waiting_time, configured_timeout): | ||
# type: (float, int) -> None | ||
def __init__( | ||
self, waiting_time, configured_timeout, isolation_scope=None, current_scope=None | ||
): | ||
# type: (float, int, Optional[Scope], Optional[Scope]) -> None | ||
threading.Thread.__init__(self) | ||
self.waiting_time = waiting_time | ||
self.configured_timeout = configured_timeout | ||
|
||
self.isolation_scope = isolation_scope | ||
self.current_scope = current_scope | ||
|
||
self._stop_event = threading.Event() | ||
|
||
def stop(self): | ||
# type: () -> None | ||
self._stop_event.set() | ||
|
||
def _capture_exception(self): | ||
# type: () -> ExcInfo | ||
exc_info = sys.exc_info() | ||
|
||
client = sentry_sdk.get_client() | ||
event, hint = event_from_exception( | ||
exc_info, | ||
client_options=client.options, | ||
mechanism={"type": "threading", "handled": False}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: AWS Lambda Timeout Mechanism InconsistencyThe |
||
) | ||
sentry_sdk.capture_event(event, hint=hint) | ||
|
||
return exc_info | ||
|
||
def run(self): | ||
# type: () -> None | ||
|
||
|
@@ -1509,12 +1529,19 @@ def run(self): | |
if integer_configured_timeout < self.configured_timeout: | ||
integer_configured_timeout = integer_configured_timeout + 1 | ||
|
||
# Raising Exception after timeout duration is reached | ||
raise ServerlessTimeoutWarning( | ||
"WARNING : Function is expected to get timed out. Configured timeout duration = {} seconds.".format( | ||
integer_configured_timeout | ||
) | ||
) | ||
if self.isolation_scope is not None and self.current_scope is not None: | ||
with sentry_sdk.scope.use_isolation_scope(self.isolation_scope): | ||
with sentry_sdk.scope.use_scope(self.current_scope): | ||
try: | ||
# with use_scope(self.current_scope): | ||
# Raising Exception after timeout duration is reached | ||
raise ServerlessTimeoutWarning( | ||
"WARNING : Function is expected to get timed out. Configured timeout duration = {} seconds.".format( | ||
integer_configured_timeout | ||
) | ||
) | ||
except Exception: | ||
reraise(*self._capture_exception()) | ||
|
||
|
||
def to_base64(original): | ||
|
Uh oh!
There was an error while loading. Please reload this page.