Skip to content

Commit

Permalink
Adding sentry performance tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbyt3r committed Aug 4, 2023
1 parent a67b889 commit 89998e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions uber/configspec.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions uber/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
mimetypes.init()

if c.SENTRY['enabled']:
print("Sentry is enabled")
import sentry_sdk
sentry_sdk.init(
dsn=c.SENTRY['dsn'],
Expand All @@ -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'<body>', (
Expand Down

0 comments on commit 89998e0

Please sign in to comment.