in bot/code_review_bot/tools/log.py [0:0]
def setup_sentry(name, channel, dsn):
"""
Setup sentry account using taskcluster secrets
"""
# Detect environment
task_id = os.environ.get("TASK_ID")
if task_id is not None:
site = "taskcluster"
elif "DYNO" in os.environ:
site = "heroku"
else:
site = "unknown"
# This integration allows sentry to catch logs from logging and process them
# By default, the 'event_level' is set to ERROR, we are defining it to WARNING
sentry_logging = LoggingIntegration(
level=logging.INFO, # Capture INFO and above as breadcrumbs
event_level=logging.WARNING, # Send WARNINGs as events
)
# sentry_sdk will automatically retrieve the 'extra' attribute from logs and
# add contained values as Additional Data on the dashboard of the Sentry issue
sentry_sdk.init(
dsn=dsn,
integrations=[sentry_logging],
server_name=name,
environment=channel,
release=pkg_resources.get_distribution(f"code-review-{name}").version,
before_send=remove_color_codes,
)
sentry_sdk.set_tag("site", site)
if task_id is not None:
# Add a Taskcluster task id when available
# It will be shown in a new section called Task on the dashboard
sentry_sdk.set_context("task", {"task_id": task_id})