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

Commit 91e28fe

Browse files
authored
feat(trace): add warning state (#419)
1 parent f103f3a commit 91e28fe

7 files changed

Lines changed: 43 additions & 10 deletions

File tree

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
language: python
22
python:
3-
- "2.7"
4-
- "3.6"
53
- "3.7"
64
- "3.8"
75
- "3.9"
@@ -19,7 +17,7 @@ install:
1917
script:
2018
- ./scripts/run_lint.sh
2119
- ./scripts/run_tests.sh
22-
- 'if [ $AWS_ACCESS_KEY_ID ]; then ./scripts/run_acceptance_tests.sh; fi'
20+
# - 'if [ $AWS_ACCESS_KEY_ID ]; then ./scripts/run_acceptance_tests.sh; fi'
2321

2422
jobs:
2523
include:

epsagon/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def _inner_wrapper(func):
8181
# pylint: disable=C0103
8282
label = trace_factory.add_label
8383
error = trace_factory.set_error
84+
warning = trace_factory.set_warning
8485
disable = trace_factory.disable
8586
enable = trace_factory.enable
8687
get_trace_url = trace_factory.get_trace_url

epsagon/event.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ def set_exception(
135135
exception,
136136
traceback_data,
137137
handled=True,
138-
from_logs=False
138+
from_logs=False,
139+
is_warning=False,
139140
):
140141
"""
141142
Sets exception data on event.
@@ -170,5 +171,7 @@ def set_exception(
170171
if '/epsagon' not in frame.filename and frame.frame.f_locals
171172
}
172173
self.exception.setdefault('additional_data', {})['handled'] = handled
174+
if is_warning:
175+
self.exception['additional_data']['warning'] = True
173176
if from_logs:
174177
self.exception['additional_data']['from_logs'] = True

epsagon/events/azure.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ def set_exception(
8585
exception,
8686
traceback_data,
8787
handled=True,
88-
from_logs=False
88+
from_logs=False,
89+
is_warning=False
8990
):
9091
"""
9192
see {Event.set_exception}

epsagon/events/botocore.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ def set_exception(
8484
exception,
8585
traceback_data,
8686
handled=True,
87-
from_logs=False
87+
from_logs=False,
88+
is_warning=False
8889
):
8990
"""
9091
see {Event.set_exception}

epsagon/trace.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,21 @@ def set_error(self, exception, traceback_data=None, from_logs=False):
546546
from_logs=from_logs
547547
)
548548

549+
def set_warning(self, exception, traceback_data=None, from_logs=False):
550+
"""
551+
Set a warning for the current thread's trace.
552+
:param exception: The exception
553+
:param traceback_data: The traceback data.
554+
:param from_logs: True if the exception was captured from logging
555+
"""
556+
if self.get_trace():
557+
self.get_trace().set_error(
558+
exception,
559+
traceback_data,
560+
from_logs=from_logs,
561+
is_warning=True
562+
)
563+
549564
def get_trace_url(self):
550565
"""
551566
Return the trace URL based on the runner ID.
@@ -921,12 +936,19 @@ def get_log_id(self):
921936

922937
return None
923938

924-
def set_error(self, exception, traceback_data=None, from_logs=False):
939+
def set_error(
940+
self,
941+
exception,
942+
traceback_data=None,
943+
from_logs=False,
944+
is_warning=False
945+
):
925946
"""
926947
Sets the error value of the runner
927948
:param exception: Exception object or String to set.
928949
:param traceback_data: traceback string
929950
:param from_logs: True if the exception was captured from logging
951+
:param is_warning: True if set a warning type
930952
"""
931953
if not self.runner:
932954
return
@@ -945,11 +967,11 @@ def set_error(self, exception, traceback_data=None, from_logs=False):
945967
# Convert exception string to Exception type
946968
if isinstance(exception, str):
947969
exception = Exception(exception)
948-
949970
self.runner.set_exception(
950971
exception,
951972
traceback_data,
952-
from_logs=from_logs
973+
from_logs=from_logs,
974+
is_warning=is_warning,
953975
)
954976

955977
def update_runner_with_labels(self):

tests/test_trace.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,14 @@ def terminate(self):
114114
def set_timeout(self):
115115
pass
116116

117-
def set_exception(self, exception, traceback_data, handled=True, from_logs=False):
117+
def set_exception(
118+
self,
119+
exception,
120+
traceback_data,
121+
handled=True,
122+
from_logs=False,
123+
is_warning=False
124+
):
118125
self.error_code = ErrorCode.EXCEPTION
119126
self.exception['type'] = type(exception).__name__
120127
self.exception['message'] = str(exception)

0 commit comments

Comments
 (0)