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

feat: add support for sentry>2 Celery integration #137

Merged
merged 3 commits into from
Mar 27, 2025
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
14 changes: 10 additions & 4 deletions django_guid/integrations/celery/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ def set_transaction_id(guid: str) -> None:
Sets the Sentry transaction ID if the Celery sentry integration setting is True.
"""
if settings.integration_settings.celery.sentry_integration:
from sentry_sdk import configure_scope
import sentry_sdk
from packaging import version

with configure_scope() as scope:
logger.debug('Setting Sentry transaction_id to %s', guid)
scope.set_tag('transaction_id', guid)
if version.parse(sentry_sdk.VERSION) >= version.parse('2.12.0'):
with sentry_sdk.isolation_scope() as scope:
scope.set_tag('transaction_id', guid)
else:
with sentry_sdk.configure_scope() as scope:
scope.set_tag('transaction_id', guid)

logger.debug('Setting Sentry transaction_id to %s', guid)


@before_task_publish.connect
Expand Down
5 changes: 3 additions & 2 deletions django_guid/integrations/sentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ def run(self, guid: str, **kwargs: Any) -> None:
Sets the Sentry transaction_id.
"""
import sentry_sdk
from packaging import version

if sentry_sdk.VERSION >= '2.0.0':
if version.parse(sentry_sdk.VERSION) >= version.parse('2.12.0'):
with sentry_sdk.isolation_scope() as scope:
scope.set_tag('transaction_id', guid)
else:
with sentry_sdk.configure_scope() as scope:
scope.set_tag('transaction_id', guid)

logger.debug(f'Setting Sentry transaction_id to {guid}')
logger.debug('Setting Sentry transaction_id to %s', guid)
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ django = [
{ version = "^4.0", python = ">=3.8,<3.10" },
{ version = "^4.0 | ^5.0", python = ">=3.10" }
]
packaging = "*"


[tool.poetry.group.dev.dependencies]
Expand Down