diff --git a/sentry_sdk/hub.py b/sentry_sdk/hub.py index 7fda9202df..56c1ee1b8f 100644 --- a/sentry_sdk/hub.py +++ b/sentry_sdk/hub.py @@ -17,10 +17,7 @@ Transaction, ) -from sentry_sdk.utils import ( - logger, - ContextVar, -) +from sentry_sdk.utils import ContextVar from typing import TYPE_CHECKING @@ -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( @@ -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( diff --git a/sentry_sdk/integrations/threading.py b/sentry_sdk/integrations/threading.py index 5de736e23b..46c9d9814f 100644 --- a/sentry_sdk/integrations/threading.py +++ b/sentry_sdk/integrations/threading.py @@ -1,6 +1,7 @@ import sys from functools import wraps from threading import Thread, current_thread +import warnings import sentry_sdk from sentry_sdk.integrations import Integration @@ -8,7 +9,6 @@ from sentry_sdk.utils import ( event_from_exception, capture_internal_exceptions, - logger, reraise, ) @@ -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 diff --git a/sentry_sdk/profiler/transaction_profiler.py b/sentry_sdk/profiler/transaction_profiler.py index 3743b7c905..a93cf8716c 100644 --- a/sentry_sdk/profiler/transaction_profiler.py +++ b/sentry_sdk/profiler/transaction_profiler.py @@ -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 @@ -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 ( diff --git a/sentry_sdk/scope.py b/sentry_sdk/scope.py index 6a5e70a6eb..a0fe71b41c 100644 --- a/sentry_sdk/scope.py +++ b/sentry_sdk/scope.py @@ -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 = "" @@ -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 @@ -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 diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index 866609a66e..608bfb40d7 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -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 @@ -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 @@ -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: