From da4b65f5985e4c6e34f9506c867b672d35365d6b Mon Sep 17 00:00:00 2001 From: Fabian Schindler Date: Wed, 3 Dec 2025 18:09:57 +0100 Subject: [PATCH 1/5] fix(integrations): add values for pydantic-ai and openai-agents to `_INTEGRATION_DEACTIVATES` to prohibit double span creation --- sentry_sdk/integrations/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sentry_sdk/integrations/__init__.py b/sentry_sdk/integrations/__init__.py index 4c286c87fe..fea7f100e0 100644 --- a/sentry_sdk/integrations/__init__.py +++ b/sentry_sdk/integrations/__init__.py @@ -176,6 +176,8 @@ def iter_default_integrations(with_auto_enabling_integrations): _INTEGRATION_DEACTIVATES = { "langchain": {"openai", "anthropic"}, + "openai_agents": {"openai"}, + "pydantic_ai": {"openai"}, } From f6af4b8e1357fe28dd64263ce7e831851eb00b1c Mon Sep 17 00:00:00 2001 From: Fabian Schindler Date: Wed, 3 Dec 2025 22:21:21 +0100 Subject: [PATCH 2/5] test: extend integration deactivation tests --- tests/test_ai_integration_deactivation.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/test_ai_integration_deactivation.py b/tests/test_ai_integration_deactivation.py index 71ac4f70a9..8c8c8fee31 100644 --- a/tests/test_ai_integration_deactivation.py +++ b/tests/test_ai_integration_deactivation.py @@ -2,6 +2,8 @@ from sentry_sdk import get_client from sentry_sdk.integrations import _INTEGRATION_DEACTIVATES +from sentry_sdk.integrations.openai_agents import OpenAIAgentsIntegration +from sentry_sdk.integrations.pydantic_ai import PydanticAIIntegration try: @@ -36,6 +38,10 @@ def test_integration_deactivates_map_exists(): assert "langchain" in _INTEGRATION_DEACTIVATES assert "openai" in _INTEGRATION_DEACTIVATES["langchain"] assert "anthropic" in _INTEGRATION_DEACTIVATES["langchain"] + assert "openai_agents" in _INTEGRATION_DEACTIVATES + assert "openai" in _INTEGRATION_DEACTIVATES["openai_agents"] + assert "pydantic_ai" in _INTEGRATION_DEACTIVATES + assert "openai" in _INTEGRATION_DEACTIVATES["pydantic_ai"] def test_langchain_auto_deactivates_openai_and_anthropic( @@ -104,13 +110,17 @@ def test_user_can_override_with_both_explicit_integrations( assert AnthropicIntegration in integration_types -def test_disabling_langchain_allows_openai_and_anthropic( +def test_disabling_integrations_allows_openai_and_anthropic( sentry_init, reset_integrations ): sentry_init( default_integrations=False, auto_enabling_integrations=True, - disabled_integrations=[LangchainIntegration], + disabled_integrations=[ + LangchainIntegration, + OpenAIAgentsIntegration, + PydanticAIIntegration, + ], ) client = get_client() From 8378c347605c6cc5fe00c6ca04a37a58887366dc Mon Sep 17 00:00:00 2001 From: Fabian Schindler Date: Fri, 5 Dec 2025 09:16:32 +0100 Subject: [PATCH 3/5] test: fix tests to skip when dependencies have not been installed --- tests/test_ai_integration_deactivation.py | 25 ++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/tests/test_ai_integration_deactivation.py b/tests/test_ai_integration_deactivation.py index 8c8c8fee31..781a304d83 100644 --- a/tests/test_ai_integration_deactivation.py +++ b/tests/test_ai_integration_deactivation.py @@ -2,8 +2,6 @@ from sentry_sdk import get_client from sentry_sdk.integrations import _INTEGRATION_DEACTIVATES -from sentry_sdk.integrations.openai_agents import OpenAIAgentsIntegration -from sentry_sdk.integrations.pydantic_ai import PydanticAIIntegration try: @@ -28,8 +26,29 @@ has_anthropic = False +try: + from sentry_sdk.integrations.openai_agents import OpenAIAgentsIntegration + + has_openai_agents = True +except Exception: + has_openai_agents = False + +try: + from sentry_sdk.integrations.pydantic_ai import PydanticAIIntegration + + has_pydantic_ai = True +except Exception: + has_pydantic_ai = False + + pytestmark = pytest.mark.skipif( - not (has_langchain and has_openai and has_anthropic), + not ( + has_langchain + and has_openai + and has_anthropic + and has_openai_agents + and has_pydantic_ai + ), reason="Requires langchain, openai, and anthropic packages to be installed", ) From 13d5fa6491e32f35791fe38d15b8bc8c4c7ecec7 Mon Sep 17 00:00:00 2001 From: Fabian Schindler Date: Fri, 5 Dec 2025 09:19:08 +0100 Subject: [PATCH 4/5] fix: pydantic-ai should also deactivate anthropic --- sentry_sdk/integrations/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sentry_sdk/integrations/__init__.py b/sentry_sdk/integrations/__init__.py index fea7f100e0..b340dec36e 100644 --- a/sentry_sdk/integrations/__init__.py +++ b/sentry_sdk/integrations/__init__.py @@ -177,7 +177,7 @@ def iter_default_integrations(with_auto_enabling_integrations): _INTEGRATION_DEACTIVATES = { "langchain": {"openai", "anthropic"}, "openai_agents": {"openai"}, - "pydantic_ai": {"openai"}, + "pydantic_ai": {"openai", "anthropic"}, } From 5178a1120bf754be4f247e533f1e5b676794958e Mon Sep 17 00:00:00 2001 From: Fabian Schindler Date: Fri, 5 Dec 2025 09:28:06 +0100 Subject: [PATCH 5/5] test: fix test to include anthropic deactivation --- tests/test_ai_integration_deactivation.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_ai_integration_deactivation.py b/tests/test_ai_integration_deactivation.py index 781a304d83..dc8aef6be8 100644 --- a/tests/test_ai_integration_deactivation.py +++ b/tests/test_ai_integration_deactivation.py @@ -61,6 +61,7 @@ def test_integration_deactivates_map_exists(): assert "openai" in _INTEGRATION_DEACTIVATES["openai_agents"] assert "pydantic_ai" in _INTEGRATION_DEACTIVATES assert "openai" in _INTEGRATION_DEACTIVATES["pydantic_ai"] + assert "anthropic" in _INTEGRATION_DEACTIVATES["pydantic_ai"] def test_langchain_auto_deactivates_openai_and_anthropic(