Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sentry): Replace raven with sentry-sdk #2770

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions content_api/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from superdesk.factory.elastic_apm import setup_apm
from superdesk.validator import SuperdeskValidator
from superdesk.factory.app import SuperdeskEve, set_error_handlers, get_media_storage_class
from superdesk.factory.sentry import SuperdeskSentry


def get_app(config=None):
Expand Down Expand Up @@ -82,8 +81,6 @@ def get_app(config=None):
except AttributeError:
pass

app.sentry = SuperdeskSentry(app)

return app


Expand Down
3 changes: 0 additions & 3 deletions prod_api/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from superdesk.factory.elastic_apm import setup_apm
from superdesk.validator import SuperdeskValidator
from superdesk.factory.app import SuperdeskEve, set_error_handlers, get_media_storage_class
from superdesk.factory.sentry import SuperdeskSentry

from prod_api.auth import JWTAuth

Expand Down Expand Up @@ -90,8 +89,6 @@ def get_app(config=None):
else:
init_app(app)

app.sentry = SuperdeskSentry(app)

return app


Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ ignore_missing_imports = True
[mypy-draftjs_exporter.*]
ignore_missing_imports = True

[mypy-raven.*]
[mypy-sentry_sdk.*]
ignore_missing_imports = True

[mypy-kombu.*]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"ldap3>=2.2.4,<2.10",
"pytz>=2021.3",
"tzlocal>=5.2",
"raven[flask]>=5.10,<7.0",
"sentry-sdk[quart]>=1.5.7,<2.0",
"requests>=2.7.0,<3.0",
"boto3>=1.26,<2.0",
"websockets>=12.0,<13.2",
Expand Down
20 changes: 17 additions & 3 deletions superdesk/factory/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import superdesk
import logging

import sentry_sdk
from sentry_sdk.integrations.asyncio import AsyncioIntegration
from sentry_sdk.integrations.quart import QuartIntegration
from flask_mail import Mail
from eve.auth import TokenAuth
from eve.io.mongo.mongo import _create_index as create_index
Expand All @@ -42,7 +45,6 @@
from superdesk.celery_app import init_celery
from superdesk.datalayer import SuperdeskDataLayer # noqa
from superdesk.errors import SuperdeskError, SuperdeskApiError, DocumentError
from superdesk.factory.sentry import SuperdeskSentry
from superdesk.logging import configure_logging
from superdesk.storage import ProxyMediaStorage
from superdesk.validator import SuperdeskValidator
Expand Down Expand Up @@ -225,8 +227,8 @@ def __init__(self, **kwargs):
self._endpoint_groups = []
self._endpoint_lookup = {}
super().__init__(**kwargs)
self.setup_sentry()
self.async_app = SuperdeskAsyncApp(self)

self.teardown_request(self._after_each_request)

def __getattr__(self, name):
Expand Down Expand Up @@ -399,6 +401,19 @@ def get_current_request(self, req=None) -> HttpFlaskRequest | None:
new_request.user = self.async_app.auth.get_current_user(new_request)
return new_request

def setup_sentry(self):
if not self.config.get("SENTRY_DSN"):
return

# Given how quart_flask_patch patches things, it makes Sentry SDK to think that flask is installed
# mistakenly enabling FlaskIntegration, which breaks QuartIntegration, and preventing sentry from working properly.
# https://github.com/pgjones/quart-flask-patch/blob/0.3.0/src/quart_flask_patch/_patch.py#L110
# This prevents flask integration from being enabled at all until we're can use a newer version of sentry-sdk where
# specific integrations can be disabled https://github.com/getsentry/sentry-python/releases/tag/2.11.0
sentry_sdk.integrations._processed_integrations.add("flask")

sentry_sdk.init(dsn=self.config["SENTRY_DSN"], integrations=[QuartIntegration(), AsyncioIntegration()])


def get_media_storage_class(app_config: Dict[str, Any], use_provider_config: bool = True) -> Type[MediaStorage]:
if use_provider_config and app_config.get("MEDIA_STORAGE_PROVIDER"):
Expand Down Expand Up @@ -471,7 +486,6 @@ def get_app(config=None, media_storage=None, config_object=None, init_elastic=No

app.jinja_loader = custom_loader
app.mail = Mail(app)
app.sentry = SuperdeskSentry(app)
cache_backend.init_app(app)
setup_apm(app)

Expand Down
29 changes: 0 additions & 29 deletions superdesk/factory/sentry.py

This file was deleted.

12 changes: 0 additions & 12 deletions tests/sentry_tests.py

This file was deleted.

Loading