diff --git a/uber/configspec.ini b/uber/configspec.ini index bd3ee9578..e30e6ce32 100644 --- a/uber/configspec.ini +++ b/uber/configspec.ini @@ -1842,6 +1842,8 @@ release = string(default="") [[/]] tools.add_email_to_error_page.on = boolean(default=True) +tools.report_sentry.on = boolean(default=True) +tools.start_transaction.on = boolean(default=True) # custom logging output: # turn off normal traceback and header logging on errors, instead use our custom verbose logger that prints more info diff --git a/uber/server.py b/uber/server.py index 6ff01bf34..ae3e1c776 100644 --- a/uber/server.py +++ b/uber/server.py @@ -23,6 +23,7 @@ mimetypes.init() if c.SENTRY['enabled']: + print("Sentry is enabled") import sentry_sdk sentry_sdk.init( dsn=c.SENTRY['dsn'], @@ -35,6 +36,19 @@ traces_sample_rate=c.SENTRY['sample_rate'] / 100 ) + def start_transaction(): + cherrypy.request.sentry_transaction = sentry_sdk.start_transaction( + name=f"{cherrypy.request.method} {cherrypy.request.path_info}", + op=f"{cherrypy.request.method} {cherrypy.request.path_info}", + ) + cherrypy.request.sentry_transaction.__enter__() + cherrypy.tools.start_transaction = cherrypy.Tool('on_start_resource', start_transaction) + + def report_sentry(): + cherrypy.request.sentry_transaction.__exit__(None, None, None) + cherrypy.tools.report_sentry = cherrypy.Tool('on_end_request', report_sentry) + + def _add_email(): [body] = cherrypy.response.body body = body.replace(b'', (