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
This commit is contained in:
parent
9dd214b3a6
commit
d5dffcffd6
15
src/main.py
15
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},
|
||||
|
|
|
|||
Loading…
Reference in New Issue