From ab5d8a797e1b6ca217f022f3e7aec1cdb69f3805 Mon Sep 17 00:00:00 2001 From: Neel Shah Date: Fri, 10 Jan 2025 14:39:24 +0100 Subject: [PATCH] Setup scopes before client (#3916) The newly added feature flags add an error processor to `current_scope` in their `setup_once`. This is actually an antipattern and shouldn't be encouraged. Either way, this PR sets up the scopes first since the integrations get setup in the `Client` and require that scope to be correct. --- sentry_sdk/_init_implementation.py | 2 +- tests/conftest.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sentry_sdk/_init_implementation.py b/sentry_sdk/_init_implementation.py index 74bbd9a20f..4ad110ab56 100644 --- a/sentry_sdk/_init_implementation.py +++ b/sentry_sdk/_init_implementation.py @@ -23,9 +23,9 @@ def _init(*args, **kwargs): This takes the same arguments as the client constructor. """ + setup_scope_context_management() client = sentry_sdk.Client(*args, **kwargs) sentry_sdk.get_global_scope().set_client(client) - setup_scope_context_management() _check_python_deprecations() diff --git a/tests/conftest.py b/tests/conftest.py index 70f86b6905..d067e04eb5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -199,10 +199,10 @@ def inner(identifier): @pytest.fixture def sentry_init(request): def inner(*a, **kw): + setup_scope_context_management() kw.setdefault("transport", TestTransport()) client = sentry_sdk.Client(*a, **kw) sentry_sdk.get_global_scope().set_client(client) - setup_scope_context_management() if request.node.get_closest_marker("forked"): # Do not run isolation if the test is already running in