Skip to content

Commit 9a25377

Browse files
authored
Use warnings module for deprecation messagse. (#4180)
Fixes #4109
1 parent dd02f57 commit 9a25377

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

sentry_sdk/consts.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class SPANDATA:
160160

161161
AI_TOOL_CALLS = "ai.tool_calls"
162162
"""
163-
For an AI model call, the function that was called. This is deprecated for OpenAI, and replaced by tool_calls
163+
For an AI model call, the function that was called.
164164
"""
165165

166166
AI_TOOLS = "ai.tools"

sentry_sdk/integrations/opentelemetry/scope.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import cast
22
from contextlib import contextmanager
3+
import warnings
34

45
from opentelemetry.context import (
56
get_value,
@@ -142,8 +143,10 @@ def start_transaction(self, **kwargs):
142143
This function is deprecated and will be removed in a future release.
143144
Use :py:meth:`sentry_sdk.start_span` instead.
144145
"""
145-
logger.warning(
146-
"The `start_transaction` method is deprecated, please use `sentry_sdk.start_span instead.`"
146+
warnings.warn(
147+
"The `start_transaction` method is deprecated, please use `sentry_sdk.start_span instead.`",
148+
DeprecationWarning,
149+
stacklevel=2,
147150
)
148151
return self.start_span(**kwargs)
149152

sentry_sdk/scope.py

+12-6
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,10 @@ def trace_propagation_meta(self, *args, **kwargs):
563563
"""
564564
span = kwargs.pop("span", None)
565565
if span is not None:
566-
logger.warning(
567-
"The parameter `span` in trace_propagation_meta() is deprecated and will be removed in the future."
566+
warnings.warn(
567+
"The parameter `span` in trace_propagation_meta() is deprecated and will be removed in the future.",
568+
DeprecationWarning,
569+
stacklevel=2,
568570
)
569571

570572
meta = ""
@@ -735,8 +737,10 @@ def transaction(self, value):
735737
# transaction name or transaction (self._span) depending on the type of
736738
# the value argument.
737739

738-
logger.warning(
739-
"Assigning to scope.transaction directly is deprecated: use scope.set_transaction_name() instead."
740+
warnings.warn(
741+
"Assigning to scope.transaction directly is deprecated: use scope.set_transaction_name() instead.",
742+
DeprecationWarning,
743+
stacklevel=2,
740744
)
741745
self._transaction = value
742746
if self._span and self._span.containing_transaction:
@@ -954,8 +958,10 @@ def start_transaction(self, **kwargs):
954958
This function is deprecated and will be removed in a future release.
955959
Use :py:meth:`sentry_sdk.start_span` instead.
956960
"""
957-
logger.warning(
958-
"The `start_transaction` method is deprecated, please use `sentry_sdk.start_span instead.`"
961+
warnings.warn(
962+
"The `start_transaction` method is deprecated, please use `sentry_sdk.start_span instead.`",
963+
DeprecationWarning,
964+
stacklevel=2,
959965
)
960966
return NoOpSpan(**kwargs)
961967

sentry_sdk/tracing.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from datetime import datetime
22
from enum import Enum
33
import json
4+
import warnings
45

56
from opentelemetry import trace as otel_trace, context
67
from opentelemetry.trace import (
@@ -476,8 +477,10 @@ def containing_transaction(self):
476477
.. deprecated:: 3.0.0
477478
This will be removed in the future. Use :func:`root_span` instead.
478479
"""
479-
logger.warning(
480-
"Deprecated: This will be removed in the future. Use root_span instead."
480+
warnings.warn(
481+
"Deprecated: This will be removed in the future. Use root_span instead.",
482+
DeprecationWarning,
483+
stacklevel=2,
481484
)
482485
return self.root_span
483486

0 commit comments

Comments
 (0)