Skip to content

Commit 3671a70

Browse files
feat(api): Remove sentry_sdk.configure_scope
Also, remove any tests for `sentry_sdk.configure_scope`. BREAKING CHANGE: Remove `sentry_sdk.configure_scope`. Closes: #3402
1 parent 81cdbd4 commit 3671a70

File tree

6 files changed

+2
-243
lines changed

6 files changed

+2
-243
lines changed

sentry_sdk/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"capture_event",
2020
"capture_exception",
2121
"capture_message",
22-
"configure_scope",
2322
"continue_trace",
2423
"flush",
2524
"get_baggage",

sentry_sdk/api.py

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import inspect
22
import warnings
3-
from contextlib import contextmanager
43

54
from sentry_sdk import tracing_utils, Client
65
from sentry_sdk._init_implementation import init
@@ -16,7 +15,6 @@
1615

1716
from typing import Any
1817
from typing import Dict
19-
from typing import Generator
2018
from typing import Optional
2119
from typing import overload
2220
from typing import Callable
@@ -55,7 +53,6 @@ def overload(x):
5553
"capture_event",
5654
"capture_exception",
5755
"capture_message",
58-
"configure_scope",
5956
"continue_trace",
6057
"flush",
6158
"get_baggage",
@@ -194,56 +191,6 @@ def add_breadcrumb(
194191
return get_isolation_scope().add_breadcrumb(crumb, hint, **kwargs)
195192

196193

197-
@overload
198-
def configure_scope():
199-
# type: () -> ContextManager[Scope]
200-
pass
201-
202-
203-
@overload
204-
def configure_scope( # noqa: F811
205-
callback, # type: Callable[[Scope], None]
206-
):
207-
# type: (...) -> None
208-
pass
209-
210-
211-
def configure_scope( # noqa: F811
212-
callback=None, # type: Optional[Callable[[Scope], None]]
213-
):
214-
# type: (...) -> Optional[ContextManager[Scope]]
215-
"""
216-
Reconfigures the scope.
217-
218-
:param callback: If provided, call the callback with the current scope.
219-
220-
:returns: If no callback is provided, returns a context manager that returns the scope.
221-
"""
222-
warnings.warn(
223-
"sentry_sdk.configure_scope is deprecated and will be removed in the next major version. "
224-
"Please consult our migration guide to learn how to migrate to the new API: "
225-
"https://docs.sentry.io/platforms/python/migration/1.x-to-2.x#scope-configuring",
226-
DeprecationWarning,
227-
stacklevel=2,
228-
)
229-
230-
scope = get_isolation_scope()
231-
scope.generate_propagation_context()
232-
233-
if callback is not None:
234-
# TODO: used to return None when client is None. Check if this changes behavior.
235-
callback(scope)
236-
237-
return None
238-
239-
@contextmanager
240-
def inner():
241-
# type: () -> Generator[Scope, None, None]
242-
yield scope
243-
244-
return inner()
245-
246-
247194
@overload
248195
def push_scope():
249196
# type: () -> ContextManager[Scope]

tests/new_scopes_compat/test_new_scopes_compat.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,6 @@
1111
"""
1212

1313

14-
def test_configure_scope_sdk1(sentry_init, capture_events):
15-
"""
16-
Mutate data in a `with configure_scope` block.
17-
18-
Checks the results of SDK 2.x against the results the same code returned in SDK 1.x.
19-
"""
20-
sentry_init()
21-
22-
events = capture_events()
23-
24-
sentry_sdk.set_tag("A", 1)
25-
sentry_sdk.capture_message("Event A")
26-
27-
with sentry_sdk.configure_scope() as scope: # configure scope
28-
sentry_sdk.set_tag("B1", 1)
29-
scope.set_tag("B2", 1)
30-
sentry_sdk.capture_message("Event B")
31-
32-
sentry_sdk.set_tag("Z", 1)
33-
sentry_sdk.capture_message("Event Z")
34-
35-
(event_a, event_b, event_z) = events
36-
37-
# Check against the results the same code returned in SDK 1.x
38-
assert event_a["tags"] == {"A": 1}
39-
assert event_b["tags"] == {"A": 1, "B1": 1, "B2": 1}
40-
assert event_z["tags"] == {"A": 1, "B1": 1, "B2": 1, "Z": 1}
41-
42-
4314
def test_push_scope_sdk1(sentry_init, capture_events):
4415
"""
4516
Mutate data in a `with push_scope` block

tests/new_scopes_compat/test_new_scopes_compat_event.py

Lines changed: 1 addition & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -335,71 +335,6 @@ def test_event(sentry_init, capture_envelopes, expected_error, expected_transact
335335

336336
envelopes = capture_envelopes()
337337

338-
with sentry_sdk.start_transaction(
339-
name="test_transaction", op="test_transaction_op"
340-
) as trx:
341-
with sentry_sdk.start_span(op="test_span") as span:
342-
with sentry_sdk.configure_scope() as scope: # configure scope
343-
_generate_event_data(scope)
344-
_faulty_function()
345-
346-
(error_envelope, transaction_envelope) = envelopes
347-
348-
error = error_envelope.get_event()
349-
transaction = transaction_envelope.get_transaction_event()
350-
attachment = error_envelope.items[-1]
351-
352-
assert error == expected_error(trx, span)
353-
assert transaction == expected_transaction(trx, span)
354-
assert attachment.headers == {
355-
"filename": "hello.txt",
356-
"type": "attachment",
357-
"content_type": "text/plain",
358-
}
359-
assert attachment.payload.bytes == b"Hello World"
360-
361-
362-
def test_event2(sentry_init, capture_envelopes, expected_error, expected_transaction):
363-
_init_sentry_sdk(sentry_init)
364-
365-
envelopes = capture_envelopes()
366-
367-
with Hub(Hub.current):
368-
sentry_sdk.set_tag("A", 1) # will not be added
369-
370-
with Hub.current: # with hub
371-
with sentry_sdk.push_scope() as scope:
372-
scope.set_tag("B", 1) # will not be added
373-
374-
with sentry_sdk.start_transaction(
375-
name="test_transaction", op="test_transaction_op"
376-
) as trx:
377-
with sentry_sdk.start_span(op="test_span") as span:
378-
with sentry_sdk.configure_scope() as scope: # configure scope
379-
_generate_event_data(scope)
380-
_faulty_function()
381-
382-
(error_envelope, transaction_envelope) = envelopes
383-
384-
error = error_envelope.get_event()
385-
transaction = transaction_envelope.get_transaction_event()
386-
attachment = error_envelope.items[-1]
387-
388-
assert error == expected_error(trx, span)
389-
assert transaction == expected_transaction(trx, span)
390-
assert attachment.headers == {
391-
"filename": "hello.txt",
392-
"type": "attachment",
393-
"content_type": "text/plain",
394-
}
395-
assert attachment.payload.bytes == b"Hello World"
396-
397-
398-
def test_event3(sentry_init, capture_envelopes, expected_error, expected_transaction):
399-
_init_sentry_sdk(sentry_init)
400-
401-
envelopes = capture_envelopes()
402-
403338
with Hub(Hub.current):
404339
sentry_sdk.set_tag("A", 1) # will not be added
405340

@@ -431,43 +366,7 @@ def test_event3(sentry_init, capture_envelopes, expected_error, expected_transac
431366
assert attachment.payload.bytes == b"Hello World"
432367

433368

434-
def test_event4(sentry_init, capture_envelopes, expected_error, expected_transaction):
435-
_init_sentry_sdk(sentry_init)
436-
437-
envelopes = capture_envelopes()
438-
439-
with Hub(Hub.current):
440-
sentry_sdk.set_tag("A", 1) # will not be added
441-
442-
with Hub(Hub.current): # with hub clone
443-
with sentry_sdk.push_scope() as scope:
444-
scope.set_tag("B", 1) # will not be added
445-
446-
with sentry_sdk.start_transaction(
447-
name="test_transaction", op="test_transaction_op"
448-
) as trx:
449-
with sentry_sdk.start_span(op="test_span") as span:
450-
with sentry_sdk.configure_scope() as scope: # configure scope
451-
_generate_event_data(scope)
452-
_faulty_function()
453-
454-
(error_envelope, transaction_envelope) = envelopes
455-
456-
error = error_envelope.get_event()
457-
transaction = transaction_envelope.get_transaction_event()
458-
attachment = error_envelope.items[-1]
459-
460-
assert error == expected_error(trx, span)
461-
assert transaction == expected_transaction(trx, span)
462-
assert attachment.headers == {
463-
"filename": "hello.txt",
464-
"type": "attachment",
465-
"content_type": "text/plain",
466-
}
467-
assert attachment.payload.bytes == b"Hello World"
468-
469-
470-
def test_event5(sentry_init, capture_envelopes, expected_error, expected_transaction):
369+
def test_event2(sentry_init, capture_envelopes, expected_error, expected_transaction):
471370
_init_sentry_sdk(sentry_init)
472371

473372
envelopes = capture_envelopes()

tests/test_api.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
is_initialized,
1212
start_transaction,
1313
set_tags,
14-
configure_scope,
1514
push_scope,
1615
get_global_scope,
1716
get_current_scope,
@@ -185,12 +184,6 @@ def test_set_tags(sentry_init, capture_events):
185184
}, "Updating tags with empty dict changed tags"
186185

187186

188-
def test_configure_scope_deprecation():
189-
with pytest.warns(DeprecationWarning):
190-
with configure_scope():
191-
...
192-
193-
194187
def test_push_scope_deprecation():
195188
with pytest.warns(DeprecationWarning):
196189
with push_scope():

tests/test_client.py

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212

1313
import sentry_sdk
1414
from sentry_sdk import (
15-
Hub,
1615
Client,
1716
add_breadcrumb,
18-
configure_scope,
1917
capture_message,
2018
capture_exception,
2119
capture_event,
@@ -557,39 +555,12 @@ def capture_envelope(self, envelope):
557555
)
558556

559557
start = time.time()
560-
output = subprocess.check_output([sys.executable, str(app)])
558+
subprocess.check_output([sys.executable, str(app)])
561559
end = time.time()
562560

563561
# Each message takes at least 0.1 seconds to process
564562
assert int(end - start) >= num_messages / 10
565563

566-
assert output.count(b"HI") == num_messages
567-
568-
569-
def test_configure_scope_available(
570-
sentry_init, request, monkeypatch, suppress_deprecation_warnings
571-
):
572-
"""
573-
Test that scope is configured if client is configured
574-
575-
This test can be removed once configure_scope and the Hub are removed.
576-
"""
577-
sentry_init()
578-
579-
with configure_scope() as scope:
580-
assert scope is Hub.current.scope
581-
scope.set_tag("foo", "bar")
582-
583-
calls = []
584-
585-
def callback(scope):
586-
calls.append(scope)
587-
scope.set_tag("foo", "bar")
588-
589-
assert configure_scope(callback) is None
590-
assert len(calls) == 1
591-
assert calls[0] is Hub.current.scope
592-
593564

594565
@pytest.mark.tests_internal_exceptions
595566
def test_client_debug_option_enabled(sentry_init, caplog):
@@ -609,27 +580,6 @@ def test_client_debug_option_disabled(with_client, sentry_init, caplog):
609580
assert "OK" not in caplog.text
610581

611582

612-
@pytest.mark.skip(
613-
reason="New behavior in SDK 2.0: You have a scope before init and add data to it."
614-
)
615-
def test_scope_initialized_before_client(sentry_init, capture_events):
616-
"""
617-
This is a consequence of how configure_scope() works. We must
618-
make `configure_scope()` a noop if no client is configured. Even
619-
if the user later configures a client: We don't know that.
620-
"""
621-
with configure_scope() as scope:
622-
scope.set_tag("foo", 42)
623-
624-
sentry_init()
625-
626-
events = capture_events()
627-
capture_message("hi")
628-
(event,) = events
629-
630-
assert "tags" not in event
631-
632-
633583
def test_weird_chars(sentry_init, capture_events):
634584
sentry_init()
635585
events = capture_events()

0 commit comments

Comments
 (0)