Skip to content

Commit

Permalink
[SDESK-7389] Fix sentry/quart integrations (#1148)
Browse files Browse the repository at this point in the history
* Fix sentry/quart integrations

`sentry-sdk` newer than v2.0 cannot be used as we are stuck with self hosted Sentry `v9.0`. As of `sentry-sdk` 2.0.0, there is a breaking change, were events are sent to `/envelope` endpoint instead of `/store`. This new `/envelope` endpoint was implemented on Sentry Server in `v10.0`.

References:
- https://github.com/getsentry/sentry-python/releases/tag/2.0.0 (look for "Removed support for sending events to the /store endpoint")
- https://forum.sentry.io/t/csrf-verification-failed-token-was-not-found-or-was-invalid/12177/6

SDESK-7389

* Remove not needed import
  • Loading branch information
eos87 authored Nov 5, 2024
1 parent 2239098 commit 8daa99a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ rsa==4.9
# oauth2client
s3transfer==0.10.3
# via boto3
sentry-sdk[quart]==2.14.0
sentry-sdk[quart]==1.45.1
# via -r requirements.txt
sgmllib3k==1.0.0
# via feedparser
Expand Down
20 changes: 11 additions & 9 deletions newsroom/factory/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pathlib
import importlib

# import sentry_sdk
import sentry_sdk
from flask_mail import Mail
from flask_caching import Cache
from elasticapm.contrib.flask import ElasticAPM
Expand All @@ -28,7 +28,7 @@
from superdesk.core.storage import GridFSMediaStorageAsync
from superdesk.factory.app import SuperdeskEve

# from sentry_sdk.integrations.quart import QuartIntegration
from sentry_sdk.integrations.quart import QuartIntegration

import newsroom
from newsroom.auth.eve_auth import SessionAuth
Expand Down Expand Up @@ -287,13 +287,15 @@ def register_resource(self, resource, settings):
self.logger.warning("Consider adding regex_url config to resource %s to fix HATEOAS", resource)

def setup_sentry(self):
# TODO-ASYNC: Fix sentry/quart integrations
pass
# if self.config.get("SENTRY_DSN"):
# sentry_sdk.init(
# dsn=self.config["SENTRY_DSN"],
# integrations=[QuartIntegration()],
# )
if self.config.get("SENTRY_DSN"):
# 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()])

def _get_apm_environment(self):
if self.config.get("CLIENT_URL"):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ honcho>=1.0.1
hypercorn>=0.17.3
PyRTF3>=0.47.5
xhtml2pdf>=0.2.4
sentry-sdk[quart]>=1.5.7,<2.15
sentry-sdk[quart]>=1.5.7,<2.0
python3-saml>=1.15,<1.17
google-auth>=2.6,<2.30

Expand Down

0 comments on commit 8daa99a

Please sign in to comment.