Skip to content

Commit

Permalink
Switch all deprecation warnings to the warnings module
Browse files Browse the repository at this point in the history
  • Loading branch information
antonpirker committed Feb 28, 2025
1 parent 0d23b72 commit 047db79
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 34 deletions.
18 changes: 10 additions & 8 deletions sentry_sdk/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
Transaction,
)

from sentry_sdk.utils import (
logger,
ContextVar,
)
from sentry_sdk.utils import ContextVar

from typing import TYPE_CHECKING

Expand Down Expand Up @@ -271,9 +268,12 @@ def last_event_id(self):
.. deprecated:: 1.40.5
This function is deprecated and will be removed in a future release. The functions `capture_event`, `capture_message`, and `capture_exception` return the event ID directly.
"""
logger.warning(
"Deprecated: last_event_id is deprecated. This will be removed in the future. The functions `capture_event`, `capture_message`, and `capture_exception` return the event ID directly."
warnings.warn(
"Deprecated: last_event_id is deprecated. This will be removed in the future. The functions `capture_event`, `capture_message`, and `capture_exception` return the event ID directly.",
stacklevel=2,
category=DeprecationWarning,
)

return self._last_event_id

def bind_client(
Expand Down Expand Up @@ -719,8 +719,10 @@ def trace_propagation_meta(self, span=None):
to allow propagation of trace information.
"""
if span is not None:
logger.warning(
"The parameter `span` in trace_propagation_meta() is deprecated and will be removed in the future."
warnings.warn(
"The parameter `span` in trace_propagation_meta() is deprecated and will be removed in the future.",
stacklevel=2,
category=DeprecationWarning,
)

return get_current_scope().trace_propagation_meta(
Expand Down
8 changes: 5 additions & 3 deletions sentry_sdk/integrations/threading.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import sys
from functools import wraps
from threading import Thread, current_thread
import warnings

import sentry_sdk
from sentry_sdk.integrations import Integration
from sentry_sdk.scope import use_isolation_scope, use_scope
from sentry_sdk.utils import (
event_from_exception,
capture_internal_exceptions,
logger,
reraise,
)

Expand All @@ -31,8 +31,10 @@ class ThreadingIntegration(Integration):
def __init__(self, propagate_hub=None, propagate_scope=True):
# type: (Optional[bool], bool) -> None
if propagate_hub is not None:
logger.warning(
"Deprecated: propagate_hub is deprecated. This will be removed in the future."
warnings.warn(
"Deprecated: propagate_hub is deprecated. This will be removed in the future.",
stacklevel=2,
category=DeprecationWarning,
)

# Note: propagate_hub did not have any effect on propagation of scope data
Expand Down
17 changes: 10 additions & 7 deletions sentry_sdk/profiler/transaction_profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,12 @@ def has_profiling_enabled(options):

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."
warnings.warn(
"_experiments['profiles_sample_rate'] is deprecated. Please use the non-experimental profiles_sample_rate option directly.",
stacklevel=2,
category=DeprecationWarning,
)

if profiles_sample_rate > 0:
return True

Expand Down Expand Up @@ -164,10 +165,12 @@ def setup_profiler(options):
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."
warnings.warn(
"_experiments['profiler_mode'] is deprecated. Please use the non-experimental profiler_mode option directly.",
stacklevel=2,
category=DeprecationWarning,
)

profiler_mode = profiler_mode or default_profiler_mode

if (
Expand Down
20 changes: 13 additions & 7 deletions sentry_sdk/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,10 @@ def trace_propagation_meta(self, *args, **kwargs):
"""
span = kwargs.pop("span", None)
if span is not None:
logger.warning(
"The parameter `span` in trace_propagation_meta() is deprecated and will be removed in the future."
warnings.warn(
"The parameter `span` in trace_propagation_meta() is deprecated and will be removed in the future.",
stacklevel=2,
category=DeprecationWarning,
)

meta = ""
Expand Down Expand Up @@ -713,8 +715,10 @@ def level(self, value):
:param value: The level to set.
"""
logger.warning(
"Deprecated: use .set_level() instead. This will be removed in the future."
warnings.warn(
"Deprecated: use .set_level() instead. This will be removed in the future.",
stacklevel=2,
category=DeprecationWarning,
)

self._level = value
Expand Down Expand Up @@ -769,10 +773,12 @@ def transaction(self, value):
# Without breaking version compatibility, we could make the setter set a
# transaction name or transaction (self._span) depending on the type of
# the value argument.

logger.warning(
"Assigning to scope.transaction directly is deprecated: use scope.set_transaction_name() instead."
warnings.warn(
"Assigning to scope.transaction directly is deprecated: use scope.set_transaction_name() instead.",
stacklevel=2,
category=DeprecationWarning,
)

self._transaction = value
if self._span and self._span.containing_transaction:
self._span.containing_transaction.name = value
Expand Down
22 changes: 13 additions & 9 deletions sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,12 @@ def continue_from_environ(
:param environ: The ASGI/WSGI environ to pull information from.
"""
if cls is Span:
logger.warning(
"Deprecated: use Transaction.continue_from_environ "
"instead of Span.continue_from_environ."
warnings.warn(
"Deprecated: use Transaction.continue_from_environ instead of Span.continue_from_environ.",
stacklevel=2,
category=DeprecationWarning,
)

return Transaction.continue_from_headers(EnvironHeaders(environ), **kwargs)

@classmethod
Expand All @@ -491,9 +493,10 @@ def continue_from_headers(
"""
# TODO move this to the Transaction class
if cls is Span:
logger.warning(
"Deprecated: use Transaction.continue_from_headers "
"instead of Span.continue_from_headers."
warnings.warn(
"Deprecated: use Transaction.continue_from_headers instead of Span.continue_from_headers.",
stacklevel=2,
category=DeprecationWarning,
)

# TODO-neel move away from this kwargs stuff, it's confusing and opaque
Expand Down Expand Up @@ -553,9 +556,10 @@ def from_traceparent(
Create a ``Transaction`` with the given params, then add in data pulled from
the given ``sentry-trace`` header value before returning the ``Transaction``.
"""
logger.warning(
"Deprecated: Use Transaction.continue_from_headers(headers, **kwargs) "
"instead of from_traceparent(traceparent, **kwargs)"
warnings.warn(
"Deprecated: Use Transaction.continue_from_headers(headers, **kwargs) instead of from_traceparent(traceparent, **kwargs)",
stacklevel=2,
category=DeprecationWarning,
)

if not traceparent:
Expand Down

0 comments on commit 047db79

Please sign in to comment.