Skip to content

chore: Drop more deprecated stuff #4176

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 8 commits into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from 7 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
9 changes: 8 additions & 1 deletion MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
- `Span.finish()` no longer returns the `event_id` if the event is sent to sentry.
- The `Profile()` constructor does not accept a `hub` parameter anymore.
- A `Profile` object does not have a `.hub` property anymore.
- `MAX_PROFILE_DURATION_NS`, `PROFILE_MINIMUM_SAMPLES`, `Profile`, `Scheduler`, `ThreadScheduler`, `GeventScheduler`, `has_profiling_enabled`, `setup_profiler`, `teardown_profiler` are no longer accessible from `sentry_sdk.profiler`. They're still accessible from `sentry_sdk.profiler.transaction_profiler`.
- `DEFAULT_SAMPLING_FREQUENCY`, `MAX_STACK_DEPTH`, `get_frame_name`, `extract_frame`, `extract_stack`, `frame_id` are no longer accessible from `sentry_sdk.profiler`. They're still accessible from `sentry_sdk.profiler.utils`.
- `sentry_sdk.continue_trace` no longer returns a `Transaction` and is now a context manager.
- Redis integration: In Redis pipeline spans there is no `span["data"]["redis.commands"]` that contains a dict `{"count": 3, "first_ten": ["cmd1", "cmd2", ...]}` but instead `span["data"]["redis.commands.count"]` (containing `3`) and `span["data"]["redis.commands.first_ten"]` (containing `["cmd1", "cmd2", ...]`).
- clickhouse-driver integration: The query is now available under the `db.query.text` span attribute (only if `send_default_pii` is `True`).
Expand Down Expand Up @@ -130,6 +132,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh

- Spans no longer have a `description`. Use `name` instead.
- Dropped support for Python 3.6.
- The `enable_tracing` `init` option has been removed. Configure `traces_sample_rate` directly.
- The `custom_sampling_context` parameter of `start_transaction` has been removed. Use `attributes` instead to set key-value pairs of data that should be accessible in the traces sampler. Note that span attributes need to conform to the [OpenTelemetry specification](https://opentelemetry.io/docs/concepts/signals/traces/#attributes), meaning only certain types can be set as values.
- The PyMongo integration no longer sets tags. The data is still accessible via span attributes.
- The PyMongo integration doesn't set `operation_ids` anymore. The individual IDs (`operation_id`, `request_id`, `session_id`) are now accessible as separate span attributes.
Expand All @@ -141,13 +144,17 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
- The context manager `auto_session_tracking()` has been removed. Use `track_session()` instead.
- The context manager `auto_session_tracking_scope()` has been removed. Use `track_session()` instead.
- Utility function `is_auto_session_tracking_enabled()` has been removed. There is no public replacement. There is a private `_is_auto_session_tracking_enabled()` (if you absolutely need this function) It accepts a `scope` parameter instead of the previously used `hub` parameter.
- Utility function `is_auto_session_tracking_enabled_scope()` has been removed. There is no public replacement. There is a private `_is_auto_session_tracking_enabled()` (if you absolutely need this function)
- Utility function `is_auto_session_tracking_enabled_scope()` has been removed. There is no public replacement. There is a private `_is_auto_session_tracking_enabled()` (if you absolutely need this function).
- Setting `scope.level` has been removed. Use `scope.set_level` instead.
- `span.containing_transaction` has been removed. Use `span.root_span` instead.
- `continue_from_headers`, `continue_from_environ` and `from_traceparent` have been removed, please use top-level API `sentry_sdk.continue_trace` instead.
- `PropagationContext` constructor no longer takes a `dynamic_sampling_context` but takes a `baggage` object instead.
- `ThreadingIntegration` no longer takes the `propagate_hub` argument.
- `Baggage.populate_from_transaction` has been removed.
- `debug.configure_debug_hub` was removed.
- `profiles_sample_rate` and `profiler_mode` were removed from options available via `_experiments`. Use the top-level `profiles_sample_rate` and `profiler_mode` options instead.
- `Transport.capture_event` has been removed. Use `Transport.capture_envelope` instead.
- Function transports are no longer supported. Subclass the `Transport` instead.

### Deprecated

Expand Down
11 changes: 0 additions & 11 deletions sentry_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from datetime import datetime, timezone
from importlib import import_module
from typing import TYPE_CHECKING, List, Dict, cast, overload
import warnings

from sentry_sdk._compat import check_uwsgi_thread_support
from sentry_sdk.utils import (
Expand Down Expand Up @@ -121,9 +120,6 @@ def _get_options(*args, **kwargs):

rv["project_root"] = project_root

if rv["enable_tracing"] is True and rv["traces_sample_rate"] is None:
rv["traces_sample_rate"] = 1.0

if rv["event_scrubber"] is None:
rv["event_scrubber"] = EventScrubber(
send_default_pii=(
Expand All @@ -137,13 +133,6 @@ def _get_options(*args, **kwargs):
)
rv["socket_options"] = None

if rv["enable_tracing"] is not None:
warnings.warn(
"The `enable_tracing` parameter is deprecated. Please use `traces_sample_rate` instead.",
DeprecationWarning,
stacklevel=2,
)

return rv


Expand Down
4 changes: 0 additions & 4 deletions sentry_sdk/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,6 @@ def __init__(
proxy_headers=None, # type: Optional[Dict[str, str]]
before_send_transaction=None, # type: Optional[TransactionProcessor]
project_root=None, # type: Optional[str]
enable_tracing=None, # type: Optional[bool]
include_local_variables=True, # type: Optional[bool]
include_source_context=True, # type: Optional[bool]
trace_propagation_targets=[ # noqa: B006
Expand Down Expand Up @@ -915,9 +914,6 @@ def __init__(

:param profile_session_sample_rate:


:param enable_tracing:

:param propagate_traces:

:param auto_session_tracking:
Expand Down
10 changes: 0 additions & 10 deletions sentry_sdk/debug.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import sys
import logging
import warnings

from sentry_sdk import get_client
from sentry_sdk.client import _client_init_debug
Expand Down Expand Up @@ -30,12 +29,3 @@ def configure_logger():
logger.addHandler(_handler)
logger.setLevel(logging.DEBUG)
logger.addFilter(_DebugFilter())


def configure_debug_hub():
# type: () -> None
warnings.warn(
"configure_debug_hub is deprecated. Please remove calls to it, as it is a no-op.",
DeprecationWarning,
stacklevel=2,
)
36 changes: 0 additions & 36 deletions sentry_sdk/profiler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,8 @@
start_profiler,
stop_profiler,
)
from sentry_sdk.profiler.transaction_profiler import (
MAX_PROFILE_DURATION_NS,
PROFILE_MINIMUM_SAMPLES,
Profile,
Scheduler,
ThreadScheduler,
GeventScheduler,
has_profiling_enabled,
setup_profiler,
teardown_profiler,
)
from sentry_sdk.profiler.utils import (
DEFAULT_SAMPLING_FREQUENCY,
MAX_STACK_DEPTH,
get_frame_name,
extract_frame,
extract_stack,
frame_id,
)

__all__ = [
"start_profiler",
"stop_profiler",
# DEPRECATED: The following was re-exported for backwards compatibility. It
# will be removed from sentry_sdk.profiler in a future release.
"MAX_PROFILE_DURATION_NS",
"PROFILE_MINIMUM_SAMPLES",
"Profile",
"Scheduler",
"ThreadScheduler",
"GeventScheduler",
"has_profiling_enabled",
"setup_profiler",
"teardown_profiler",
"DEFAULT_SAMPLING_FREQUENCY",
"MAX_STACK_DEPTH",
"get_frame_name",
"extract_frame",
"extract_stack",
"frame_id",
]
8 changes: 1 addition & 7 deletions sentry_sdk/profiler/continuous_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,9 @@ def setup_continuous_profiler(options, sdk_info, capture_func):
else:
default_profiler_mode = ThreadContinuousScheduler.mode

profiler_mode = default_profiler_mode
if options.get("profiler_mode") is not None:
profiler_mode = options["profiler_mode"]
else:
# TODO: deprecate this and just use the existing `profiler_mode`
experiments = options.get("_experiments", {})

profiler_mode = (
experiments.get("continuous_profiling_mode") or default_profiler_mode
)

frequency = DEFAULT_SAMPLING_FREQUENCY

Expand Down
22 changes: 2 additions & 20 deletions sentry_sdk/profiler/transaction_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,6 @@ def has_profiling_enabled(options):
if profiles_sample_rate is not None and profiles_sample_rate > 0:
return True

profiles_sample_rate = options["_experiments"].get("profiles_sample_rate")
if profiles_sample_rate is not None:
logger.warning(
"_experiments['profiles_sample_rate'] is deprecated. "
"Please use the non-experimental profiles_sample_rate option "
"directly."
)
if profiles_sample_rate > 0:
return True

return False


Expand All @@ -157,16 +147,9 @@ def setup_profiler(options):
else:
default_profiler_mode = ThreadScheduler.mode

profiler_mode = default_profiler_mode
if options.get("profiler_mode") is not None:
profiler_mode = options["profiler_mode"]
else:
profiler_mode = options.get("_experiments", {}).get("profiler_mode")
if profiler_mode is not None:
logger.warning(
"_experiments['profiler_mode'] is deprecated. Please use the "
"non-experimental profiler_mode option directly."
)
profiler_mode = profiler_mode or default_profiler_mode

if (
profiler_mode == ThreadScheduler.mode
Expand Down Expand Up @@ -283,12 +266,11 @@ def _set_initial_sampling_decision(self, sampling_context):

options = client.options

sample_rate = None
if callable(options.get("profiles_sampler")):
sample_rate = options["profiles_sampler"](sampling_context)
elif options["profiles_sample_rate"] is not None:
sample_rate = options["profiles_sample_rate"]
else:
sample_rate = options["_experiments"].get("profiles_sample_rate")

# The profiles_sample_rate option was not set, so profiling
# was never enabled.
Expand Down
9 changes: 3 additions & 6 deletions sentry_sdk/tracing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,14 @@ def has_tracing_enabled(options):
# type: (Optional[Dict[str, Any]]) -> bool
"""
Returns True if either traces_sample_rate or traces_sampler is
defined and enable_tracing is set and not false.
defined.
"""
if options is None:
return False

return bool(
options.get("enable_tracing") is not False
and (
options.get("traces_sample_rate") is not None
or options.get("traces_sampler") is not None
)
options.get("traces_sample_rate") is not None
or options.get("traces_sampler") is not None
)


Expand Down
59 changes: 1 addition & 58 deletions sentry_sdk/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import socket
import ssl
import time
import warnings
from datetime import datetime, timedelta, timezone
from collections import defaultdict
from urllib.request import getproxies
Expand Down Expand Up @@ -40,7 +39,7 @@
from urllib3.poolmanager import PoolManager
from urllib3.poolmanager import ProxyManager

from sentry_sdk._types import Event, EventDataCategory
from sentry_sdk._types import EventDataCategory

KEEP_ALIVE_SOCKET_OPTIONS = []
for option in [
Expand Down Expand Up @@ -73,25 +72,6 @@ def __init__(self, options=None):
else:
self.parsed_dsn = None

def capture_event(self, event):
# type: (Self, Event) -> None
"""
DEPRECATED: Please use capture_envelope instead.

This gets invoked with the event dictionary when an event should
be sent to sentry.
"""

warnings.warn(
"capture_event is deprecated, please use capture_envelope instead!",
DeprecationWarning,
stacklevel=2,
)

envelope = Envelope()
envelope.add_event(event)
self.capture_envelope(envelope)

@abstractmethod
def capture_envelope(self, envelope):
# type: (Self, Envelope) -> None
Expand Down Expand Up @@ -806,35 +786,6 @@ def _make_pool(self):
return httpcore.ConnectionPool(**opts)


class _FunctionTransport(Transport):
"""
DEPRECATED: Users wishing to provide a custom transport should subclass
the Transport class, rather than providing a function.
"""

def __init__(
self, func # type: Callable[[Event], None]
):
# type: (...) -> None
Transport.__init__(self)
self._func = func

def capture_event(
self, event # type: Event
):
# type: (...) -> None
self._func(event)
return None

def capture_envelope(self, envelope: Envelope) -> None:
# Since function transports expect to be called with an event, we need
# to iterate over the envelope and call the function for each event, via
# the deprecated capture_event method.
event = envelope.get_event()
if event is not None:
self.capture_event(event)


def make_transport(options):
# type: (Dict[str, Any]) -> Optional[Transport]
ref_transport = options["transport"]
Expand All @@ -850,14 +801,6 @@ def make_transport(options):
return ref_transport
elif isinstance(ref_transport, type) and issubclass(ref_transport, Transport):
transport_cls = ref_transport
elif callable(ref_transport):
warnings.warn(
"Function transports are deprecated and will be removed in a future release."
"Please provide a Transport instance or subclass, instead.",
DeprecationWarning,
stacklevel=2,
)
return _FunctionTransport(ref_transport)

# if a transport class is given only instantiate it if the dsn is not
# empty or None
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
_installed_integrations,
_processed_integrations,
)
from sentry_sdk.profiler import teardown_profiler
from sentry_sdk.profiler.transaction_profiler import teardown_profiler
from sentry_sdk.profiler.continuous_profiler import teardown_continuous_profiler
from sentry_sdk.transport import Transport
from sentry_sdk.utils import reraise
Expand Down
40 changes: 2 additions & 38 deletions tests/integrations/celery/test_update_celery_task_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_monitor_beat_tasks_with_headers(monitor_beat_tasks):


def test_span_with_transaction(sentry_init):
sentry_init(enable_tracing=True)
sentry_init(traces_sample_rate=1.0)
headers = {}
monitor_beat_tasks = False

Expand All @@ -91,7 +91,7 @@ def test_span_with_transaction(sentry_init):


def test_span_with_transaction_custom_headers(sentry_init):
sentry_init(enable_tracing=True)
sentry_init(traces_sample_rate=1.0)
headers = {
"baggage": BAGGAGE_VALUE,
"sentry-trace": SENTRY_TRACE_VALUE,
Expand Down Expand Up @@ -190,39 +190,3 @@ def test_celery_trace_propagation_traces_sample_rate(
else:
assert "sentry-monitor-start-timestamp-s" not in outgoing_headers
assert "sentry-monitor-start-timestamp-s" not in outgoing_headers["headers"]


@pytest.mark.parametrize(
"enable_tracing,monitor_beat_tasks",
list(itertools.product([None, True, False], [True, False])),
)
def test_celery_trace_propagation_enable_tracing(
sentry_init, enable_tracing, monitor_beat_tasks
):
"""
The celery integration does not check the traces_sample_rate.
By default traces_sample_rate is None which means "do not propagate traces".
But the celery integration does not check this value.
The Celery integration has its own mechanism to propagate traces:
https://docs.sentry.io/platforms/python/integrations/celery/#distributed-traces
"""
sentry_init(enable_tracing=enable_tracing)

headers = {}
span = None

scope = sentry_sdk.get_isolation_scope()

outgoing_headers = _update_celery_task_headers(headers, span, monitor_beat_tasks)

assert outgoing_headers["sentry-trace"] == scope.get_traceparent()
assert outgoing_headers["headers"]["sentry-trace"] == scope.get_traceparent()
assert outgoing_headers["baggage"] == scope.get_baggage().serialize()
assert outgoing_headers["headers"]["baggage"] == scope.get_baggage().serialize()

if monitor_beat_tasks:
assert "sentry-monitor-start-timestamp-s" in outgoing_headers
assert "sentry-monitor-start-timestamp-s" in outgoing_headers["headers"]
else:
assert "sentry-monitor-start-timestamp-s" not in outgoing_headers
assert "sentry-monitor-start-timestamp-s" not in outgoing_headers["headers"]
Loading
Loading