Skip to content

Commit

Permalink
exceptions: group CommandFailedErrors in sentry more finely
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jdurgin committed Jan 6, 2021
1 parent ec8beeb commit 122409d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions teuthology/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ def __str__(self):
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):

Expand Down
2 changes: 2 additions & 0 deletions teuthology/run_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 122409d

Please sign in to comment.