diff --git a/MIGRATION_GUIDE.md b/MIGRATION_GUIDE.md index d0c895a878..a57452e67b 100644 --- a/MIGRATION_GUIDE.md +++ b/MIGRATION_GUIDE.md @@ -145,6 +145,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh - The `enable_logs` option was removed. Using Sentry's logging API now works without requiring setting `enable_logs=True`. - The `enable_metrics` option was removed. - The deprecated `@ai_track` decorator was removed. +- The deprecated `record_token_usage` function was removed. - The deprecated `push_scope` and `configure_scope` APIs have been removed. Use `with new_scope():` to push a new scope and `scope = get_current_scope()` to retrieve the current scope instead. - The experimental `max_spans` option was removed. - The experimental `before_send_log` option was removed. Use the top-level `before_send_log` instead. diff --git a/sentry_sdk/ai/monitoring.py b/sentry_sdk/ai/monitoring.py deleted file mode 100644 index 4799e1892d..0000000000 --- a/sentry_sdk/ai/monitoring.py +++ /dev/null @@ -1,55 +0,0 @@ -from typing import TYPE_CHECKING - -from sentry_sdk.consts import SPANDATA -from sentry_sdk.utils import deprecation_warning - -if TYPE_CHECKING: - from typing import Any, Awaitable, Callable, Optional, TypeVar, Union - - from sentry_sdk.traces import Span - - F = TypeVar("F", bound=Union[Callable[..., Any], Callable[..., Awaitable[Any]]]) - - -def record_token_usage( - span: "Span", - input_tokens: "Optional[int]" = None, - input_tokens_cached: "Optional[int]" = None, - input_tokens_cache_write: "Optional[int]" = None, - output_tokens: "Optional[int]" = None, - output_tokens_reasoning: "Optional[int]" = None, - total_tokens: "Optional[int]" = None, -) -> None: - deprecation_warning( - "record_token_usage() is deprecated and will be removed in version 3.0 of sentry-sdk. " - "Use the manual span API instead, e.g. span.set_attribute() (in streaming mode) or span.set_data().", - ) - - if input_tokens is not None: - span.set_attribute(SPANDATA.GEN_AI_USAGE_INPUT_TOKENS, input_tokens) - - if input_tokens_cached is not None: - span.set_attribute( - SPANDATA.GEN_AI_USAGE_CACHE_READ_INPUT_TOKENS, input_tokens_cached - ) - - if input_tokens_cache_write is not None: - span.set_attribute( - SPANDATA.GEN_AI_USAGE_CACHE_CREATION_INPUT_TOKENS, - input_tokens_cache_write, - ) - - if output_tokens is not None: - span.set_attribute(SPANDATA.GEN_AI_USAGE_OUTPUT_TOKENS, output_tokens) - - if output_tokens_reasoning is not None: - span.set_attribute( - SPANDATA.GEN_AI_USAGE_REASONING_OUTPUT_TOKENS, - output_tokens_reasoning, - ) - - if total_tokens is None and input_tokens is not None and output_tokens is not None: - total_tokens = input_tokens + output_tokens - - if total_tokens is not None: - span.set_attribute(SPANDATA.GEN_AI_USAGE_TOTAL_TOKENS, total_tokens)