Skip to content

Commit

Permalink
Ensure error group is string
Browse files Browse the repository at this point in the history
  • Loading branch information
TimPansino committed Mar 29, 2023
1 parent 1c05448 commit 45f6896
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 4 additions & 2 deletions newrelic/api/time_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
from newrelic.core.config import is_expected_error, should_ignore_error
from newrelic.core.trace_cache import trace_cache

from newrelic.packages import six

_logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -433,8 +435,8 @@ def notice_error(self, error=None, attributes=None, expected=None, ignore=None,
})
if error_group_name_raw:
_, error_group_name = process_user_attribute("error.group.name", error_group_name_raw)
if error_group_name is None:
raise ValueError("Invalid attribute value for error.group.name: %s" % str(error_group_name_raw))
if error_group_name is None or not isinstance(error_group_name, six.text_type):
raise ValueError("Invalid attribute value for error.group.name. Expected string, got: %s" % str(error_group_name_raw))
except Exception:
_logger.error("Encountered error when calling error group callback:\n%s", "".join(traceback.format_exception(*sys.exc_info())))
error_group_name = None
Expand Down
4 changes: 2 additions & 2 deletions newrelic/core/stats_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,8 +742,8 @@ def notice_error(self, error=None, attributes=None, expected=None, ignore=None,
})
if error_group_name_raw:
_, error_group_name = process_user_attribute("error.group.name", error_group_name_raw)
if error_group_name is None:
raise ValueError("Invalid attribute value for error.group.name: %s" % str(error_group_name_raw))
if error_group_name is None or not isinstance(error_group_name, six.text_type):
raise ValueError("Invalid attribute value for error.group.name. Expected string, got: %s" % str(error_group_name_raw))
else:
agent_attributes["error.group.name"] = error_group_name

Expand Down
8 changes: 6 additions & 2 deletions tests/agent_features/test_error_group_callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ def error_group_callback(exc, data):
return _truncated_value
elif isinstance(exc, IndexError):
return []
elif isinstance(exc, LookupError):
return 123
elif isinstance(exc, TypeError):
return ""

Expand Down Expand Up @@ -86,8 +88,9 @@ def test_set_error_group_callback(callback, accepted):
(TypeError, None, False),
(RuntimeError, None, False),
(IndexError, None, False),
(LookupError, None, False),
(ZeroDivisionError, _truncated_value[:255], False),
], ids=("standard", "high-security", "empty-string", "None-value", "bad-type", "truncated-value"))
], ids=("standard", "high-security", "empty-string", "None-value", "list-type", "int-type", "truncated-value"))
@reset_core_stats_engine()
def test_error_group_name_callback(exc_class, group_name, high_security):
_callback_called.clear()
Expand Down Expand Up @@ -127,8 +130,9 @@ def _test():
(TypeError, None, False),
(RuntimeError, None, False),
(IndexError, None, False),
(LookupError, None, False),
(ZeroDivisionError, _truncated_value[:255], False),
], ids=("standard", "high-security", "empty-string", "None-value", "bad-type", "truncated-value"))
], ids=("standard", "high-security", "empty-string", "None-value", "list-type", "int-type", "truncated-value"))
@reset_core_stats_engine()
def test_error_group_name_callback_outside_transaction(exc_class, group_name, high_security):
_callback_called.clear()
Expand Down

0 comments on commit 45f6896

Please sign in to comment.