From d5dffcffd6211fa686513fd88fb79483cb83808f Mon Sep 17 00:00:00 2001 From: Rajat Ahuja Date: Wed, 7 May 2025 14:06:24 -0500 Subject: [PATCH] filter out HonchoException in sentry.sdk init (#103) * filter out HonchoException in sentry.sdk init * actually capture exc object so it can be filtered properly * rm unused logging integration --- src/main.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main.py b/src/main.py index 4d9143a8..a7369efd 100644 --- a/src/main.py +++ b/src/main.py @@ -66,11 +66,22 @@ async def setup_admin_jwt(): # Sentry Setup SENTRY_ENABLED = os.getenv("SENTRY_ENABLED", "False").lower() == "true" -if SENTRY_ENABLED: +if SENTRY_ENABLED: + + def before_send(event, hint): + if 'exc_info' in hint: + exc_type, exc_value, _ = hint['exc_info'] + # Filter out HonchoExceptions from being sent to Sentry + if isinstance(exc_value, HonchoException): + return None + + return event + sentry_sdk.init( dsn=os.getenv("SENTRY_DSN"), traces_sample_rate=0.4, profiles_sample_rate=0.4, + before_send=before_send, integrations=[ StarletteIntegration( transaction_style="endpoint", @@ -139,7 +150,7 @@ app.include_router(keys.router, prefix="/v1") @app.exception_handler(HonchoException) async def honcho_exception_handler(request: Request, exc: HonchoException): """Handle all Honcho-specific exceptions.""" - logger.error(f"{exc.__class__.__name__}: {exc.detail}") + logger.error(f"{exc.__class__.__name__}: {exc.detail}", exc_info=exc) return JSONResponse( status_code=exc.status_code, content={"detail": exc.detail},