Skip to content

Use warnings module for deprecation messagse. #4180

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 1 commit into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion sentry_sdk/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class SPANDATA:

AI_TOOL_CALLS = "ai.tool_calls"
"""
For an AI model call, the function that was called. This is deprecated for OpenAI, and replaced by tool_calls
For an AI model call, the function that was called.
"""

AI_TOOLS = "ai.tools"
Expand Down
7 changes: 5 additions & 2 deletions sentry_sdk/integrations/opentelemetry/scope.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import cast
from contextlib import contextmanager
import warnings

from opentelemetry.context import (
get_value,
Expand Down Expand Up @@ -142,8 +143,10 @@ def start_transaction(self, **kwargs):
This function is deprecated and will be removed in a future release.
Use :py:meth:`sentry_sdk.start_span` instead.
"""
logger.warning(
"The `start_transaction` method is deprecated, please use `sentry_sdk.start_span instead.`"
warnings.warn(
"The `start_transaction` method is deprecated, please use `sentry_sdk.start_span instead.`",
DeprecationWarning,
stacklevel=2,
)
return self.start_span(**kwargs)

Expand Down
18 changes: 12 additions & 6 deletions sentry_sdk/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,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.",
DeprecationWarning,
stacklevel=2,
)

meta = ""
Expand Down Expand Up @@ -735,8 +737,10 @@ def transaction(self, value):
# 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.",
DeprecationWarning,
stacklevel=2,
)
self._transaction = value
if self._span and self._span.containing_transaction:
Expand Down Expand Up @@ -954,8 +958,10 @@ def start_transaction(self, **kwargs):
This function is deprecated and will be removed in a future release.
Use :py:meth:`sentry_sdk.start_span` instead.
"""
logger.warning(
"The `start_transaction` method is deprecated, please use `sentry_sdk.start_span instead.`"
warnings.warn(
"The `start_transaction` method is deprecated, please use `sentry_sdk.start_span instead.`",
DeprecationWarning,
stacklevel=2,
)
return NoOpSpan(**kwargs)

Expand Down
7 changes: 5 additions & 2 deletions sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from datetime import datetime
from enum import Enum
import json
import warnings

from opentelemetry import trace as otel_trace, context
from opentelemetry.trace import (
Expand Down Expand Up @@ -476,8 +477,10 @@ def containing_transaction(self):
.. deprecated:: 3.0.0
This will be removed in the future. Use :func:`root_span` instead.
"""
logger.warning(
"Deprecated: This will be removed in the future. Use root_span instead."
warnings.warn(
"Deprecated: This will be removed in the future. Use root_span instead.",
DeprecationWarning,
stacklevel=2,
)
return self.root_span

Expand Down
Loading