From a16dead98495740e2dc2e8ed7768b88dde37ffdf Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Thu, 12 Mar 2026 14:36:38 +0100 Subject: [PATCH 1/3] fix: Remove more unused imports --- scripts/populate_tox/populate_tox.py | 1 - sentry_sdk/_batcher.py | 2 +- sentry_sdk/_log_batcher.py | 2 +- sentry_sdk/_metrics_batcher.py | 1 - sentry_sdk/_span_batcher.py | 4 +--- sentry_sdk/_types.py | 1 - sentry_sdk/ai/utils.py | 2 -- sentry_sdk/client.py | 4 +--- sentry_sdk/consts.py | 1 - sentry_sdk/integrations/anthropic.py | 2 +- sentry_sdk/integrations/django/tasks.py | 3 +-- sentry_sdk/integrations/google_genai/streaming.py | 2 +- sentry_sdk/integrations/google_genai/utils.py | 2 -- sentry_sdk/integrations/grpc/aio/server.py | 2 +- sentry_sdk/integrations/grpc/server.py | 2 +- sentry_sdk/integrations/openai.py | 1 - sentry_sdk/integrations/openai_agents/__init__.py | 1 - sentry_sdk/integrations/openai_agents/patches/agent_run.py | 1 - .../integrations/openai_agents/patches/error_tracing.py | 4 +--- sentry_sdk/integrations/pydantic_ai/__init__.py | 2 +- sentry_sdk/integrations/pydantic_ai/patches/graph_nodes.py | 1 - sentry_sdk/integrations/pydantic_ai/spans/ai_client.py | 1 - sentry_sdk/integrations/strawberry.py | 2 -- sentry_sdk/logger.py | 4 ++-- sentry_sdk/metrics.py | 4 ++-- sentry_sdk/scope.py | 2 -- sentry_sdk/tracing.py | 1 - sentry_sdk/utils.py | 1 - tests/integrations/django/test_tasks.py | 1 - tests/integrations/huggingface_hub/test_huggingface_hub.py | 1 - tests/integrations/litellm/test_litellm.py | 1 - tests/integrations/openai/test_openai.py | 2 -- tests/integrations/openai_agents/test_openai_agents.py | 5 ----- tests/integrations/pydantic_ai/test_pydantic_ai.py | 6 ++---- tests/integrations/stdlib/test_httplib.py | 1 - tests/integrations/strawberry/test_strawberry.py | 1 - tests/test_ai_integration_deactivation.py | 1 - tests/test_ai_monitoring.py | 6 ------ tests/test_logs.py | 4 ++-- tests/test_metrics.py | 5 +---- tests/test_shadowed_module.py | 1 - tests/test_spotlight.py | 1 - tests/tracing/test_decorator.py | 1 - tests/tracing/test_deprecated.py | 3 --- tests/tracing/test_sampling.py | 2 +- 45 files changed, 21 insertions(+), 77 deletions(-) diff --git a/scripts/populate_tox/populate_tox.py b/scripts/populate_tox/populate_tox.py index 7f1065378e..fb404b0921 100644 --- a/scripts/populate_tox/populate_tox.py +++ b/scripts/populate_tox/populate_tox.py @@ -20,7 +20,6 @@ from packaging.specifiers import SpecifierSet from packaging.version import Version from pathlib import Path -from textwrap import dedent from typing import Optional, Union # Adding the scripts directory to PATH. This is necessary in order to be able diff --git a/sentry_sdk/_batcher.py b/sentry_sdk/_batcher.py index 4a6ee07e67..3b188a694b 100644 --- a/sentry_sdk/_batcher.py +++ b/sentry_sdk/_batcher.py @@ -4,7 +4,7 @@ from datetime import datetime, timezone from typing import TYPE_CHECKING, TypeVar, Generic -from sentry_sdk.utils import format_timestamp, safe_repr, serialize_attribute +from sentry_sdk.utils import format_timestamp from sentry_sdk.envelope import Envelope, Item, PayloadRef if TYPE_CHECKING: diff --git a/sentry_sdk/_log_batcher.py b/sentry_sdk/_log_batcher.py index 1c59f7379c..d765236846 100644 --- a/sentry_sdk/_log_batcher.py +++ b/sentry_sdk/_log_batcher.py @@ -2,7 +2,7 @@ from sentry_sdk._batcher import Batcher from sentry_sdk.utils import serialize_attribute -from sentry_sdk.envelope import Envelope, Item, PayloadRef +from sentry_sdk.envelope import Item, PayloadRef if TYPE_CHECKING: from typing import Any diff --git a/sentry_sdk/_metrics_batcher.py b/sentry_sdk/_metrics_batcher.py index e60a4c86ec..92cece209b 100644 --- a/sentry_sdk/_metrics_batcher.py +++ b/sentry_sdk/_metrics_batcher.py @@ -2,7 +2,6 @@ from sentry_sdk._batcher import Batcher from sentry_sdk.utils import serialize_attribute -from sentry_sdk.envelope import Item if TYPE_CHECKING: from typing import Any diff --git a/sentry_sdk/_span_batcher.py b/sentry_sdk/_span_batcher.py index df3598b282..09985d9301 100644 --- a/sentry_sdk/_span_batcher.py +++ b/sentry_sdk/_span_batcher.py @@ -4,14 +4,12 @@ from typing import TYPE_CHECKING from sentry_sdk._batcher import Batcher -from sentry_sdk.consts import SPANSTATUS from sentry_sdk.envelope import Envelope, Item, PayloadRef -from sentry_sdk.utils import format_timestamp, serialize_attribute, safe_repr +from sentry_sdk.utils import format_timestamp, serialize_attribute if TYPE_CHECKING: from typing import Any, Callable, Optional from sentry_sdk.traces import StreamedSpan - from sentry_sdk._types import SerializedAttributeValue class SpanBatcher(Batcher["StreamedSpan"]): diff --git a/sentry_sdk/_types.py b/sentry_sdk/_types.py index e3e8c16f90..baf5f6a2fd 100644 --- a/sentry_sdk/_types.py +++ b/sentry_sdk/_types.py @@ -109,7 +109,6 @@ def substituted_because_contains_sensitive_data(cls) -> "AnnotatedValue": from typing import Mapping from typing import NotRequired from typing import Optional - from typing import Tuple from typing import Type from typing_extensions import Literal, TypedDict diff --git a/sentry_sdk/ai/utils.py b/sentry_sdk/ai/utils.py index 5acc501172..6c5073ab31 100644 --- a/sentry_sdk/ai/utils.py +++ b/sentry_sdk/ai/utils.py @@ -1,8 +1,6 @@ import inspect import json -from collections import deque from copy import deepcopy -from sys import getsizeof from typing import TYPE_CHECKING from sentry_sdk._types import BLOB_DATA_SUBSTITUTE diff --git a/sentry_sdk/client.py b/sentry_sdk/client.py index f540a49f35..9aa26a4f30 100644 --- a/sentry_sdk/client.py +++ b/sentry_sdk/client.py @@ -8,8 +8,7 @@ from typing import TYPE_CHECKING, List, Dict, cast, overload import warnings -import sentry_sdk -from sentry_sdk._compat import PY37, check_uwsgi_thread_support +from sentry_sdk._compat import check_uwsgi_thread_support from sentry_sdk._metrics_batcher import MetricsBatcher from sentry_sdk._span_batcher import SpanBatcher from sentry_sdk.utils import ( @@ -23,7 +22,6 @@ get_type_name, get_default_release, handle_in_app, - is_gevent, logger, get_before_send_log, get_before_send_metric, diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py index eb077ef62f..acdf7177b4 100644 --- a/sentry_sdk/consts.py +++ b/sentry_sdk/consts.py @@ -54,7 +54,6 @@ class CompressionAlgo(Enum): Hint, IgnoreSpansConfig, Log, - MeasurementUnit, Metric, ProfilerMode, TracesSampler, diff --git a/sentry_sdk/integrations/anthropic.py b/sentry_sdk/integrations/anthropic.py index eca9e8bd3e..0aa812cab3 100644 --- a/sentry_sdk/integrations/anthropic.py +++ b/sentry_sdk/integrations/anthropic.py @@ -45,7 +45,7 @@ raise DidNotEnable("Anthropic not installed") if TYPE_CHECKING: - from typing import Any, AsyncIterator, Iterator, List, Optional, Union + from typing import Any, AsyncIterator, Iterator, Optional, Union from sentry_sdk.tracing import Span from sentry_sdk._types import TextPart diff --git a/sentry_sdk/integrations/django/tasks.py b/sentry_sdk/integrations/django/tasks.py index 84bc4d2396..e6adb914e8 100644 --- a/sentry_sdk/integrations/django/tasks.py +++ b/sentry_sdk/integrations/django/tasks.py @@ -2,12 +2,11 @@ import sentry_sdk from sentry_sdk.consts import OP -from sentry_sdk.tracing import SPANSTATUS from sentry_sdk.utils import qualname_from_function try: # django.tasks were added in Django 6.0 - from django.tasks.base import Task, TaskResultStatus + from django.tasks.base import Task except ImportError: Task = None diff --git a/sentry_sdk/integrations/google_genai/streaming.py b/sentry_sdk/integrations/google_genai/streaming.py index 8649ce2ac0..3405fe2b2a 100644 --- a/sentry_sdk/integrations/google_genai/streaming.py +++ b/sentry_sdk/integrations/google_genai/streaming.py @@ -1,4 +1,4 @@ -from typing import TYPE_CHECKING, Any, List, TypedDict, Optional, Union +from typing import TYPE_CHECKING, Any, List, TypedDict, Optional from sentry_sdk.ai.utils import set_data_normalized from sentry_sdk.consts import SPANDATA diff --git a/sentry_sdk/integrations/google_genai/utils.py b/sentry_sdk/integrations/google_genai/utils.py index b2d6499843..28b54a8bcd 100644 --- a/sentry_sdk/integrations/google_genai/utils.py +++ b/sentry_sdk/integrations/google_genai/utils.py @@ -5,7 +5,6 @@ from .consts import ORIGIN, TOOL_ATTRIBUTES_MAP, GEN_AI_SYSTEM from sentry_sdk._types import BLOB_DATA_SUBSTITUTE from typing import ( - cast, TYPE_CHECKING, Iterable, Any, @@ -22,7 +21,6 @@ set_data_normalized, truncate_and_annotate_messages, normalize_message_roles, - redact_blob_message_parts, transform_google_content_part, get_modality_from_mime_type, ) diff --git a/sentry_sdk/integrations/grpc/aio/server.py b/sentry_sdk/integrations/grpc/aio/server.py index 3ed15c2de6..1e9eac8920 100644 --- a/sentry_sdk/integrations/grpc/aio/server.py +++ b/sentry_sdk/integrations/grpc/aio/server.py @@ -2,7 +2,7 @@ from sentry_sdk.consts import OP from sentry_sdk.integrations import DidNotEnable from sentry_sdk.integrations.grpc.consts import SPAN_ORIGIN -from sentry_sdk.tracing import Transaction, TransactionSource +from sentry_sdk.tracing import TransactionSource from sentry_sdk.utils import event_from_exception from typing import TYPE_CHECKING diff --git a/sentry_sdk/integrations/grpc/server.py b/sentry_sdk/integrations/grpc/server.py index 7c06fd405a..af01f37fb2 100644 --- a/sentry_sdk/integrations/grpc/server.py +++ b/sentry_sdk/integrations/grpc/server.py @@ -2,7 +2,7 @@ from sentry_sdk.consts import OP from sentry_sdk.integrations import DidNotEnable from sentry_sdk.integrations.grpc.consts import SPAN_ORIGIN -from sentry_sdk.tracing import Transaction, TransactionSource +from sentry_sdk.tracing import TransactionSource from typing import TYPE_CHECKING diff --git a/sentry_sdk/integrations/openai.py b/sentry_sdk/integrations/openai.py index b1995a6287..a5556b8776 100644 --- a/sentry_sdk/integrations/openai.py +++ b/sentry_sdk/integrations/openai.py @@ -71,7 +71,6 @@ from openai.types.chat import ( ChatCompletionMessageParam, ChatCompletionChunk, - ChatCompletionSystemMessageParam, ) except ImportError: raise DidNotEnable("OpenAI not installed") diff --git a/sentry_sdk/integrations/openai_agents/__init__.py b/sentry_sdk/integrations/openai_agents/__init__.py index 4d778676ac..1268ef3755 100644 --- a/sentry_sdk/integrations/openai_agents/__init__.py +++ b/sentry_sdk/integrations/openai_agents/__init__.py @@ -22,7 +22,6 @@ # not installed. That's why we're adding the second, more specific import # after it, even if we don't use it. import agents - from agents.run import DEFAULT_AGENT_RUNNER from agents.run import AgentRunner from agents.version import __version__ as OPENAI_AGENTS_VERSION diff --git a/sentry_sdk/integrations/openai_agents/patches/agent_run.py b/sentry_sdk/integrations/openai_agents/patches/agent_run.py index a828532ab3..040b10b668 100644 --- a/sentry_sdk/integrations/openai_agents/patches/agent_run.py +++ b/sentry_sdk/integrations/openai_agents/patches/agent_run.py @@ -1,5 +1,4 @@ import sys -from functools import wraps from sentry_sdk.consts import SPANDATA from sentry_sdk.integrations import DidNotEnable diff --git a/sentry_sdk/integrations/openai_agents/patches/error_tracing.py b/sentry_sdk/integrations/openai_agents/patches/error_tracing.py index 8598d9c4fd..9d6fd59e0f 100644 --- a/sentry_sdk/integrations/openai_agents/patches/error_tracing.py +++ b/sentry_sdk/integrations/openai_agents/patches/error_tracing.py @@ -1,14 +1,12 @@ from functools import wraps import sentry_sdk -from sentry_sdk.consts import SPANSTATUS -from sentry_sdk.tracing_utils import set_span_errored from ..utils import _record_exception_on_span from typing import TYPE_CHECKING if TYPE_CHECKING: - from typing import Any, Callable, Optional + from typing import Any def _patch_error_tracing() -> None: diff --git a/sentry_sdk/integrations/pydantic_ai/__init__.py b/sentry_sdk/integrations/pydantic_ai/__init__.py index 2f1808d14f..0f0de53fa5 100644 --- a/sentry_sdk/integrations/pydantic_ai/__init__.py +++ b/sentry_sdk/integrations/pydantic_ai/__init__.py @@ -2,7 +2,7 @@ try: - import pydantic_ai # type: ignore + import pydantic_ai # type: ignore # noqa: F401 except ImportError: raise DidNotEnable("pydantic-ai not installed") diff --git a/sentry_sdk/integrations/pydantic_ai/patches/graph_nodes.py b/sentry_sdk/integrations/pydantic_ai/patches/graph_nodes.py index 56e46d869f..afb10395f4 100644 --- a/sentry_sdk/integrations/pydantic_ai/patches/graph_nodes.py +++ b/sentry_sdk/integrations/pydantic_ai/patches/graph_nodes.py @@ -1,7 +1,6 @@ from contextlib import asynccontextmanager from functools import wraps -import sentry_sdk from sentry_sdk.integrations import DidNotEnable from ..spans import ( diff --git a/sentry_sdk/integrations/pydantic_ai/spans/ai_client.py b/sentry_sdk/integrations/pydantic_ai/spans/ai_client.py index 8e0b6b9f35..dc95acad45 100644 --- a/sentry_sdk/integrations/pydantic_ai/spans/ai_client.py +++ b/sentry_sdk/integrations/pydantic_ai/spans/ai_client.py @@ -29,7 +29,6 @@ if TYPE_CHECKING: from typing import Any, List, Dict - from pydantic_ai.usage import RequestUsage # type: ignore from pydantic_ai.messages import ModelMessage, SystemPromptPart # type: ignore from sentry_sdk._types import TextPart as SentryTextPart diff --git a/sentry_sdk/integrations/strawberry.py b/sentry_sdk/integrations/strawberry.py index 12676b53eb..a12ee63e2a 100644 --- a/sentry_sdk/integrations/strawberry.py +++ b/sentry_sdk/integrations/strawberry.py @@ -13,9 +13,7 @@ capture_internal_exceptions, ensure_integration_enabled, event_from_exception, - logger, package_version, - _get_installed_modules, ) try: diff --git a/sentry_sdk/logger.py b/sentry_sdk/logger.py index 4a90fef70b..ee6184105a 100644 --- a/sentry_sdk/logger.py +++ b/sentry_sdk/logger.py @@ -4,10 +4,10 @@ from typing import Any, TYPE_CHECKING import sentry_sdk -from sentry_sdk.utils import format_attribute, safe_repr, capture_internal_exceptions +from sentry_sdk.utils import format_attribute, capture_internal_exceptions if TYPE_CHECKING: - from sentry_sdk._types import Attributes, Log + from sentry_sdk._types import Attributes OTEL_RANGES = [ diff --git a/sentry_sdk/metrics.py b/sentry_sdk/metrics.py index 167e49da05..fb5f21ec4e 100644 --- a/sentry_sdk/metrics.py +++ b/sentry_sdk/metrics.py @@ -1,8 +1,8 @@ import time -from typing import Any, Optional, TYPE_CHECKING, Union +from typing import Any, Optional, TYPE_CHECKING import sentry_sdk -from sentry_sdk.utils import format_attribute, safe_repr +from sentry_sdk.utils import format_attribute if TYPE_CHECKING: from sentry_sdk._types import Attributes, Metric, MetricType diff --git a/sentry_sdk/scope.py b/sentry_sdk/scope.py index a3477cb200..103ab20712 100644 --- a/sentry_sdk/scope.py +++ b/sentry_sdk/scope.py @@ -32,7 +32,6 @@ has_span_streaming_enabled, is_ignored_span, _make_sampling_decision, - normalize_incoming_data, PropagationContext, ) from sentry_sdk.traces import _DEFAULT_PARENT_SPAN, StreamedSpan, NoOpStreamedSpan @@ -57,7 +56,6 @@ has_metrics_enabled, ) -import typing from typing import TYPE_CHECKING, cast if TYPE_CHECKING: diff --git a/sentry_sdk/tracing.py b/sentry_sdk/tracing.py index a778da7361..13aed0d9d8 100644 --- a/sentry_sdk/tracing.py +++ b/sentry_sdk/tracing.py @@ -25,7 +25,6 @@ List, Optional, ParamSpec, - Set, Tuple, TypeVar, Union, diff --git a/sentry_sdk/utils.py b/sentry_sdk/utils.py index a333467ae9..4dfd36d17c 100644 --- a/sentry_sdk/utils.py +++ b/sentry_sdk/utils.py @@ -46,7 +46,6 @@ Dict, Iterator, List, - Literal, NoReturn, Optional, ParamSpec, diff --git a/tests/integrations/django/test_tasks.py b/tests/integrations/django/test_tasks.py index 220d64b111..56c68b807f 100644 --- a/tests/integrations/django/test_tasks.py +++ b/tests/integrations/django/test_tasks.py @@ -1,7 +1,6 @@ import pytest import sentry_sdk -from sentry_sdk import start_span from sentry_sdk.integrations.django import DjangoIntegration from sentry_sdk.consts import OP diff --git a/tests/integrations/huggingface_hub/test_huggingface_hub.py b/tests/integrations/huggingface_hub/test_huggingface_hub.py index 851c1f717a..d17a7a31ef 100644 --- a/tests/integrations/huggingface_hub/test_huggingface_hub.py +++ b/tests/integrations/huggingface_hub/test_huggingface_hub.py @@ -2,7 +2,6 @@ import pytest import re import responses -import httpx from huggingface_hub import InferenceClient diff --git a/tests/integrations/litellm/test_litellm.py b/tests/integrations/litellm/test_litellm.py index ef129c6cfd..9022093fa3 100644 --- a/tests/integrations/litellm/test_litellm.py +++ b/tests/integrations/litellm/test_litellm.py @@ -19,7 +19,6 @@ async def __call__(self, *args, **kwargs): except ImportError: pytest.skip("litellm not installed", allow_module_level=True) -import sentry_sdk from sentry_sdk import start_transaction from sentry_sdk.consts import OP, SPANDATA from sentry_sdk._types import BLOB_DATA_SUBSTITUTE diff --git a/tests/integrations/openai/test_openai.py b/tests/integrations/openai/test_openai.py index 7f75bb977e..23fb0d9ad7 100644 --- a/tests/integrations/openai/test_openai.py +++ b/tests/integrations/openai/test_openai.py @@ -46,8 +46,6 @@ OpenAIIntegration, _calculate_token_usage, ) -from sentry_sdk._types import AnnotatedValue -from sentry_sdk.serializer import serialize from sentry_sdk.utils import safe_serialize from unittest import mock # python 3.3 and above diff --git a/tests/integrations/openai_agents/test_openai_agents.py b/tests/integrations/openai_agents/test_openai_agents.py index 117755b963..4fc97a24f3 100644 --- a/tests/integrations/openai_agents/test_openai_agents.py +++ b/tests/integrations/openai_agents/test_openai_agents.py @@ -1,5 +1,4 @@ import asyncio -import re import pytest from unittest.mock import MagicMock, patch import os @@ -19,7 +18,6 @@ from agents.models.openai_responses import OpenAIResponsesModel from unittest import mock -from unittest.mock import AsyncMock import agents from agents import ( @@ -46,15 +44,12 @@ ResponseCompletedEvent, Response, ResponseUsage, - ResponseStreamEvent, ) from openai.types.responses.response_usage import ( InputTokensDetails, OutputTokensDetails, ) -from openai._response import AsyncAPIResponse -from openai._models import FinalRequestOptions test_run_config = agents.RunConfig(tracing_disabled=True) diff --git a/tests/integrations/pydantic_ai/test_pydantic_ai.py b/tests/integrations/pydantic_ai/test_pydantic_ai.py index 52f724a4dc..f0ddc6c4ed 100644 --- a/tests/integrations/pydantic_ai/test_pydantic_ai.py +++ b/tests/integrations/pydantic_ai/test_pydantic_ai.py @@ -889,7 +889,7 @@ async def test_mcp_tool_execution_spans(sentry_init, capture_events): """ pytest.importorskip("mcp") - from unittest.mock import AsyncMock, MagicMock + from unittest.mock import MagicMock from pydantic_ai.mcp import MCPServerStdio from pydantic_ai import Agent from pydantic_ai.toolsets.combined import CombinedToolset @@ -1379,7 +1379,6 @@ async def test_agent_data_from_scope(sentry_init, capture_events): """ Test that agent data can be retrieved from Sentry scope when not passed directly. """ - import sentry_sdk agent = Agent( "test", @@ -1753,7 +1752,7 @@ async def test_message_parts_with_tool_return(sentry_init, capture_events): """ Test that ToolReturnPart messages are handled correctly. """ - from pydantic_ai import Agent, messages + from pydantic_ai import Agent agent = Agent( "test", @@ -2509,7 +2508,6 @@ async def test_tool_execution_without_span_context(sentry_init, capture_events): This tests the code path where current_span is None in _patch_tool_execution. """ # Import the patching function - from unittest.mock import AsyncMock, MagicMock sentry_init( integrations=[PydanticAIIntegration()], diff --git a/tests/integrations/stdlib/test_httplib.py b/tests/integrations/stdlib/test_httplib.py index ad6b0688b9..cdbf6cd68c 100644 --- a/tests/integrations/stdlib/test_httplib.py +++ b/tests/integrations/stdlib/test_httplib.py @@ -1,6 +1,5 @@ import os import datetime -import socket from http.client import HTTPConnection, HTTPSConnection from http.server import BaseHTTPRequestHandler, HTTPServer from socket import SocketIO diff --git a/tests/integrations/strawberry/test_strawberry.py b/tests/integrations/strawberry/test_strawberry.py index ba645da257..d3174ed857 100644 --- a/tests/integrations/strawberry/test_strawberry.py +++ b/tests/integrations/strawberry/test_strawberry.py @@ -5,7 +5,6 @@ pytest.importorskip("fastapi") pytest.importorskip("flask") -from unittest import mock from fastapi import FastAPI from fastapi.testclient import TestClient diff --git a/tests/test_ai_integration_deactivation.py b/tests/test_ai_integration_deactivation.py index b02b64c6ee..683de2f0b2 100644 --- a/tests/test_ai_integration_deactivation.py +++ b/tests/test_ai_integration_deactivation.py @@ -190,7 +190,6 @@ def test_langchain_and_openai_both_explicit_both_active( def test_no_langchain_means_openai_and_anthropic_can_auto_enable( sentry_init, reset_integrations, monkeypatch ): - import sys import sentry_sdk.integrations old_iter = sentry_sdk.integrations.iter_default_integrations diff --git a/tests/test_ai_monitoring.py b/tests/test_ai_monitoring.py index 969d14658d..a88fe33696 100644 --- a/tests/test_ai_monitoring.py +++ b/tests/test_ai_monitoring.py @@ -1,19 +1,14 @@ -import json -import uuid - import pytest import sentry_sdk from sentry_sdk._types import ( AnnotatedValue, - SENSITIVE_DATA_SUBSTITUTE, BLOB_DATA_SUBSTITUTE, ) from sentry_sdk.ai.monitoring import ai_track from sentry_sdk.ai.utils import ( MAX_GEN_AI_MESSAGE_BYTES, MAX_SINGLE_MESSAGE_CONTENT_CHARS, - set_data_normalized, truncate_and_annotate_messages, truncate_messages_by_size, _find_truncation_index, @@ -27,7 +22,6 @@ transform_content_part, transform_message_content, ) -from sentry_sdk.serializer import serialize from sentry_sdk.utils import safe_serialize diff --git a/tests/test_logs.py b/tests/test_logs.py index d9c8a79f8c..4a78725bb1 100644 --- a/tests/test_logs.py +++ b/tests/test_logs.py @@ -2,14 +2,14 @@ import logging import sys import time -from typing import List, Any, Mapping, Union +from typing import List, Any, Mapping import pytest from unittest import mock import sentry_sdk import sentry_sdk.logger from sentry_sdk import get_client -from sentry_sdk.envelope import Envelope, Item, PayloadRef +from sentry_sdk.envelope import Envelope from sentry_sdk.types import Log from sentry_sdk.consts import SPANDATA, VERSION diff --git a/tests/test_metrics.py b/tests/test_metrics.py index ada50d645d..3ad3f6042d 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -1,9 +1,6 @@ -import json -import sys -from typing import List, Any, Mapping +from typing import List from unittest import mock -import pytest import sentry_sdk from sentry_sdk import get_client diff --git a/tests/test_shadowed_module.py b/tests/test_shadowed_module.py index 10d86f285b..8beb93dc36 100644 --- a/tests/test_shadowed_module.py +++ b/tests/test_shadowed_module.py @@ -7,7 +7,6 @@ import pytest from sentry_sdk import integrations -from sentry_sdk.integrations import _DEFAULT_INTEGRATIONS, Integration def pytest_generate_tests(metafunc): diff --git a/tests/test_spotlight.py b/tests/test_spotlight.py index f554ff7c5b..1e304e5e54 100644 --- a/tests/test_spotlight.py +++ b/tests/test_spotlight.py @@ -1,7 +1,6 @@ import pytest import sentry_sdk -from sentry_sdk.spotlight import DEFAULT_SPOTLIGHT_URL @pytest.fixture diff --git a/tests/tracing/test_decorator.py b/tests/tracing/test_decorator.py index 70dc186ba0..15432f5862 100644 --- a/tests/tracing/test_decorator.py +++ b/tests/tracing/test_decorator.py @@ -1,5 +1,4 @@ import inspect -import sys from unittest import mock import pytest diff --git a/tests/tracing/test_deprecated.py b/tests/tracing/test_deprecated.py index ac3b8d7463..f030a465ff 100644 --- a/tests/tracing/test_deprecated.py +++ b/tests/tracing/test_deprecated.py @@ -4,9 +4,6 @@ import sentry_sdk import sentry_sdk.tracing -from sentry_sdk import start_span - -from sentry_sdk.tracing import Span @pytest.mark.parametrize( diff --git a/tests/tracing/test_sampling.py b/tests/tracing/test_sampling.py index c0f307ecf7..93c1106c99 100644 --- a/tests/tracing/test_sampling.py +++ b/tests/tracing/test_sampling.py @@ -5,7 +5,7 @@ import pytest import sentry_sdk -from sentry_sdk import start_span, start_transaction, capture_exception, continue_trace +from sentry_sdk import start_span, start_transaction, capture_exception from sentry_sdk.tracing_utils import Baggage from sentry_sdk.utils import logger From e2c90e0242780a002c2937b4e0d404c6b50b3688 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Thu, 12 Mar 2026 14:45:40 +0100 Subject: [PATCH 2/3] . --- pyproject.toml | 1 - sentry_sdk/ai/__init__.py | 14 +++++++------- .../integrations/openai_agents/patches/__init__.py | 10 +++++----- .../integrations/openai_agents/spans/__init__.py | 8 ++++---- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 4b3d72ea09..b090d9bd4d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -227,7 +227,6 @@ ignore = [ "N804", # First argument of classmethod should be named cls # Additional ignores for codebase compatibility - "F401", # Unused imports - many in TYPE_CHECKING blocks used for type comments "E721", # Use isinstance instead of type() == - existing pattern in this codebase ] diff --git a/sentry_sdk/ai/__init__.py b/sentry_sdk/ai/__init__.py index 7f0d9f92f7..3e5f13727b 100644 --- a/sentry_sdk/ai/__init__.py +++ b/sentry_sdk/ai/__init__.py @@ -1,8 +1,8 @@ from .utils import ( - set_data_normalized, - GEN_AI_MESSAGE_ROLE_MAPPING, - GEN_AI_MESSAGE_ROLE_REVERSE_MAPPING, - normalize_message_role, - normalize_message_roles, - set_conversation_id, -) # noqa: F401 + set_data_normalized, # noqa: F401 + GEN_AI_MESSAGE_ROLE_MAPPING, # noqa: F401 + GEN_AI_MESSAGE_ROLE_REVERSE_MAPPING, # noqa: F401 + normalize_message_role, # noqa: F401 + normalize_message_roles, # noqa: F401 + set_conversation_id, # noqa: F401 +) diff --git a/sentry_sdk/integrations/openai_agents/patches/__init__.py b/sentry_sdk/integrations/openai_agents/patches/__init__.py index e3be2776b3..9ab9e7fab6 100644 --- a/sentry_sdk/integrations/openai_agents/patches/__init__.py +++ b/sentry_sdk/integrations/openai_agents/patches/__init__.py @@ -2,9 +2,9 @@ from .tools import _get_all_tools # noqa: F401 from .runner import _create_run_wrapper, _create_run_streamed_wrapper # noqa: F401 from .agent_run import ( - _run_single_turn, - _run_single_turn_streamed, - _execute_handoffs, - _execute_final_output, -) # noqa: F401 + _run_single_turn, # noqa: F401 + _run_single_turn_streamed, # noqa: F401 + _execute_handoffs, # noqa: F401 + _execute_final_output, # noqa: F401 +) from .error_tracing import _patch_error_tracing # noqa: F401 diff --git a/sentry_sdk/integrations/openai_agents/spans/__init__.py b/sentry_sdk/integrations/openai_agents/spans/__init__.py index 64b979fc25..2187c4ee51 100644 --- a/sentry_sdk/integrations/openai_agents/spans/__init__.py +++ b/sentry_sdk/integrations/openai_agents/spans/__init__.py @@ -3,7 +3,7 @@ from .execute_tool import execute_tool_span, update_execute_tool_span # noqa: F401 from .handoff import handoff_span # noqa: F401 from .invoke_agent import ( - invoke_agent_span, - update_invoke_agent_span, - end_invoke_agent_span, -) # noqa: F401 + invoke_agent_span, # noqa: F401 + update_invoke_agent_span, # noqa: F401 + end_invoke_agent_span, # noqa: F401 +) From 6a938158f0ffdcdd4b671876baa4bc9cd731f4ae Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Thu, 12 Mar 2026 14:51:35 +0100 Subject: [PATCH 3/3] fix log tests --- tests/test_logs.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/test_logs.py b/tests/test_logs.py index 4a78725bb1..5eb699f534 100644 --- a/tests/test_logs.py +++ b/tests/test_logs.py @@ -2,7 +2,7 @@ import logging import sys import time -from typing import List, Any, Mapping +from typing import List, Any, Mapping, Union import pytest from unittest import mock @@ -19,8 +19,7 @@ def otel_attributes_to_dict(otel_attrs: "Mapping[str, Any]") -> "Mapping[str, Any]": - def _convert_attr(attr): - # type: (Mapping[str, Union[str, float, bool]]) -> Any + def _convert_attr(attr: "Mapping[str, Union[str, float, bool]]") -> "Any": if attr["type"] == "boolean": return attr["value"] if attr["type"] == "double":