Unverified Commit 981c0f83 authored by mvdbeek's avatar mvdbeek
Browse files

Drop SentryWSGIMiddleware

It appears that we can't combine the WSGI middleware with the ASGI
middleware in the same app. We're currently not sending events that
occur in the WSGI portion of the app. With this change they're logged
again, though we do lose the WSGI request context (which contains,
browser, route, etc.) It's usually pretty clear from the traceback what
went wrong though, so I think this is much better than what's happening
now.
parent e7092b6d
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -171,6 +171,11 @@ def add_empty_response_middleware(app: FastAPI) -> None:
    app.add_middleware(SuppressNoResponseReturnedMiddleware)


def add_sentry_middleware(app: FastAPI) -> None:
    from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
    app.add_middleware(SentryAsgiMiddleware)


def add_exception_handler(app: FastAPI) -> None:
    @app.exception_handler(RequestValidationError)
    async def validate_exception_middleware(request: Request, exc: RequestValidationError) -> Response:
+0 −6
Original line number Diff line number Diff line
@@ -1366,13 +1366,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)
    # Various debug middleware that can only be turned on if the debug
    # flag is set, either because they are insecure or greatly hurt
    # performance
+3 −5
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ from galaxy.webapps.base.api import (
    add_empty_response_middleware,
    add_exception_handler,
    add_request_id_middleware,
    add_sentry_middleware,
    GalaxyFileResponse,
    include_all_package_routers,
)
@@ -103,11 +104,6 @@ def add_galaxy_middleware(app: FastAPI, gx_app):
    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,
@@ -158,6 +154,8 @@ def initialize_fast_app(gx_wsgi_webapp, gx_app):
    gx_app.haltables.append(("WSGI Middleware threadpool", wsgi_handler.executor.shutdown))
    app.mount("/", wsgi_handler)
    add_empty_response_middleware(app)
    if gx_app.config.sentry_dsn:
        add_sentry_middleware(app)
    if gx_app.config.galaxy_url_prefix != "/":
        parent_app = FastAPI()
        parent_app.mount(gx_app.config.galaxy_url_prefix, app=app)
+0 −7
Original line number Diff line number Diff line
@@ -263,14 +263,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

+3 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ from galaxy.webapps.base.api import (
    add_empty_response_middleware,
    add_exception_handler,
    add_request_id_middleware,
    add_sentry_middleware,
    include_all_package_routers,
)

@@ -22,6 +23,8 @@ def initialize_fast_app(gx_webapp, tool_shed_app):
    tool_shed_app.haltables.append(("WSGI Middleware threadpool", wsgi_handler.executor.shutdown))
    app.mount("/", wsgi_handler)
    add_empty_response_middleware(app)
    if tool_shed_app.config.sentry_dsn:
        add_sentry_middleware(app=app)
    return app