From 0870caa161390a7add7aff9865f75e80fd7698ce Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Fri, 6 Jun 2025 15:14:37 +0200 Subject: [PATCH 1/2] ref: Remove `propagate_hub` to `ThreadingIntegration` This parameter is deprecated as of Sentry SDK 2.0.0; the default value is now `True`, so passing this parameter is no longer needed. --- src/sentry/utils/sdk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sentry/utils/sdk.py b/src/sentry/utils/sdk.py index 503118b8b1eedf..72fad9fb457761 100644 --- a/src/sentry/utils/sdk.py +++ b/src/sentry/utils/sdk.py @@ -490,7 +490,7 @@ def flush( LoggingIntegration(event_level=None, sentry_logs_level=logging.INFO), RustInfoIntegration(), RedisIntegration(), - ThreadingIntegration(propagate_hub=True), + ThreadingIntegration(), ], **sdk_options, ) From 102cb523f9d7473ad7bd465b380d591f23a90c85 Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Fri, 6 Jun 2025 15:20:46 +0200 Subject: [PATCH 2/2] ref(sdk): Use top-level `get_current_scope` Using `sentry_sdk.Scope.get_current_scope` has been deprecated in favor of `sentry_sdk.get_current_scope`. Going forward, we generally would like SDK users to stick to the top-level APIs. Split off from #92011. --- src/sentry/cache/base.py | 2 +- .../integrations/web/organization_integration_setup.py | 2 +- src/sentry/scim/endpoints/utils.py | 2 +- src/sentry/utils/concurrent.py | 2 +- src/sentry/utils/sdk.py | 2 +- src/sentry/utils/snuba.py | 6 +++--- src/sentry/utils/snuba_rpc.py | 6 ++---- tests/sentry/utils/test_sdk.py | 4 ++-- 8 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/sentry/cache/base.py b/src/sentry/cache/base.py index bbbf28ca961316..80855281e93949 100644 --- a/src/sentry/cache/base.py +++ b/src/sentry/cache/base.py @@ -46,7 +46,7 @@ def _mark_transaction(self, op): if not self.is_default_cache: return - scope = sentry_sdk.Scope.get_current_scope() + scope = sentry_sdk.get_current_scope() # Do not set this tag if we're in the global scope (which roughly # equates to having a transaction). if scope.transaction: diff --git a/src/sentry/integrations/web/organization_integration_setup.py b/src/sentry/integrations/web/organization_integration_setup.py index fc207e76199eee..2b583a22ae2b2e 100644 --- a/src/sentry/integrations/web/organization_integration_setup.py +++ b/src/sentry/integrations/web/organization_integration_setup.py @@ -21,7 +21,7 @@ class OrganizationIntegrationSetupView(ControlSiloOrganizationView): csrf_protect = False def handle(self, request: HttpRequest, organization, provider_id) -> HttpResponseBase: - scope = sentry_sdk.Scope.get_current_scope() + scope = sentry_sdk.get_current_scope() scope.set_transaction_name(f"integration.{provider_id}", source=TransactionSource.VIEW) pipeline = IntegrationPipeline( diff --git a/src/sentry/scim/endpoints/utils.py b/src/sentry/scim/endpoints/utils.py index b40562e373f7ec..c73c549882d0d7 100644 --- a/src/sentry/scim/endpoints/utils.py +++ b/src/sentry/scim/endpoints/utils.py @@ -25,7 +25,7 @@ class SCIMApiError(APIException): def __init__(self, detail, status_code=400): - transaction = sentry_sdk.Scope.get_current_scope().transaction + transaction = sentry_sdk.get_current_scope().transaction if transaction is not None: transaction.set_tag("http.status_code", status_code) super().__init__({"schemas": [SCIM_API_ERROR], "detail": detail}) diff --git a/src/sentry/utils/concurrent.py b/src/sentry/utils/concurrent.py index 82e1b706d2fa47..5d09bc92431d97 100644 --- a/src/sentry/utils/concurrent.py +++ b/src/sentry/utils/concurrent.py @@ -248,7 +248,7 @@ def submit[ priority, ( sentry_sdk.Scope.get_isolation_scope(), - sentry_sdk.Scope.get_current_scope(), + sentry_sdk.get_current_scope(), callable, future, ), diff --git a/src/sentry/utils/sdk.py b/src/sentry/utils/sdk.py index 72fad9fb457761..bf9d8057604ffa 100644 --- a/src/sentry/utils/sdk.py +++ b/src/sentry/utils/sdk.py @@ -584,7 +584,7 @@ def check_current_scope_transaction( Note: Ignores scope `transaction` values with `source = "custom"`, indicating a value which has been set maunually. """ - scope = sentry_sdk.Scope.get_current_scope() + scope = sentry_sdk.get_current_scope() transaction_from_request = get_transaction_name_from_request(request) if ( diff --git a/src/sentry/utils/snuba.py b/src/sentry/utils/snuba.py index d112d1e3902668..1a82826a7816ba 100644 --- a/src/sentry/utils/snuba.py +++ b/src/sentry/utils/snuba.py @@ -1091,7 +1091,7 @@ def _apply_cache_and_build_results( use_cache: bool | None = False, ) -> ResultSet: parent_api: str = "" - scope = sentry_sdk.Scope.get_current_scope() + scope = sentry_sdk.get_current_scope() if scope.transaction: parent_api = scope.transaction.name @@ -1162,7 +1162,7 @@ def _bulk_snuba_query(snuba_requests: Sequence[SnubaRequest]) -> ResultSet: [ ( sentry_sdk.Scope.get_isolation_scope(), - sentry_sdk.Scope.get_current_scope(), + sentry_sdk.get_current_scope(), snuba_request, ) for snuba_request in snuba_requests_list @@ -1175,7 +1175,7 @@ def _bulk_snuba_query(snuba_requests: Sequence[SnubaRequest]) -> ResultSet: _snuba_query( ( sentry_sdk.Scope.get_isolation_scope(), - sentry_sdk.Scope.get_current_scope(), + sentry_sdk.get_current_scope(), snuba_requests_list[0], ) ) diff --git a/src/sentry/utils/snuba_rpc.py b/src/sentry/utils/snuba_rpc.py index 42c92e4400f74f..bc66cc62d4fb87 100644 --- a/src/sentry/utils/snuba_rpc.py +++ b/src/sentry/utils/snuba_rpc.py @@ -123,7 +123,7 @@ def _make_rpc_requests( partial_request = partial( _make_rpc_request, thread_isolation_scope=sentry_sdk.Scope.get_isolation_scope(), - thread_current_scope=sentry_sdk.Scope.get_current_scope(), + thread_current_scope=sentry_sdk.get_current_scope(), ) response = [ result @@ -253,9 +253,7 @@ def _make_rpc_request( else thread_isolation_scope ) thread_current_scope = ( - sentry_sdk.Scope.get_current_scope() - if thread_current_scope is None - else thread_current_scope + sentry_sdk.get_current_scope() if thread_current_scope is None else thread_current_scope ) if SNUBA_INFO: from google.protobuf.json_format import MessageToJson diff --git a/tests/sentry/utils/test_sdk.py b/tests/sentry/utils/test_sdk.py index 1609caa4ed86d4..592547b863d681 100644 --- a/tests/sentry/utils/test_sdk.py +++ b/tests/sentry/utils/test_sdk.py @@ -216,7 +216,7 @@ def test_scope_has_correct_transaction(self, mock_resolve: MagicMock): mock_scope = Scope() mock_scope._transaction = "/dogs/{name}/" - with patch("sentry.utils.sdk.sentry_sdk.Scope.get_current_scope", return_value=mock_scope): + with patch("sentry.utils.sdk.sentry_sdk.get_current_scope", return_value=mock_scope): mismatch = check_current_scope_transaction(Request(HttpRequest())) assert mismatch is None @@ -225,7 +225,7 @@ def test_scope_has_wrong_transaction(self, mock_resolve: MagicMock): mock_scope = Scope() mock_scope._transaction = "/tricks/{trick_name}/" - with patch("sentry.utils.sdk.sentry_sdk.Scope.get_current_scope", return_value=mock_scope): + with patch("sentry.utils.sdk.sentry_sdk.get_current_scope", return_value=mock_scope): mismatch = check_current_scope_transaction(Request(HttpRequest())) assert mismatch == { "scope_transaction": "/tricks/{trick_name}/",