Skip to content

Commit

Permalink
Use sentry-fastapi integration, expose sampling rate
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdbeek committed Feb 10, 2023
1 parent 45c0701 commit c3a6fb9
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 19 deletions.
13 changes: 13 additions & 0 deletions doc/source/admin/galaxy_options.rst
Expand Up @@ -2914,6 +2914,19 @@
:Type: str


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
``sentry_traces_sample_rate``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

:Description:
Set to a number between 0 and 1. With this option set, every
transaction created will have that percentage chance of being sent
to Sentry. A value higher than 0 is required to analyze
performance.
:Default: ``0``
:Type: float


~~~~~~~~~~~~~~~
``statsd_host``
~~~~~~~~~~~~~~~
Expand Down
1 change: 1 addition & 0 deletions lib/galaxy/app.py
Expand Up @@ -202,6 +202,7 @@ def postfork_sentry_client():
self.config.sentry_dsn,
release=f"{self.config.version_major}.{self.config.version_minor}",
integrations=[sentry_logging],
traces_sample_rate=self.config.sentry_traces_sample_rate,
)

self.application_stack.register_postfork_function(postfork_sentry_client)
Expand Down
5 changes: 5 additions & 0 deletions lib/galaxy/config/sample/galaxy.yml.sample
Expand Up @@ -1667,6 +1667,11 @@ galaxy:
# Sentry. Possible values are DEBUG, INFO, WARNING, ERROR or CRITICAL.
#sentry_event_level: ERROR

# Set to a number between 0 and 1. With this option set, every
# transaction created will have that percentage chance of being sent
# to Sentry. A value higher than 0 is required to analyze performance.
#sentry_traces_sample_rate: 0

# Log to statsd Statsd is an external statistics aggregator
# (https://github.com/etsy/statsd) Enabling the following options will
# cause galaxy to log request timing and other statistics to the
Expand Down
5 changes: 5 additions & 0 deletions lib/galaxy/config/sample/tool_shed.yml.sample
Expand Up @@ -311,6 +311,11 @@ tool_shed:
# Sentry. Possible values are DEBUG, INFO, WARNING, ERROR or CRITICAL.
#sentry_event_level: ERROR

# Set to a number between 0 and 1. With this option set, every
# transaction created will have that percentage chance of being sent
# to Sentry. A value higher than 0 is required to analyze performance.
#sentry_traces_sample_rate: 0

# Galaxy Session Timeout This provides a timeout (in minutes) after
# which a user will have to log back in. A duration of 0 disables this
# feature.
Expand Down
9 changes: 9 additions & 0 deletions lib/galaxy/config/schemas/config_schema.yml
Expand Up @@ -2108,6 +2108,15 @@ mapping:
Determines the minimum log level that will be sent as an event to Sentry.
Possible values are DEBUG, INFO, WARNING, ERROR or CRITICAL.
sentry_traces_sample_rate:
type: float
default: 0
required: false
desc: |
Set to a number between 0 and 1. With this option set, every transaction created
will have that percentage chance of being sent to Sentry. A value higher than 0
is required to analyze performance.
statsd_host:
type: str
required: false
Expand Down
9 changes: 9 additions & 0 deletions lib/galaxy/config/schemas/tool_shed_config_schema.yml
Expand Up @@ -557,6 +557,15 @@ mapping:
Determines the minimum log level that will be sent as an event to Sentry.
Possible values are DEBUG, INFO, WARNING, ERROR or CRITICAL.
sentry_traces_sample_rate:
type: float
default: 0
required: false
desc: |
Set to a number between 0 and 1. With this option set, every transaction created
will have that percentage chance of being sent to Sentry. A value higher than 0
is required to analyze performance.
session_duration:
type: int
default: 0
Expand Down
2 changes: 1 addition & 1 deletion lib/galaxy/dependencies/conditional-requirements.txt
Expand Up @@ -2,7 +2,7 @@
psycopg2-binary==2.9.5
mysqlclient
fluent-logger
sentry-sdk
sentry-sdk[fastapi]
pbs_python
drmaa
statsd
Expand Down
7 changes: 1 addition & 6 deletions lib/galaxy/webapps/galaxy/buildapp.py
Expand Up @@ -66,6 +66,7 @@ def app_pair(global_conf, load_app_kwds=None, wsgi_preflight=True, **kwargs):
# Call app's shutdown method when the interpeter exits, this cleanly stops
# the various Galaxy application daemon threads
app.application_stack.register_postfork_function(atexit.register, app.shutdown)

# Create the universe WSGI application
webapp = GalaxyWebApplication(app, session_cookie="galaxysession", name="galaxy")

Expand Down Expand Up @@ -1304,13 +1305,7 @@ def wrap_in_middleware(app, global_conf, application_stack, **local_conf):
from paste import recursive

app = wrap_if_allowed(app, stack, recursive.RecursiveMiddleware, args=(conf,))
# If sentry logging is enabled, log here before propogating up to
# the error middleware
sentry_dsn = conf.get("sentry_dsn", None)
if sentry_dsn:
from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware

app = wrap_if_allowed(app, stack, SentryWsgiMiddleware)
# Error middleware
app = wrap_if_allowed(app, stack, ErrorMiddleware, args=(conf,))
# Transaction logging (apache access.log style)
Expand Down
5 changes: 0 additions & 5 deletions lib/galaxy/webapps/galaxy/fast_app.py
Expand Up @@ -107,11 +107,6 @@ async def add_x_frame_options(request: Request, call_next):
GalaxyFileResponse.nginx_x_accel_redirect_base = gx_app.config.nginx_x_accel_redirect_base
GalaxyFileResponse.apache_xsendfile = gx_app.config.apache_xsendfile

if gx_app.config.sentry_dsn:
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware

app.add_middleware(SentryAsgiMiddleware)

if gx_app.config.get("allowed_origin_hostnames", None):
app.add_middleware(
GalaxyCORSMiddleware,
Expand Down
7 changes: 0 additions & 7 deletions lib/tool_shed/webapp/buildapp.py
Expand Up @@ -267,14 +267,7 @@ def wrap_in_middleware(app, global_conf, application_stack, **local_conf):
from paste.translogger import TransLogger

app = wrap_if_allowed(app, stack, TransLogger)
# If sentry logging is enabled, log here before propogating up to
# the error middleware
# TODO sentry config is duplicated between tool_shed/galaxy, refactor this.
sentry_dsn = conf.get("sentry_dsn", None)
if sentry_dsn:
from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware

app = wrap_if_allowed(app, stack, SentryWsgiMiddleware)
# X-Forwarded-Host handling
from galaxy.web.framework.middleware.xforwardedhost import XForwardedHostMiddleware

Expand Down

0 comments on commit c3a6fb9

Please sign in to comment.