Skip to content

Commit

Permalink
fix(api): Deprecate configure_scope (#3351)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
szokeasaurusrex committed Jul 26, 2024
1 parent 1d17d57 commit 6f11f50
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
9 changes: 9 additions & 0 deletions sentry_sdk/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import inspect
import warnings
from contextlib import contextmanager

from sentry_sdk import tracing_utils, Client
Expand Down Expand Up @@ -185,6 +186,14 @@ def configure_scope( # noqa: F811
:returns: If no callback is provided, returns a context manager that returns the scope.
"""
warnings.warn(
"sentry_sdk.configure_scope is deprecated and will be removed in the next major version. "
"Please consult our migration guide to learn how to migrate to the new API: "
"https://docs.sentry.io/platforms/python/migration/1.x-to-2.x#scope-configuring",
DeprecationWarning,
stacklevel=2,
)

scope = Scope.get_isolation_scope()
scope.generate_propagation_context()

Expand Down
7 changes: 7 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
is_initialized,
start_transaction,
set_tags,
configure_scope,
)

from sentry_sdk.client import Client, NonRecordingClient
Expand Down Expand Up @@ -179,3 +180,9 @@ def test_set_tags(sentry_init, capture_events):
"tag2": "updated",
"tag3": "new",
}, "Updating tags with empty dict changed tags"


def test_configure_scope_deprecation():
with pytest.warns(DeprecationWarning):
with configure_scope():
...
4 changes: 3 additions & 1 deletion tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,9 @@ def capture_envelope(self, envelope):
assert output.count(b"HI") == num_messages


def test_configure_scope_available(sentry_init, request, monkeypatch):
def test_configure_scope_available(
sentry_init, request, monkeypatch, suppress_deprecation_warnings
):
"""
Test that scope is configured if client is configured
Expand Down

0 comments on commit 6f11f50

Please sign in to comment.