Skip to content

Commit

Permalink
[file-processing-refactor] addresses starlette bug via a really bad n…
Browse files Browse the repository at this point in the history
…uclear option.
  • Loading branch information
biblicabeebli committed Mar 22, 2024
1 parent 26bd3cc commit 959132a
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion config/django_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sentry_sdk
from django.core.exceptions import ImproperlyConfigured
from sentry_sdk.integrations.django import DjangoIntegration
from sentry_sdk.integrations.celery import CeleryIntegration

from config import DB_MODE, DB_MODE_POSTGRES, DB_MODE_SQLITE
from config.settings import DOMAIN_NAME, FLASK_SECRET_KEY, SENTRY_ELASTIC_BEANSTALK_DSN
Expand Down Expand Up @@ -155,7 +156,6 @@
},
]


# json serializer crashes with module object does not have attribute .dumps
# or it cannot serialize a datetime object.
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
Expand All @@ -173,17 +173,40 @@

# enable Sentry error reporting
our_sentry_dsn = normalize_sentry_dsn(SENTRY_ELASTIC_BEANSTALK_DSN)

# We encounter the starlette integration bug _at least_ when running tasks in celery.
# https://github.com/getsentry/sentry-python/issues/1603
# None of the fixes work, so we are going with the nuclear option of purging the integration from
# _AUTO_ENABLING_INTEGRATIONS inside the integrations code. This is very bad form, but without it
# file processing errors in a weird/unpredictable way. (Possibly after the first page of data? it's
# not clear.)
from sentry_sdk.integrations import _AUTO_ENABLING_INTEGRATIONS
if "sentry_sdk.integrations.starlette.StarletteIntegration" not in _AUTO_ENABLING_INTEGRATIONS:
raise ImproperlyConfigured(
"We have a bug where the starlette integration is getting auto enabling and then raising "
"an error. There is no good option here, but this message is better than the next line"
"failing. Sorry future person!"
)
_AUTO_ENABLING_INTEGRATIONS.remove("sentry_sdk.integrations.starlette.StarletteIntegration")

# Ok now we can
sentry_sdk.init(
dsn=our_sentry_dsn,
enable_tracing=False,
ignore_errors=["WorkerLostError", "DisallowedHost"],
# auto_enabling_integrations=False, # this was one of the fixes for the starlette bug that didn't work.
integrations=[
DjangoIntegration(
transaction_style='url',
middleware_spans=False,
signals_spans=False,
cache_spans=False,
),
CeleryIntegration(
propagate_traces=False,
monitor_beat_tasks=False,
exclude_beat_tasks=True
)
],
)

Expand Down

0 comments on commit 959132a

Please sign in to comment.