Skip to content

Commit 6f11f50

Browse files
fix(api): Deprecate configure_scope (#3351)
Although `configure_scope` was meant to be deprecated since Sentry SDK 2.0.0, calling `configure_scope` did not raise a deprecation warning. Now, it does. Fixes #3346
1 parent 1d17d57 commit 6f11f50

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

sentry_sdk/api.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import inspect
2+
import warnings
23
from contextlib import contextmanager
34

45
from sentry_sdk import tracing_utils, Client
@@ -185,6 +186,14 @@ def configure_scope( # noqa: F811
185186
186187
:returns: If no callback is provided, returns a context manager that returns the scope.
187188
"""
189+
warnings.warn(
190+
"sentry_sdk.configure_scope is deprecated and will be removed in the next major version. "
191+
"Please consult our migration guide to learn how to migrate to the new API: "
192+
"https://docs.sentry.io/platforms/python/migration/1.x-to-2.x#scope-configuring",
193+
DeprecationWarning,
194+
stacklevel=2,
195+
)
196+
188197
scope = Scope.get_isolation_scope()
189198
scope.generate_propagation_context()
190199

tests/test_api.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
is_initialized,
1212
start_transaction,
1313
set_tags,
14+
configure_scope,
1415
)
1516

1617
from sentry_sdk.client import Client, NonRecordingClient
@@ -179,3 +180,9 @@ def test_set_tags(sentry_init, capture_events):
179180
"tag2": "updated",
180181
"tag3": "new",
181182
}, "Updating tags with empty dict changed tags"
183+
184+
185+
def test_configure_scope_deprecation():
186+
with pytest.warns(DeprecationWarning):
187+
with configure_scope():
188+
...

tests/test_client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,9 @@ def capture_envelope(self, envelope):
570570
assert output.count(b"HI") == num_messages
571571

572572

573-
def test_configure_scope_available(sentry_init, request, monkeypatch):
573+
def test_configure_scope_available(
574+
sentry_init, request, monkeypatch, suppress_deprecation_warnings
575+
):
574576
"""
575577
Test that scope is configured if client is configured
576578

0 commit comments

Comments
 (0)