diff --git a/asgi_correlation_id/extensions/sentry.py b/asgi_correlation_id/extensions/sentry.py index 0e3c174..cd314e9 100644 --- a/asgi_correlation_id/extensions/sentry.py +++ b/asgi_correlation_id/extensions/sentry.py @@ -23,8 +23,9 @@ def set_transaction_id(correlation_id: str) -> None: which makes it easier to correlate logs to specific events. """ import sentry_sdk + from packaging import version - if sentry_sdk.VERSION >= '2.12.0': + if version.parse(sentry_sdk.VERSION) >= version.parse('2.12.0'): scope = sentry_sdk.get_isolation_scope() scope.set_tag('transaction_id', correlation_id) else: diff --git a/tests/test_extension_sentry.py b/tests/test_extension_sentry.py index 496bdd2..0fd438a 100644 --- a/tests/test_extension_sentry.py +++ b/tests/test_extension_sentry.py @@ -1,4 +1,5 @@ from unittest.mock import Mock +from packaging import version import sentry_sdk @@ -11,7 +12,7 @@ def test_sentry_sdk_installed(mocker): """ Check that the scope.set_tag method is called when Sentry is installed. """ - if sentry_sdk.VERSION >= '2.12.0': + if version.parse(sentry_sdk.VERSION) >= version.parse('2.12.0'): set_tag_mock = Mock() scope_mock = Mock() scope_mock.set_tag = set_tag_mock