-
Notifications
You must be signed in to change notification settings - Fork 568
feat(integrations): add ability to auto-deactivate lower-level integrations based on map #5052
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
shellmayr
merged 7 commits into
master
from
shellmayr/feat/auto-deactivate-lower-level-integartions
Nov 4, 2025
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
078c8d1
feat(integrations): add ability to auto-deactivate lower-level integr…
shellmayr 1c9a231
types
shellmayr 4ac8df8
work in review comments
shellmayr 4db7783
remove forking
alexander-alderman-webb 3697471
ci: Add tests for deactivating integrations to misc workflow (#5061)
alexander-alderman-webb d6c7379
Merge branch 'master' into shellmayr/feat/auto-deactivate-lower-level…
alexander-alderman-webb b34d342
merge
alexander-alderman-webb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -154,6 +154,7 @@ | |
| "pure_eval", | ||
| "trytond", | ||
| "typer", | ||
| "integration_deactivation", | ||
| ], | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,222 @@ | ||
| import pytest | ||
|
|
||
| from sentry_sdk import get_client | ||
| from sentry_sdk.integrations import _INTEGRATION_DEACTIVATES | ||
|
|
||
|
|
||
| try: | ||
| from sentry_sdk.integrations.langchain import LangchainIntegration | ||
|
|
||
| has_langchain = True | ||
| except Exception: | ||
| has_langchain = False | ||
|
|
||
| try: | ||
| from sentry_sdk.integrations.openai import OpenAIIntegration | ||
|
|
||
| has_openai = True | ||
| except Exception: | ||
| has_openai = False | ||
|
|
||
| try: | ||
| from sentry_sdk.integrations.anthropic import AnthropicIntegration | ||
|
|
||
| has_anthropic = True | ||
| except Exception: | ||
| has_anthropic = False | ||
|
|
||
|
|
||
| pytestmark = pytest.mark.skipif( | ||
| not (has_langchain and has_openai and has_anthropic), | ||
| reason="Requires langchain, openai, and anthropic packages to be installed", | ||
| ) | ||
|
|
||
|
|
||
| def test_integration_deactivates_map_exists(): | ||
| assert "langchain" in _INTEGRATION_DEACTIVATES | ||
| assert "openai" in _INTEGRATION_DEACTIVATES["langchain"] | ||
| assert "anthropic" in _INTEGRATION_DEACTIVATES["langchain"] | ||
|
|
||
|
|
||
| def test_langchain_auto_deactivates_openai_and_anthropic( | ||
| sentry_init, reset_integrations | ||
| ): | ||
| sentry_init( | ||
| default_integrations=False, | ||
| auto_enabling_integrations=True, | ||
| ) | ||
|
|
||
| client = get_client() | ||
| integration_types = { | ||
| type(integration) for integration in client.integrations.values() | ||
| } | ||
|
|
||
| if LangchainIntegration in integration_types: | ||
| assert OpenAIIntegration not in integration_types | ||
| assert AnthropicIntegration not in integration_types | ||
|
|
||
|
|
||
| def test_user_can_override_with_explicit_openai(sentry_init, reset_integrations): | ||
| sentry_init( | ||
| default_integrations=False, | ||
| auto_enabling_integrations=True, | ||
| integrations=[OpenAIIntegration()], | ||
| ) | ||
|
|
||
| client = get_client() | ||
| integration_types = { | ||
| type(integration) for integration in client.integrations.values() | ||
| } | ||
|
|
||
| assert OpenAIIntegration in integration_types | ||
|
|
||
|
|
||
| def test_user_can_override_with_explicit_anthropic(sentry_init, reset_integrations): | ||
| sentry_init( | ||
| default_integrations=False, | ||
| auto_enabling_integrations=True, | ||
| integrations=[AnthropicIntegration()], | ||
| ) | ||
|
|
||
| client = get_client() | ||
| integration_types = { | ||
| type(integration) for integration in client.integrations.values() | ||
| } | ||
|
|
||
| assert AnthropicIntegration in integration_types | ||
|
|
||
|
|
||
| def test_user_can_override_with_both_explicit_integrations( | ||
| sentry_init, reset_integrations | ||
| ): | ||
| sentry_init( | ||
| default_integrations=False, | ||
| auto_enabling_integrations=True, | ||
| integrations=[OpenAIIntegration(), AnthropicIntegration()], | ||
| ) | ||
|
|
||
| client = get_client() | ||
| integration_types = { | ||
| type(integration) for integration in client.integrations.values() | ||
| } | ||
|
|
||
| assert OpenAIIntegration in integration_types | ||
| assert AnthropicIntegration in integration_types | ||
|
|
||
|
|
||
| def test_disabling_langchain_allows_openai_and_anthropic( | ||
| sentry_init, reset_integrations | ||
| ): | ||
| sentry_init( | ||
| default_integrations=False, | ||
| auto_enabling_integrations=True, | ||
| disabled_integrations=[LangchainIntegration], | ||
| ) | ||
|
|
||
| client = get_client() | ||
| integration_types = { | ||
| type(integration) for integration in client.integrations.values() | ||
| } | ||
|
|
||
| assert LangchainIntegration not in integration_types | ||
|
|
||
|
|
||
| def test_explicit_langchain_still_deactivates_others(sentry_init, reset_integrations): | ||
| sentry_init( | ||
| default_integrations=False, | ||
| auto_enabling_integrations=False, | ||
| integrations=[LangchainIntegration()], | ||
| ) | ||
|
|
||
| client = get_client() | ||
| integration_types = { | ||
| type(integration) for integration in client.integrations.values() | ||
| } | ||
|
|
||
| if LangchainIntegration in integration_types: | ||
| assert OpenAIIntegration not in integration_types | ||
| assert AnthropicIntegration not in integration_types | ||
|
|
||
|
|
||
| def test_langchain_and_openai_both_explicit_both_active( | ||
| sentry_init, reset_integrations | ||
| ): | ||
| sentry_init( | ||
| default_integrations=False, | ||
| auto_enabling_integrations=False, | ||
| integrations=[LangchainIntegration(), OpenAIIntegration()], | ||
| ) | ||
|
|
||
| client = get_client() | ||
| integration_types = { | ||
| type(integration) for integration in client.integrations.values() | ||
| } | ||
|
|
||
| assert LangchainIntegration in integration_types | ||
| assert OpenAIIntegration in integration_types | ||
|
|
||
|
|
||
| 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 | ||
|
|
||
| def filtered_iter(with_auto_enabling): | ||
| for cls in old_iter(with_auto_enabling): | ||
| if cls.identifier != "langchain": | ||
| yield cls | ||
|
|
||
| monkeypatch.setattr( | ||
| sentry_sdk.integrations, "iter_default_integrations", filtered_iter | ||
| ) | ||
|
|
||
| sentry_init( | ||
| default_integrations=False, | ||
| auto_enabling_integrations=True, | ||
| ) | ||
|
|
||
| client = get_client() | ||
| integration_types = { | ||
| type(integration) for integration in client.integrations.values() | ||
| } | ||
|
|
||
| assert LangchainIntegration not in integration_types | ||
|
|
||
alexander-alderman-webb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def test_deactivation_with_default_integrations_enabled( | ||
| sentry_init, reset_integrations | ||
| ): | ||
| sentry_init( | ||
| default_integrations=True, | ||
| auto_enabling_integrations=True, | ||
| ) | ||
|
|
||
| client = get_client() | ||
| integration_types = { | ||
| type(integration) for integration in client.integrations.values() | ||
| } | ||
|
|
||
| if LangchainIntegration in integration_types: | ||
| assert OpenAIIntegration not in integration_types | ||
| assert AnthropicIntegration not in integration_types | ||
|
|
||
|
|
||
| def test_only_auto_enabling_integrations_without_defaults( | ||
| sentry_init, reset_integrations | ||
| ): | ||
| sentry_init( | ||
| default_integrations=False, | ||
| auto_enabling_integrations=True, | ||
| ) | ||
|
|
||
| client = get_client() | ||
| integration_types = { | ||
| type(integration) for integration in client.integrations.values() | ||
| } | ||
|
|
||
| if LangchainIntegration in integration_types: | ||
| assert OpenAIIntegration not in integration_types | ||
| assert AnthropicIntegration not in integration_types | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.