Skip to content

Commit 047db79

Browse files
committed
Switch all deprecation warnings to the warnings module
1 parent 0d23b72 commit 047db79

File tree

5 files changed

+51
-34
lines changed

5 files changed

+51
-34
lines changed

Diff for: sentry_sdk/hub.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@
1717
Transaction,
1818
)
1919

20-
from sentry_sdk.utils import (
21-
logger,
22-
ContextVar,
23-
)
20+
from sentry_sdk.utils import ContextVar
2421

2522
from typing import TYPE_CHECKING
2623

@@ -271,9 +268,12 @@ def last_event_id(self):
271268
.. deprecated:: 1.40.5
272269
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.
273270
"""
274-
logger.warning(
275-
"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."
271+
warnings.warn(
272+
"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.",
273+
stacklevel=2,
274+
category=DeprecationWarning,
276275
)
276+
277277
return self._last_event_id
278278

279279
def bind_client(
@@ -719,8 +719,10 @@ def trace_propagation_meta(self, span=None):
719719
to allow propagation of trace information.
720720
"""
721721
if span is not None:
722-
logger.warning(
723-
"The parameter `span` in trace_propagation_meta() is deprecated and will be removed in the future."
722+
warnings.warn(
723+
"The parameter `span` in trace_propagation_meta() is deprecated and will be removed in the future.",
724+
stacklevel=2,
725+
category=DeprecationWarning,
724726
)
725727

726728
return get_current_scope().trace_propagation_meta(

Diff for: sentry_sdk/integrations/threading.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import sys
22
from functools import wraps
33
from threading import Thread, current_thread
4+
import warnings
45

56
import sentry_sdk
67
from sentry_sdk.integrations import Integration
78
from sentry_sdk.scope import use_isolation_scope, use_scope
89
from sentry_sdk.utils import (
910
event_from_exception,
1011
capture_internal_exceptions,
11-
logger,
1212
reraise,
1313
)
1414

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

3840
# Note: propagate_hub did not have any effect on propagation of scope data

Diff for: sentry_sdk/profiler/transaction_profiler.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,12 @@ def has_profiling_enabled(options):
129129

130130
profiles_sample_rate = options["_experiments"].get("profiles_sample_rate")
131131
if profiles_sample_rate is not None:
132-
logger.warning(
133-
"_experiments['profiles_sample_rate'] is deprecated. "
134-
"Please use the non-experimental profiles_sample_rate option "
135-
"directly."
132+
warnings.warn(
133+
"_experiments['profiles_sample_rate'] is deprecated. Please use the non-experimental profiles_sample_rate option directly.",
134+
stacklevel=2,
135+
category=DeprecationWarning,
136136
)
137+
137138
if profiles_sample_rate > 0:
138139
return True
139140

@@ -164,10 +165,12 @@ def setup_profiler(options):
164165
else:
165166
profiler_mode = options.get("_experiments", {}).get("profiler_mode")
166167
if profiler_mode is not None:
167-
logger.warning(
168-
"_experiments['profiler_mode'] is deprecated. Please use the "
169-
"non-experimental profiler_mode option directly."
168+
warnings.warn(
169+
"_experiments['profiler_mode'] is deprecated. Please use the non-experimental profiler_mode option directly.",
170+
stacklevel=2,
171+
category=DeprecationWarning,
170172
)
173+
171174
profiler_mode = profiler_mode or default_profiler_mode
172175

173176
if (

Diff for: sentry_sdk/scope.py

+13-7
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,10 @@ def trace_propagation_meta(self, *args, **kwargs):
579579
"""
580580
span = kwargs.pop("span", None)
581581
if span is not None:
582-
logger.warning(
583-
"The parameter `span` in trace_propagation_meta() is deprecated and will be removed in the future."
582+
warnings.warn(
583+
"The parameter `span` in trace_propagation_meta() is deprecated and will be removed in the future.",
584+
stacklevel=2,
585+
category=DeprecationWarning,
584586
)
585587

586588
meta = ""
@@ -713,8 +715,10 @@ def level(self, value):
713715
714716
:param value: The level to set.
715717
"""
716-
logger.warning(
717-
"Deprecated: use .set_level() instead. This will be removed in the future."
718+
warnings.warn(
719+
"Deprecated: use .set_level() instead. This will be removed in the future.",
720+
stacklevel=2,
721+
category=DeprecationWarning,
718722
)
719723

720724
self._level = value
@@ -769,10 +773,12 @@ def transaction(self, value):
769773
# Without breaking version compatibility, we could make the setter set a
770774
# transaction name or transaction (self._span) depending on the type of
771775
# the value argument.
772-
773-
logger.warning(
774-
"Assigning to scope.transaction directly is deprecated: use scope.set_transaction_name() instead."
776+
warnings.warn(
777+
"Assigning to scope.transaction directly is deprecated: use scope.set_transaction_name() instead.",
778+
stacklevel=2,
779+
category=DeprecationWarning,
775780
)
781+
776782
self._transaction = value
777783
if self._span and self._span.containing_transaction:
778784
self._span.containing_transaction.name = value

Diff for: sentry_sdk/tracing.py

+13-9
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,12 @@ def continue_from_environ(
466466
:param environ: The ASGI/WSGI environ to pull information from.
467467
"""
468468
if cls is Span:
469-
logger.warning(
470-
"Deprecated: use Transaction.continue_from_environ "
471-
"instead of Span.continue_from_environ."
469+
warnings.warn(
470+
"Deprecated: use Transaction.continue_from_environ instead of Span.continue_from_environ.",
471+
stacklevel=2,
472+
category=DeprecationWarning,
472473
)
474+
473475
return Transaction.continue_from_headers(EnvironHeaders(environ), **kwargs)
474476

475477
@classmethod
@@ -491,9 +493,10 @@ def continue_from_headers(
491493
"""
492494
# TODO move this to the Transaction class
493495
if cls is Span:
494-
logger.warning(
495-
"Deprecated: use Transaction.continue_from_headers "
496-
"instead of Span.continue_from_headers."
496+
warnings.warn(
497+
"Deprecated: use Transaction.continue_from_headers instead of Span.continue_from_headers.",
498+
stacklevel=2,
499+
category=DeprecationWarning,
497500
)
498501

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

561565
if not traceparent:

0 commit comments

Comments
 (0)