From df7b0d88805806996d6d328ef726a88f6f7d2b2a Mon Sep 17 00:00:00 2001 From: Simon Hellmayr Date: Mon, 12 Jan 2026 13:20:14 +0100 Subject: [PATCH 1/5] chore(gen_ai): add auto-enablement for google genai and litellm --- sentry_sdk/integrations/__init__.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sentry_sdk/integrations/__init__.py b/sentry_sdk/integrations/__init__.py index 5ab181df25..dac11a80d8 100644 --- a/sentry_sdk/integrations/__init__.py +++ b/sentry_sdk/integrations/__init__.py @@ -81,12 +81,14 @@ def iter_default_integrations( "sentry_sdk.integrations.fastapi.FastApiIntegration", "sentry_sdk.integrations.flask.FlaskIntegration", "sentry_sdk.integrations.gql.GQLIntegration", + "sentry_sdk.integrations.google_genai.GoogleGenAIIntegration", "sentry_sdk.integrations.graphene.GrapheneIntegration", "sentry_sdk.integrations.httpx.HttpxIntegration", "sentry_sdk.integrations.huey.HueyIntegration", "sentry_sdk.integrations.huggingface_hub.HuggingfaceHubIntegration", "sentry_sdk.integrations.langchain.LangchainIntegration", "sentry_sdk.integrations.langgraph.LanggraphIntegration", + "sentry_sdk.integrations.litellm.LiteLLMIntegration", "sentry_sdk.integrations.litestar.LitestarIntegration", "sentry_sdk.integrations.loguru.LoguruIntegration", "sentry_sdk.integrations.mcp.MCPIntegration", @@ -166,6 +168,7 @@ def iter_default_integrations( _INTEGRATION_DEACTIVATES = { "langchain": {"openai", "anthropic"}, + "litellm": {"openai", "anthropic"}, "openai_agents": {"openai"}, "pydantic_ai": {"openai", "anthropic"}, } From d29ddb8fda8aa802a550470585e234f5276d610b Mon Sep 17 00:00:00 2001 From: Simon Hellmayr Date: Tue, 13 Jan 2026 13:01:56 +0100 Subject: [PATCH 2/5] fix test --- tests/integrations/litellm/test_litellm.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/integrations/litellm/test_litellm.py b/tests/integrations/litellm/test_litellm.py index 1b925fb61f..798fa07d31 100644 --- a/tests/integrations/litellm/test_litellm.py +++ b/tests/integrations/litellm/test_litellm.py @@ -566,10 +566,15 @@ def test_litellm_specific_parameters(sentry_init, capture_events): assert span["data"]["gen_ai.litellm.custom_llm_provider"] == "custom_provider" -def test_no_integration(sentry_init, capture_events): +def test_no_integration( + sentry_init, capture_events, reset_integrations, uninstall_integration +): """Test that when integration is not enabled, callbacks don't break.""" + # Reset integrations since LiteLLM is now auto-enabled and we need to test + # the behavior when it's explicitly disabled sentry_init( traces_sample_rate=1.0, + disabled_integrations=[LiteLLMIntegration], ) events = capture_events() @@ -597,6 +602,9 @@ def test_no_integration(sentry_init, capture_events): assert event["type"] == "transaction" assert len(event.get("spans", [])) == 0 + # Clean up: uninstall litellm so subsequent tests can re-install it + uninstall_integration("litellm") + def test_response_without_usage(sentry_init, capture_events): """Test handling of responses without usage information.""" From 84740ff8b1329082cf9fa58b479e3707b10867ed Mon Sep 17 00:00:00 2001 From: Simon Hellmayr Date: Tue, 13 Jan 2026 13:30:05 +0100 Subject: [PATCH 3/5] remove litellm --- sentry_sdk/integrations/__init__.py | 2 -- tests/integrations/litellm/test_litellm.py | 10 +--------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/sentry_sdk/integrations/__init__.py b/sentry_sdk/integrations/__init__.py index dac11a80d8..4d56e0df73 100644 --- a/sentry_sdk/integrations/__init__.py +++ b/sentry_sdk/integrations/__init__.py @@ -88,7 +88,6 @@ def iter_default_integrations( "sentry_sdk.integrations.huggingface_hub.HuggingfaceHubIntegration", "sentry_sdk.integrations.langchain.LangchainIntegration", "sentry_sdk.integrations.langgraph.LanggraphIntegration", - "sentry_sdk.integrations.litellm.LiteLLMIntegration", "sentry_sdk.integrations.litestar.LitestarIntegration", "sentry_sdk.integrations.loguru.LoguruIntegration", "sentry_sdk.integrations.mcp.MCPIntegration", @@ -168,7 +167,6 @@ def iter_default_integrations( _INTEGRATION_DEACTIVATES = { "langchain": {"openai", "anthropic"}, - "litellm": {"openai", "anthropic"}, "openai_agents": {"openai"}, "pydantic_ai": {"openai", "anthropic"}, } diff --git a/tests/integrations/litellm/test_litellm.py b/tests/integrations/litellm/test_litellm.py index 798fa07d31..1b925fb61f 100644 --- a/tests/integrations/litellm/test_litellm.py +++ b/tests/integrations/litellm/test_litellm.py @@ -566,15 +566,10 @@ def test_litellm_specific_parameters(sentry_init, capture_events): assert span["data"]["gen_ai.litellm.custom_llm_provider"] == "custom_provider" -def test_no_integration( - sentry_init, capture_events, reset_integrations, uninstall_integration -): +def test_no_integration(sentry_init, capture_events): """Test that when integration is not enabled, callbacks don't break.""" - # Reset integrations since LiteLLM is now auto-enabled and we need to test - # the behavior when it's explicitly disabled sentry_init( traces_sample_rate=1.0, - disabled_integrations=[LiteLLMIntegration], ) events = capture_events() @@ -602,9 +597,6 @@ def test_no_integration( assert event["type"] == "transaction" assert len(event.get("spans", [])) == 0 - # Clean up: uninstall litellm so subsequent tests can re-install it - uninstall_integration("litellm") - def test_response_without_usage(sentry_init, capture_events): """Test handling of responses without usage information.""" From d96fb3f06a5bb00ad8e654faf7163cdfc9902ead Mon Sep 17 00:00:00 2001 From: Simon Hellmayr Date: Tue, 13 Jan 2026 13:42:55 +0100 Subject: [PATCH 4/5] fix(google_genai): Add minimum version check in setup_once The GoogleGenAI integration is auto-enabled but was not checking the minimum version (1.29.0) before attempting to patch methods. This could cause AttributeError crashes during Sentry initialization if a user has an older version of google-genai installed. Add _check_minimum_version call in setup_once() to ensure graceful handling of incompatible versions, matching the pattern used by other auto-enabled integrations like Anthropic. Co-Authored-By: Claude Sonnet 4.5 --- sentry_sdk/integrations/google_genai/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sentry_sdk/integrations/google_genai/__init__.py b/sentry_sdk/integrations/google_genai/__init__.py index 27a42f4f6a..e482f51cfd 100644 --- a/sentry_sdk/integrations/google_genai/__init__.py +++ b/sentry_sdk/integrations/google_genai/__init__.py @@ -45,6 +45,12 @@ def __init__(self: "GoogleGenAIIntegration", include_prompts: bool = True) -> No @staticmethod def setup_once() -> None: + from sentry_sdk.integrations import _check_minimum_version + from sentry_sdk.utils import package_version + + version = package_version("google-genai") + _check_minimum_version(GoogleGenAIIntegration, version, package="google-genai") + # Patch sync methods Models.generate_content = _wrap_generate_content(Models.generate_content) Models.generate_content_stream = _wrap_generate_content_stream( From 9771645dc0d1816a15a203b950ccae2ea5a72b6d Mon Sep 17 00:00:00 2001 From: Simon Hellmayr Date: Tue, 13 Jan 2026 13:46:24 +0100 Subject: [PATCH 5/5] remove version check --- sentry_sdk/integrations/google_genai/__init__.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/sentry_sdk/integrations/google_genai/__init__.py b/sentry_sdk/integrations/google_genai/__init__.py index e482f51cfd..27a42f4f6a 100644 --- a/sentry_sdk/integrations/google_genai/__init__.py +++ b/sentry_sdk/integrations/google_genai/__init__.py @@ -45,12 +45,6 @@ def __init__(self: "GoogleGenAIIntegration", include_prompts: bool = True) -> No @staticmethod def setup_once() -> None: - from sentry_sdk.integrations import _check_minimum_version - from sentry_sdk.utils import package_version - - version = package_version("google-genai") - _check_minimum_version(GoogleGenAIIntegration, version, package="google-genai") - # Patch sync methods Models.generate_content = _wrap_generate_content(Models.generate_content) Models.generate_content_stream = _wrap_generate_content_stream(