Skip to content

Conversation

@alexander-alderman-webb
Copy link
Contributor

@alexander-alderman-webb alexander-alderman-webb commented Nov 26, 2025

Add a test parametrized on our integrations. The test detects if the integration imports modules not in the standard library, and if so, verifies that importing the integration with an empty shadow module raises a DidNotEnable exception.

Motivation

Adding integrations to be auto-enabling can cause SDK crashes in two specific cases we encountered at the end of last week:

  • the user has an old package version that we don’t support, resulting in an ImportError when we patch something that does not yet exist; or
  • something like an agents.py in the environment shadows the import and causes an ImportError if the auto-activation still triggers.

All integrations with poorly gated imports are not auto-enabling, but some affected integrations are new (e.g., litellm).

Issues

Closes #5140

Reminders

@codecov
Copy link

codecov bot commented Nov 26, 2025

❌ 2 Tests Failed:

Tests completed Failed Passed Skipped
28653 2 28651 2319
View the top 2 failed test(s) by shortest run time
tests.test_shadowed_module::test_shadowed_modules_when_importing_integrations
Stack Traces | 0.042s run time
tests/test_shadowed_module.py:74: in test_shadowed_modules_when_importing_integrations
    importlib.import_module(module_path)
.../local/lib/python3.6/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:994: in _gcd_import
    ???
<frozen importlib._bootstrap>:971: in _find_and_load
    ???
<frozen importlib._bootstrap>:955: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:665: in _load_unlocked
    ???
<frozen importlib._bootstrap_external>:674: in exec_module
    ???
<frozen importlib._bootstrap_external>:781: in get_code
    ???
<frozen importlib._bootstrap_external>:741: in source_to_code
    ???
<frozen importlib._bootstrap>:219: in _call_with_frames_removed
    ???
E     File ".../sentry_sdk/integrations/asyncpg.py", line 1
E       from __future__ import annotations
E                                        ^
E   SyntaxError: future feature annotations is not defined
tests.test_shadowed_module::test_shadowed_modules_when_importing_integrations
Stack Traces | 0.042s run time
tests/test_shadowed_module.py:74: in test_shadowed_modules_when_importing_integrations
    importlib.import_module(module_path)
.../local/lib/python3.6/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:994: in _gcd_import
    ???
<frozen importlib._bootstrap>:971: in _find_and_load
    ???
<frozen importlib._bootstrap>:955: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:665: in _load_unlocked
    ???
<frozen importlib._bootstrap_external>:674: in exec_module
    ???
<frozen importlib._bootstrap_external>:781: in get_code
    ???
<frozen importlib._bootstrap_external>:741: in source_to_code
    ???
<frozen importlib._bootstrap>:219: in _call_with_frames_removed
    ???
E     File ".../sentry_sdk/integrations/asyncpg.py", line 1
E       from __future__ import annotations
E                                        ^
E   SyntaxError: future feature annotations is not defined

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

Comment on lines 63 to 74
# Temporary skip list
if submodule_name in (
"clickhouse_driver",
"grpc",
"litellm",
"opentelemetry",
"pure_eval",
"ray",
"trytond",
"typer",
):
continue
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we merge this test, my plan is to remove integrations from the skip list one-by-one.

@alexander-alderman-webb alexander-alderman-webb marked this pull request as ready for review November 26, 2025 10:09
@alexander-alderman-webb alexander-alderman-webb requested a review from a team as a code owner November 26, 2025 10:09
Comment on lines 85 to 87
sys.modules[dependency] = types.ModuleType(dependency)
with pytest.raises(integrations.DidNotEnable):
importlib.import_module(module_path)

This comment was marked as outdated.

Copy link
Contributor Author

@alexander-alderman-webb alexander-alderman-webb Nov 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to parametrize the test and fork it because messing with sys.modules and importing can cause side-effects and influence other tests otherwise.

edit: I don't like adding more forked tests. I'll move the test into it's own tox environment so there's no risk of messing with the behavior of other tests when removing the forking.

@alexander-alderman-webb alexander-alderman-webb marked this pull request as draft November 26, 2025 10:12
@alexander-alderman-webb alexander-alderman-webb marked this pull request as ready for review November 27, 2025 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test integrations with empty shadow modules

2 participants