Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sentry #92

Merged
merged 1 commit into from
Jan 23, 2025
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
27 changes: 17 additions & 10 deletions odabot/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@
from dynaconf import Dynaconf
from dynaconf.vendor.box import BoxList

import sentry_sdk

logger = logging.getLogger()

# will init if SENTRY_DSN is set
sentry = sentry_sdk.init()

try:
import markdown
import rdflib
Expand Down Expand Up @@ -89,7 +94,7 @@ def send_email(_to, subject, text, attachments=None, extra_emails=[]):
)
logger.info('sending email: %s %s', r, r.text)
except Exception as e:
logger.error('Exception while sending email: %s', e)
logger.exception('Exception while sending email: %s', e)


def get_commit_state(gitlab_api_url, proj_id, commit_sha, name):
Expand Down Expand Up @@ -433,7 +438,10 @@ def update_workflow(last_commit,
'last_deployment_status': 'failed',
'stage_failed': 'build'}

logger.warning('exception deploying %s! %s', project['name'], repr(e))
logger.error('Build error in %s! %s', project['name'], repr(e),
extra={'Dockerfile': getattr(e, 'dockerfile', None),
'buildlog': getattr(e, 'buildlog', None)})


with tempfile.TemporaryDirectory() as tmpdir:
attachments = []
Expand All @@ -460,7 +468,7 @@ def update_workflow(last_commit,
'last_deployment_status': 'failed',
'stage_failed': 'deploy'}

logger.warning('exception deploying %s! %s', project['name'], repr(e))
logger.exception('exception deploying %s! %s', project['name'], repr(e))

send_email(last_commit['committer_email'],
f"[ODA-Workflow-Bot] unfortunately did NOT manage to deploy {project['name']}!",
Expand All @@ -472,7 +480,6 @@ def update_workflow(last_commit,
send_email(extra_emails,
f"[ODA-Workflow-Bot] internal error while deploying {project['name']}",
traceback.format_exc())
# TODO: sentry

else:
kg_record = f'''
Expand Down Expand Up @@ -749,7 +756,7 @@ def update_workflows(obj, dry_run, force, loop, pattern):
yaml.dump(oda_bot_runtime, fd)

except Exception as e:
logger.error("unexpected exception: %s", traceback.format_exc())
logger.exception("unexpected exception: %s", traceback.format_exc())

if loop > 0:
logger.info("sleeping %s", loop)
Expand Down Expand Up @@ -1155,7 +1162,7 @@ def repo_file_path_if_available(filename):

except Exception as e:
if isinstance(e, sp.SubprocessError):
logger.error(r.stderr)
logger.exception('%s. stderr: %s', e, r.stderr)

kwargs = {}
try:
Expand Down Expand Up @@ -1194,8 +1201,8 @@ def repo_file_path_if_available(filename):
with open(state_storage, 'w') as fd:
yaml.dump(oda_bot_runtime, fd)
except Exception as e:
logger.error("unexpected exception: %s", traceback.format_exc())
logger.error("Cleanup all changes in the repo directory")
logger.exception("unexpected exception: %s", traceback.format_exc())
logger.info("Cleanup all changes in the repo directory")
try:
set_commit_state(
gitlab_api_url=gitlab_api_url,
Expand All @@ -1210,12 +1217,12 @@ def repo_file_path_if_available(filename):
pass

sp.run(['git', 'clean', '-fd'])
logger.error("continue with the next repo")
logger.info("continue with the next repo")

continue

except Exception:
logger.error("unexpected exception: %s", traceback.format_exc())
logger.exception("unexpected exception: %s", traceback.format_exc())

if loop > 0:
logger.info("sleeping %s", loop)
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
'click',
'requests',
'dynaconf',
'sentry-sdk'
]

extras_req = {
Expand All @@ -23,7 +24,7 @@
],
'galaxy': [
'nb2workflow[galaxy]',
'python-frontmatter'
'python-frontmatter',
]

}
Expand Down
Loading