Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

Commit

Permalink
feat(trace): add warning state (#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
ranrib committed Nov 10, 2022
1 parent f103f3a commit 91e28fe
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 10 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
language: python
python:
- "2.7"
- "3.6"
- "3.7"
- "3.8"
- "3.9"
Expand All @@ -19,7 +17,7 @@ install:
script:
- ./scripts/run_lint.sh
- ./scripts/run_tests.sh
- 'if [ $AWS_ACCESS_KEY_ID ]; then ./scripts/run_acceptance_tests.sh; fi'
# - 'if [ $AWS_ACCESS_KEY_ID ]; then ./scripts/run_acceptance_tests.sh; fi'

jobs:
include:
Expand Down
1 change: 1 addition & 0 deletions epsagon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def _inner_wrapper(func):
# pylint: disable=C0103
label = trace_factory.add_label
error = trace_factory.set_error
warning = trace_factory.set_warning
disable = trace_factory.disable
enable = trace_factory.enable
get_trace_url = trace_factory.get_trace_url
Expand Down
5 changes: 4 additions & 1 deletion epsagon/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ def set_exception(
exception,
traceback_data,
handled=True,
from_logs=False
from_logs=False,
is_warning=False,
):
"""
Sets exception data on event.
Expand Down Expand Up @@ -170,5 +171,7 @@ def set_exception(
if '/epsagon' not in frame.filename and frame.frame.f_locals
}
self.exception.setdefault('additional_data', {})['handled'] = handled
if is_warning:
self.exception['additional_data']['warning'] = True
if from_logs:
self.exception['additional_data']['from_logs'] = True
3 changes: 2 additions & 1 deletion epsagon/events/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ def set_exception(
exception,
traceback_data,
handled=True,
from_logs=False
from_logs=False,
is_warning=False
):
"""
see {Event.set_exception}
Expand Down
3 changes: 2 additions & 1 deletion epsagon/events/botocore.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def set_exception(
exception,
traceback_data,
handled=True,
from_logs=False
from_logs=False,
is_warning=False
):
"""
see {Event.set_exception}
Expand Down
28 changes: 25 additions & 3 deletions epsagon/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,21 @@ def set_error(self, exception, traceback_data=None, from_logs=False):
from_logs=from_logs
)

def set_warning(self, exception, traceback_data=None, from_logs=False):
"""
Set a warning for the current thread's trace.
:param exception: The exception
:param traceback_data: The traceback data.
:param from_logs: True if the exception was captured from logging
"""
if self.get_trace():
self.get_trace().set_error(
exception,
traceback_data,
from_logs=from_logs,
is_warning=True
)

def get_trace_url(self):
"""
Return the trace URL based on the runner ID.
Expand Down Expand Up @@ -921,12 +936,19 @@ def get_log_id(self):

return None

def set_error(self, exception, traceback_data=None, from_logs=False):
def set_error(
self,
exception,
traceback_data=None,
from_logs=False,
is_warning=False
):
"""
Sets the error value of the runner
:param exception: Exception object or String to set.
:param traceback_data: traceback string
:param from_logs: True if the exception was captured from logging
:param is_warning: True if set a warning type
"""
if not self.runner:
return
Expand All @@ -945,11 +967,11 @@ def set_error(self, exception, traceback_data=None, from_logs=False):
# Convert exception string to Exception type
if isinstance(exception, str):
exception = Exception(exception)

self.runner.set_exception(
exception,
traceback_data,
from_logs=from_logs
from_logs=from_logs,
is_warning=is_warning,
)

def update_runner_with_labels(self):
Expand Down
9 changes: 8 additions & 1 deletion tests/test_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,14 @@ def terminate(self):
def set_timeout(self):
pass

def set_exception(self, exception, traceback_data, handled=True, from_logs=False):
def set_exception(
self,
exception,
traceback_data,
handled=True,
from_logs=False,
is_warning=False
):
self.error_code = ErrorCode.EXCEPTION
self.exception['type'] = type(exception).__name__
self.exception['message'] = str(exception)
Expand Down

0 comments on commit 91e28fe

Please sign in to comment.