Skip to content

Commit 94ce314

Browse files
authored
chore: Drop more deprecated stuff (#7263)
Changes: - remove deprecated `max_spans` option of `LangchainIntegration` - remove deprecated `sentry_sdk.init()` context manager - remove deprecated `configure_debug_hub` - remove deprecated `Baggage.from_options()` - remove deprecated `Transport.capture_event()` - remove deprecated `FunctionTransport` - the `Scope.trace_propagation_meta` function no longer accepts a `span` as argument - remove deprecated direct assignment to `Scope.level` - remove deprecated direct assignment to `Scope.user` - remove deprecated `Scope.iter_headers` Closes https://linear.app/getsentry/issue/PY-1935/drop-deprecated-stuff
1 parent 0536be0 commit 94ce314

11 files changed

Lines changed: 26 additions & 228 deletions

File tree

MIGRATION_GUIDE.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
2424
- The UnraisableHookIntegration is now enabled by default.
2525
- We now don't suppress chained exceptions in the ASGI and asyncio integrations by default. The related `suppress_asgi_chained_exceptions` experimental option was removed.
2626
- In the AWS Lambda and GCP integrations, the message of the warning the SDK optionally emits if a function is about to time out has changed.
27+
- `sentry_sdk.init()` can no longer be used as a context manager.
2728

2829
### Logging
2930

@@ -145,9 +146,19 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
145146
- The deprecated `propagate_traces` option has been removed. Use `trace_propagation_targets` instead, which gives you more power over trace propagation. Note that only the top-level `init` option was removed; the `propagate_traces` option of the Celery integration remains available.
146147
- Removed Spotlight integration for Django. See [Spotlight 2.0](https://github.com/getsentry/spotlight/issues/891) for more context.
147148
- The deprecated parameter `propagate_hub` in `ThreadingIntegration()` was removed.
149+
- `configure_debug_hub` was removed.
150+
- The `max_spans` option of the `LangchainIntegration` was removed.
151+
- `Baggage.from_options` was removed.
152+
- `Transport.capture_event` was removed. Use `Transport.capture_envelope` instead.
153+
- Function transports were removed.
154+
- The `Scope.trace_propagation_meta` function no longer accepts a `span` as argument.
155+
- Direct assignment to `Scope.level` was removed. Use `Scope.set_level` instead.
156+
- Direct assignment to `Scope.user` was removed. Use `Scope.set_user` instead.
157+
- `Scope.iter_headers` was removed.
148158
- The SDK won't set any tags on its own anymore.
149159
- The `update_current_span` API was removed.
150160

161+
151162
## Deprecated
152163

153164

sentry_sdk/_init_implementation.py

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,15 @@
11
import re
2-
import warnings
32
from typing import TYPE_CHECKING
43

54
import sentry_sdk
65
from sentry_sdk.utils import logger, parse_version
76

87
if TYPE_CHECKING:
9-
from typing import Any, ContextManager, Optional
8+
from typing import Any, Optional
109

1110
import sentry_sdk.consts
1211

1312

14-
class _InitGuard:
15-
_CONTEXT_MANAGER_DEPRECATION_WARNING_MESSAGE = (
16-
"Using the return value of sentry_sdk.init as a context manager "
17-
"and manually calling the __enter__ and __exit__ methods on the "
18-
"return value are deprecated. We are no longer maintaining this "
19-
"functionality, and we will remove it in the next major release."
20-
)
21-
22-
def __init__(self, client: "sentry_sdk.Client") -> None:
23-
self._client = client
24-
25-
def __enter__(self) -> "_InitGuard":
26-
warnings.warn(
27-
self._CONTEXT_MANAGER_DEPRECATION_WARNING_MESSAGE,
28-
stacklevel=2,
29-
category=DeprecationWarning,
30-
)
31-
32-
return self
33-
34-
def __exit__(self, exc_type: "Any", exc_value: "Any", tb: "Any") -> None:
35-
warnings.warn(
36-
self._CONTEXT_MANAGER_DEPRECATION_WARNING_MESSAGE,
37-
stacklevel=2,
38-
category=DeprecationWarning,
39-
)
40-
41-
c = self._client
42-
if c is not None:
43-
c.close()
44-
45-
4613
def _check_version_deprecations() -> None:
4714
try:
4815
import gevent
@@ -71,26 +38,23 @@ def _check_version_deprecations() -> None:
7138
pass
7239

7340

74-
def _init(*args: "Optional[str]", **kwargs: "Any") -> "ContextManager[Any]":
41+
def _init(*args: "Optional[str]", **kwargs: "Any") -> None:
7542
"""Initializes the SDK and optionally integrations.
7643
7744
This takes the same arguments as the client constructor.
7845
"""
7946
client = sentry_sdk.Client(*args, **kwargs)
8047
sentry_sdk.get_global_scope().set_client(client)
8148
_check_version_deprecations()
82-
rv = _InitGuard(client)
83-
return rv
8449

8550

8651
if TYPE_CHECKING:
8752
# Make mypy, PyCharm and other static analyzers think `init` is a type to
8853
# have nicer autocompletion for params.
8954
#
90-
# Use `ClientConstructor` to define the argument types of `init` and
91-
# `ContextManager[Any]` to tell static analyzers about the return type.
55+
# Use `ClientConstructor` to define the argument types of `init`.
9256

93-
class init(sentry_sdk.consts.ClientConstructor, _InitGuard): # noqa: N801
57+
class init(sentry_sdk.consts.ClientConstructor): # noqa: N801
9458
pass
9559

9660
else:

sentry_sdk/consts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,7 @@ def __init__(
12931293
in_app_exclude: "List[str]" = [], # noqa: B006
12941294
default_integrations: bool = True,
12951295
dist: "Optional[str]" = None,
1296-
transport: "Optional[Union[sentry_sdk.transport.Transport, Type[sentry_sdk.transport.Transport], Callable[[Event], None]]]" = None,
1296+
transport: "Optional[Union[sentry_sdk.transport.Transport, Type[sentry_sdk.transport.Transport], None]]" = None,
12971297
transport_queue_size: int = DEFAULT_QUEUE_SIZE,
12981298
sample_rate: float = 1.0,
12991299
send_default_pii: "Optional[bool]" = None,

sentry_sdk/debug.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import logging
22
import sys
3-
import warnings
43
from logging import LogRecord
54

65
from sentry_sdk import get_client
@@ -27,11 +26,3 @@ def configure_logger() -> None:
2726
logger.addHandler(_handler)
2827
logger.setLevel(logging.DEBUG)
2928
logger.addFilter(_DebugFilter())
30-
31-
32-
def configure_debug_hub() -> None:
33-
warnings.warn(
34-
"configure_debug_hub is deprecated. Please remove calls to it, as it is a no-op.",
35-
DeprecationWarning,
36-
stacklevel=2,
37-
)

sentry_sdk/integrations/langchain.py

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import itertools
22
import json
33
import sys
4-
import warnings
54
from collections import OrderedDict
65
from functools import wraps
76
from typing import TYPE_CHECKING, NamedTuple
@@ -236,18 +235,8 @@ class LangchainIntegration(Integration):
236235
def __init__(
237236
self: "LangchainIntegration",
238237
include_prompts: bool = True,
239-
max_spans: "Optional[int]" = None,
240238
) -> None:
241239
self.include_prompts = include_prompts
242-
self.max_spans = max_spans
243-
244-
if max_spans is not None:
245-
warnings.warn(
246-
"The `max_spans` parameter of `LangchainIntegration` is "
247-
"deprecated and will be removed in version 3.0 of sentry-sdk.",
248-
DeprecationWarning,
249-
stacklevel=2,
250-
)
251240

252241
@staticmethod
253242
def setup_once() -> None:
@@ -274,19 +263,10 @@ def setup_once() -> None:
274263
class SentryLangchainCallback(BaseCallbackHandler):
275264
"""Callback handler that creates Sentry spans."""
276265

277-
def __init__(
278-
self, max_span_map_size: "Optional[int]", include_prompts: bool
279-
) -> None:
266+
def __init__(self, include_prompts: bool) -> None:
280267
self.span_map: "OrderedDict[UUID, Union[sentry_sdk.tracing.Span, StreamedSpan]]" = OrderedDict()
281-
self.max_span_map_size = max_span_map_size
282268
self.include_prompts = include_prompts
283269

284-
def gc_span_map(self) -> None:
285-
if self.max_span_map_size is not None:
286-
while len(self.span_map) > self.max_span_map_size:
287-
run_id, span = self.span_map.popitem(last=False)
288-
self._exit_span(span, run_id)
289-
290270
def _handle_error(self, run_id: "UUID", error: "Any") -> None:
291271
is_ignored = isinstance(error, tuple(LangchainIntegration._ignored_exceptions))
292272

@@ -356,7 +336,6 @@ def _create_span(
356336

357337
span.__enter__()
358338
self.span_map[run_id] = span
359-
self.gc_span_map()
360339
return span
361340

362341
def _exit_span(
@@ -1135,7 +1114,6 @@ def new_configure(
11351114
for cb in itertools.chain(callbacks_list, inheritable_callbacks_list)
11361115
):
11371116
sentry_handler = SentryLangchainCallback(
1138-
integration.max_spans,
11391117
integration.include_prompts,
11401118
)
11411119
if isinstance(local_callbacks, BaseCallbackManager):

sentry_sdk/scope.py

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
Deque,
6868
Dict,
6969
Generator,
70-
Iterator,
7170
List,
7271
Optional,
7372
ParamSpec,
@@ -572,18 +571,6 @@ def generate_propagation_context(
572571
if self._propagation_context is None:
573572
self.set_new_propagation_context()
574573

575-
def get_dynamic_sampling_context(self) -> "Optional[Dict[str, str]]":
576-
"""
577-
Returns the Dynamic Sampling Context from the Propagation Context.
578-
If not existing, creates a new one.
579-
580-
Deprecated: Logic moved to PropagationContext, don't use directly.
581-
"""
582-
if self._propagation_context is None:
583-
return None
584-
585-
return self._propagation_context.dynamic_sampling_context
586-
587574
def get_traceparent(self, *args: "Any", **kwargs: "Any") -> "Optional[str]":
588575
"""
589576
Returns the Sentry "sentry-trace" header (aka the traceparent) from the
@@ -655,27 +642,13 @@ def trace_propagation_meta(self, *args: "Any", **kwargs: "Any") -> str:
655642
Return meta tags which should be injected into HTML templates
656643
to allow propagation of trace information.
657644
"""
658-
span = kwargs.pop("span", None)
659-
if span is not None:
660-
logger.warning(
661-
"The parameter `span` in trace_propagation_meta() is deprecated and will be removed in the future."
662-
)
663-
664645
meta = ""
665646

666647
for name, content in self.iter_trace_propagation_headers():
667648
meta += f'<meta name="{name}" content="{content}">'
668649

669650
return meta
670651

671-
def iter_headers(self) -> "Iterator[Tuple[str, str]]":
672-
"""
673-
Creates a generator which returns the `sentry-trace` and `baggage` headers from the Propagation Context.
674-
Deprecated: use PropagationContext.iter_headers instead.
675-
"""
676-
if self._propagation_context is not None:
677-
yield from self._propagation_context.iter_headers()
678-
679652
def iter_trace_propagation_headers(
680653
self, *args: "Any", **kwargs: "Any"
681654
) -> "Generator[Tuple[str, str], None, None]":
@@ -759,22 +732,6 @@ def clear(self) -> None:
759732

760733
self._gen_ai_conversation_id: "Optional[str]" = None
761734

762-
@_attr_setter
763-
def level(self, value: "LogLevelStr") -> None:
764-
"""
765-
When set this overrides the level.
766-
767-
.. deprecated:: 1.0.0
768-
Use :func:`set_level` instead.
769-
770-
:param value: The level to set.
771-
"""
772-
logger.warning(
773-
"Deprecated: use .set_level() instead. This will be removed in the future."
774-
)
775-
776-
self._level = value
777-
778735
def set_level(self, value: "LogLevelStr") -> None:
779736
"""
780737
Sets the level for the scope.
@@ -865,16 +822,6 @@ def set_transaction_name(self, name: str, source: "Optional[str]" = None) -> Non
865822
if source:
866823
self._transaction_info["source"] = source
867824

868-
@_attr_setter
869-
def user(self, value: "Optional[Dict[str, Any]]") -> None:
870-
"""When set a specific user is bound to the scope. Deprecated in favor of set_user."""
871-
warnings.warn(
872-
"The `Scope.user` setter is deprecated in favor of `Scope.set_user()`.",
873-
DeprecationWarning,
874-
stacklevel=2,
875-
)
876-
self.set_user(value)
877-
878825
def set_user(self, value: "Optional[Dict[str, Any]]") -> None:
879826
"""Sets a user for the scope."""
880827
self._user = value

sentry_sdk/tracing_utils.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -749,16 +749,6 @@ def from_incoming_header(
749749

750750
return Baggage(sentry_items, third_party_items, mutable)
751751

752-
@classmethod
753-
def from_options(cls, scope: "sentry_sdk.scope.Scope") -> "Optional[Baggage]":
754-
"""
755-
Deprecated: use populate_from_propagation_context
756-
"""
757-
if scope._propagation_context is None:
758-
return Baggage({})
759-
760-
return Baggage.populate_from_propagation_context(scope._propagation_context)
761-
762752
@classmethod
763753
def populate_from_propagation_context(
764754
cls, propagation_context: "PropagationContext"

0 commit comments

Comments
 (0)