mirror of
https://github.com/quay/quay.git
synced 2025-11-16 11:42:27 +03:00
* Updated raven dependency to be compatible with python 3.12 --------- Co-authored-by: shudeshp <shudeshp@redhat.com>
60 lines
1.8 KiB
Python
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)
|