Skip to content

Commit

Permalink
Fix CeleryInteration when sentry is used (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
caspervdw authored Oct 10, 2024
1 parent fba464e commit bd988bc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## 0.17.2 (unreleased)
----------------------

- Nothing changed yet.
- Fixed context forwarding to celery tasks in case Sentry is used.


## 0.17.1 (2024-10-01)
Expand Down
23 changes: 23 additions & 0 deletions clean_python/celery/config.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import logging

from celery import Celery
from celery import current_app
from celery.signals import worker_process_init

from clean_python import Json
from clean_python import ValueObject
from clean_python.celery import BaseTask

__all__ = ["CeleryConfig"]

logger = logging.getLogger(__name__)


class CeleryConfig(ValueObject):
timezone: str = "Europe/Amsterdam"
Expand All @@ -29,3 +34,21 @@ def apply(self, strict_typing: bool = True) -> Celery:
app.strict_typing = strict_typing
app.config_from_object(self)
return app


@worker_process_init.connect
def worker_init(**kwargs):
# Fix Sentry configuration (if inplace)
try:
import sentry_sdk
from sentry_sdk.integrations.celery import CeleryIntegration

integration = sentry_sdk.get_client().get_integration(CeleryIntegration)
if integration is not None and integration.propagate_traces:
integration.propagate_traces = False
logger.warning(
"Automatically disabled Sentry's trace propagation. "
"Set CeleryIntegration(propagate_traces=False) to disable this warning."
)
except ImportError:
pass

0 comments on commit bd988bc

Please sign in to comment.