Skip to content

Commit 31a0642

Browse files
committed
Merge branch 'hotfix/createappeventfix'
2 parents 39816ed + 049cb87 commit 31a0642

File tree

1 file changed

+26
-18
lines changed

1 file changed

+26
-18
lines changed

trakerr/trakerr_io.py

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ def __init__(self, api_key, context_app_version="1.0", context_deployment_stage=
9393
self._events_api = EventsApi(ApiClient(Configuration().host))
9494
# Should get the default url. Also try Configuration().host
9595

96-
def create_new_app_event(self, log_level="error", classification="Issue", event_type=None,
97-
event_message=None, exc_info=None):
96+
def create_new_app_event(self, log_level="error", classification="Issue", event_type="unknown",
97+
event_message="unknown", exc_info=False):
9898
"""
9999
Creates a new AppEvent instance.
100100
:param log_level: Strng representation on the level of the Error.
@@ -108,16 +108,19 @@ def create_new_app_event(self, log_level="error", classification="Issue", event_
108108
:return: AppEvent instance with exc_info parsed depending on the above flags.
109109
"""
110110
try:
111-
if exc_info is None:
111+
if exc_info is True or exc_info is None:
112112
exc_info = sys.exc_info()
113+
if not any(exc_info):
114+
exc_info = False
115+
113116
if exc_info is not False:
114117
if not TrakerrUtils.is_exc_info_tuple(exc_info):
115118
raise TypeError(
116119
"exc_info is expected an exc_info info tuple or False.")
117120
errtype, value = exc_info[:2]
118-
if event_type is None:
121+
if event_type is None or event_type == "unknown":
119122
event_type = TrakerrUtils.format_error_name(errtype)
120-
if event_message is None:
123+
if event_message is None or event_message == "unknown":
121124
event_message = str(value)
122125

123126
if (not isinstance(log_level, string_types)
@@ -161,36 +164,41 @@ def send_event(self, app_event):
161164
self.fill_defaults(app_event)
162165
self._events_api.events_post(app_event)
163166

164-
def send_event_async(self, app_event):
167+
def send_event_async(self, app_event, call_back=None):
165168
"""
166169
Asyncronously sends the given AppEvent instance to trakerr.
167170
:param app_event: AppEvent instance to send to trakerr.
171+
:param call_back: Callback method for the async call.
172+
defaults to module level async_callback.
168173
"""
169174

170175
if not isinstance(app_event, AppEvent):
171176
raise TypeError("Argument is expected of class AppEvent.")
172177

178+
if call_back is None:
179+
call_back = async_callback
180+
173181
self.fill_defaults(app_event)
174182
self._events_api.events_post_with_http_info(
175-
app_event, callback=async_callback)
183+
app_event, callback=call_back)
176184

177-
def log(self, arg_dict, log_level="error", classification="issue", exc_info=None):
185+
def log(self, arg_dict, log_level="error", classification="issue", exc_info=True):
178186
"""
179187
Creates an AppEvent and sends it with the default values to all fields.
180188
Allows the caller to pass in user and session as added information to log,
181189
to file the error under.
182190
:param arg_dict: Dictionary with any of these key value pairs assigned to a string:
183-
errname, errmessage, user, session. You can leave any pair out that you don't need.
184-
To construct with pure default values,pass in an empty dictionary.
185-
If you are getting the Stacktrace errname and message will be filled with
186-
the values from Stacktrace. Otherwise, both errname and errmessage will be unknown.
191+
errname, errmessage, user, session. You can leave any pair out that you don't need.
192+
To construct with pure default values,pass in an empty dictionary.
193+
If you are getting the Stacktrace errname and message will be filled with
194+
the values from Stacktrace. Otherwise, both errname and errmessage will be unknown.
187195
:param log_level: String representation on the level of the Error.
188-
Can be 'debug', 'info', 'warning', 'error', 'fatal', defaults to 'error'.
196+
Can be 'debug', 'info', 'warning', 'error', 'fatal', defaults to 'error'.
189197
:param classification: Optional extra string descriptor to clarify the error.
190-
(IE: log_level is fatal and classification may be 'hard lock' or 'Network error')
198+
(IE: log_level is fatal and classification may be 'hard lock' or 'Network error')
191199
:param exc_info: exc_info tuple to parse.
192-
Default None to generate a exc_info tuple from the current stacktrace.
193-
Pass False to not generate an exc_info tuple.
200+
Default None to generate a exc_info tuple from the current stacktrace.
201+
Pass False to not generate an exc_info tuple.
194202
"""
195203
excevent = self.create_new_app_event(log_level,
196204
classification, arg_dict.get(
@@ -206,7 +214,7 @@ def fill_defaults(self, app_event):
206214
fill out the the event with the instance defaults.
207215
:param app_event: The app event to fill parameters out.
208216
:return: The fully filled out AppEvent object,
209-
while also filling out the instance passed in.
217+
while also filling out the instance passed in.
210218
"""
211219

212220
if not isinstance(app_event, AppEvent):
@@ -425,4 +433,4 @@ def async_callback(response):
425433
:param response: message returned after the async call is completed.
426434
"""
427435

428-
pprint.pprint(str(response), sys.stderr)
436+
#pprint.pprint(str(response), sys.stderr)

0 commit comments

Comments
 (0)