From 122409d72ca67719895b0a2460da867c13a2b57d Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Mon, 4 Jan 2021 10:43:54 -0500 Subject: [PATCH] exceptions: group CommandFailedErrors in sentry more finely By default sentry uses the stack trace / error type / rough error message, which ends up with many failures from different workunits grouped together. Include the actual command run, the exit status, and the optional label to group these more accurately. This will group failures of the same workunit together, for example. Signed-off-by: Josh Durgin --- teuthology/exceptions.py | 12 ++++++++++++ teuthology/run_tasks.py | 2 ++ 2 files changed, 14 insertions(+) diff --git a/teuthology/exceptions.py b/teuthology/exceptions.py index 7a29b1183..71f33e762 100644 --- a/teuthology/exceptions.py +++ b/teuthology/exceptions.py @@ -68,6 +68,18 @@ class CommandFailedError(Exception): prefix=prefix, ) + def fingerprint(self): + """ + Returns a list of strings to group failures with. + Used by sentry instead of grouping by backtrace. + """ + return [ + ' '.join(self.command), + 'exit status {}'.format(self.exitstatus), + self.label, + '{{ type }}', + ] + class AnsibleFailedError(Exception): diff --git a/teuthology/run_tasks.py b/teuthology/run_tasks.py index c8d36fdb8..602559f7f 100644 --- a/teuthology/run_tasks.py +++ b/teuthology/run_tasks.py @@ -131,10 +131,12 @@ def run_tasks(tasks, ctx): if job_id: extras['logs'] = get_http_log_path(archive_path, job_id) + fingerprint = e.fingerprint() if hasattr(e, 'fingerprint') else None exc_id = sentry_sdk.capture_exception( error=e, tags=tags, extras=extras, + fingerprint=fingerprint, ) event_url = "{server}/?query={id}".format( server=teuth_config.sentry_server.strip('/'), id=exc_id) -- 2.47.3