Skip to content
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
13 changes: 3 additions & 10 deletions newrelic/api/time_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,23 +360,16 @@ def _observe_exception(self, exc_info=None, ignore=None, expected=None, status_c
return fullname, message, message_raw, tb, is_expected

def notice_error(self, error=None, attributes=None, expected=None, ignore=None, status_code=None):
def error_is_iterable(error):
return hasattr(error, "__iter__") and not isinstance(error, (str, bytes))

def none_in_error(error):
return error_is_iterable(error) and None in error

attributes = attributes if attributes is not None else {}

# If no exception details provided, use current exception.

# Pull from sys.exc_info() if no exception is passed
# Check that the error exists and that it is a fully populated iterable
if not error or none_in_error(error) or (error and not error_is_iterable(error)):
# Pull from sys.exc_info if no exception is passed
if not error or None in error:
error = sys.exc_info()

# If no exception to report, exit
if not error or none_in_error(error) or (error and not error_is_iterable(error)):
if not error or None in error:
return

exc, value, tb = error
Expand Down
12 changes: 3 additions & 9 deletions newrelic/core/stats_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,14 +676,9 @@ def record_time_metrics(self, metrics):
self.record_time_metric(metric)

def notice_error(self, error=None, attributes=None, expected=None, ignore=None, status_code=None):
def error_is_iterable(error):
return hasattr(error, "__iter__") and not isinstance(error, (str, bytes))

def none_in_error(error):
return error_is_iterable(error) and None in error

attributes = attributes if attributes is not None else {}
settings = self.__settings

if not settings:
return

Expand All @@ -696,12 +691,11 @@ def none_in_error(error):
return

# Pull from sys.exc_info if no exception is passed
# Check that the error exists and that it is a fully populated iterable
if not error or none_in_error(error) or (error and not error_is_iterable(error)):
if not error or None in error:
error = sys.exc_info()

# If no exception to report, exit
if not error or none_in_error(error) or (error and not error_is_iterable(error)):
if not error or None in error:
return

exc, value, tb = error
Expand Down
19 changes: 0 additions & 19 deletions tests/agent_features/test_notice_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,6 @@

# =============== Test errors during a transaction ===============

_key_error_name = callable_name(KeyError)

_test_notice_error_exception_object = [(_key_error_name, "'f'")]


@validate_transaction_errors(errors=_test_notice_error_exception_object)
@background_task()
def test_notice_error_non_iterable_object():
"""Test that notice_error works when passed an exception object directly"""
try:
test_dict = {"a": 4, "b": 5}
# Force a KeyError
test_dict["f"]
except KeyError as e:
# The caught exception here is a non-iterable, singular KeyError object with no associated traceback
# This will exercise logic to pull from sys.exc_info() instead of using the exception directly
notice_error(e)


_test_notice_error_sys_exc_info = [(_runtime_error_name, "one")]


Expand Down
Loading