1
0
mirror of https://github.com/quay/quay.git synced 2025-11-16 11:42:27 +03:00
Files
quay/util/saas/exceptionlog.py
Shubhra Deshpande 22290c9812 deps: updated raven dependency to be compatible with python 3.12 (PROJQUAY-9198) (#4169)
* Updated raven dependency to be compatible with python 3.12

---------

Co-authored-by: shudeshp <shudeshp@redhat.com>
2025-08-07 15:58:59 -04:00

60 lines
1.8 KiB
Python

import logging
import sentry_sdk
class FakeSentryClient(object):
def captureException(self, *args, **kwargs):
pass
def user_context(self, *args, **kwargs):
pass
class FakeSentry(object):
def __init__(self):
self.client = FakeSentryClient()
class Sentry(object):
def __init__(self, app=None):
self.app = app
if app is not None:
self.state = self.init_app(app)
else:
self.state = None
def init_app(self, app):
sentry_type = app.config.get("EXCEPTION_LOG_TYPE", "FakeSentry")
if sentry_type == "Sentry":
sentry_dsn = app.config.get("SENTRY_DSN", "")
if sentry_dsn:
try:
initialized_sentry = sentry_sdk.init(
dsn=sentry_dsn,
environment=app.config.get("SENTRY_ENVIRONMENT", "production"),
traces_sample_rate=app.config.get("SENTRY_TRACES_SAMPLE_RATE", 0.1),
profiles_sample_rate=app.config.get("SENTRY_PROFILES_SAMPLE_RATE", 0.1),
)
# Return the initialized Sentry SDK object directly
sentry = initialized_sentry
except Exception as e:
logger = logging.getLogger(__name__)
logger.warning("Failed to initialize Sentry: %s", str(e))
sentry = FakeSentry()
else:
sentry = FakeSentry()
else:
sentry = FakeSentry()
# register extension with app
app.extensions = getattr(app, "extensions", {})
app.extensions["sentry"] = sentry
return sentry
def __getattr__(self, name):
if self.state is None:
return None
return getattr(self.state, name, None)