Skip to content

feat(api): Remove sentry_sdk.push_scope #3408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,4 @@ Client Management
Managing Scope (advanced)
=========================

.. autofunction:: sentry_sdk.api.push_scope

.. autofunction:: sentry_sdk.api.new_scope
1 change: 0 additions & 1 deletion sentry_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"isolation_scope",
"last_event_id",
"new_scope",
"push_scope",
"set_context",
"set_extra",
"set_level",
Expand Down
56 changes: 1 addition & 55 deletions sentry_sdk/api.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import inspect
import warnings

from sentry_sdk import tracing_utils, Client
from sentry_sdk._init_implementation import init
from sentry_sdk.scope import Scope, _ScopeManager, new_scope, isolation_scope
from sentry_sdk.scope import Scope, new_scope, isolation_scope
from sentry_sdk.tracing import NoOpSpan, Transaction, trace
from sentry_sdk.crons import monitor

Expand All @@ -16,10 +15,8 @@
from typing import Any
from typing import Dict
from typing import Optional
from typing import overload
from typing import Callable
from typing import TypeVar
from typing import ContextManager
from typing import Union

from typing_extensions import Unpack
Expand All @@ -39,11 +36,6 @@

T = TypeVar("T")
F = TypeVar("F", bound=Callable[..., Any])
else:

def overload(x):
# type: (T) -> T
return x


# When changing this, update __all__ in __init__.py too
Expand All @@ -66,7 +58,6 @@ def overload(x):
"isolation_scope",
"last_event_id",
"new_scope",
"push_scope",
"set_context",
"set_extra",
"set_level",
Expand Down Expand Up @@ -191,51 +182,6 @@ def add_breadcrumb(
return get_isolation_scope().add_breadcrumb(crumb, hint, **kwargs)


@overload
def push_scope():
# type: () -> ContextManager[Scope]
pass


@overload
def push_scope( # noqa: F811
callback, # type: Callable[[Scope], None]
):
# type: (...) -> None
pass


def push_scope( # noqa: F811
callback=None, # type: Optional[Callable[[Scope], None]]
):
# type: (...) -> Optional[ContextManager[Scope]]
"""
Pushes a new layer on the scope stack.

:param callback: If provided, this method pushes a scope, calls
`callback`, and pops the scope again.

:returns: If no `callback` is provided, a context manager that should
be used to pop the scope again.
"""
warnings.warn(
"sentry_sdk.push_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-pushing",
DeprecationWarning,
stacklevel=2,
)

if callback is not None:
with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning)
with push_scope() as scope:
callback(scope)
return None

return _ScopeManager()


@scopemethod
def set_tag(key, value):
# type: (str, Any) -> None
Expand Down
29 changes: 0 additions & 29 deletions tests/new_scopes_compat/test_new_scopes_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,6 @@
"""


def test_push_scope_sdk1(sentry_init, capture_events):
"""
Mutate data in a `with push_scope` block

Checks the results of SDK 2.x against the results the same code returned in SDK 1.x.
"""
sentry_init()

events = capture_events()

sentry_sdk.set_tag("A", 1)
sentry_sdk.capture_message("Event A")

with sentry_sdk.push_scope() as scope: # push scope
sentry_sdk.set_tag("B1", 1)
scope.set_tag("B2", 1)
sentry_sdk.capture_message("Event B")

sentry_sdk.set_tag("Z", 1)
sentry_sdk.capture_message("Event Z")

(event_a, event_b, event_z) = events

# Check against the results the same code returned in SDK 1.x
assert event_a["tags"] == {"A": 1}
assert event_b["tags"] == {"A": 1, "B1": 1, "B2": 1}
assert event_z["tags"] == {"A": 1, "Z": 1}


def test_with_hub_sdk1(sentry_init, capture_events):
"""
Mutate data in a `with Hub:` block
Expand Down
Loading
Loading