Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

perf: Avoid scanning installed packages when MCP SDK is not installed - #6865

#6865
Open
mangodxd wants to merge 1 commit into
getsentry:mastergetsentry/sentry-python:masterfrom
mangodxd:fix/gh-6769-lazy-package-version-mcpmangodxd/sentry-python:fix/gh-6769-lazy-package-version-mcpCopy head branch name to clipboard
Open

perf: Avoid scanning installed packages when MCP SDK is not installed#6865
mangodxd wants to merge 1 commit into
getsentry:mastergetsentry/sentry-python:masterfrom
mangodxd:fix/gh-6769-lazy-package-version-mcpmangodxd/sentry-python:fix/gh-6769-lazy-package-version-mcpCopy head branch name to clipboard

Conversation

@mangodxd

Copy link
Copy Markdown

WHY

When the MCP SDK is not installed, module-level package_version("mcp") at the top of sentry_sdk/integrations/mcp.py scans every installed distribution via _get_installed_modules(). This slows sentry_sdk.init() by ~0.2s in environments with hundreds of packages.

Issue #6769 reports that this regression was introduced by #6583, which added a module-level MCP_PACKAGE_VERSION = package_version("mcp") above the try/except ImportError guard.

HOW

Move MCP_PACKAGE_VERSION = package_version("mcp") from module-level (above the guard) to inside the try block, after the successful import mcp. When import mcp fails and DidNotEnable is raised, package_version() is never called — so environments without MCP skip the expensive distribution scan entirely.

…getsentry#6769)

When mcp SDK is not installed, module-level package_version('mcp') at
the top of sentry_sdk/integrations/mcp.py scans every installed
distribution, slowing sentry_sdk.init() by ~200ms in environments
with hundreds of packages.

Move the call below the 	ry/except ImportError guard so it only runs
when import mcp succeeds. Environments without mcp skip the scan
entirely.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@mangodxd
mangodxd requested a review from a team as a code owner July 23, 2026 11:08
@mangodxd
mangodxd force-pushed the fix/gh-6769-lazy-package-version-mcp branch from 01cf58a to 07564c8 Compare July 23, 2026 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Morty Proxy This is a proxified and sanitized view of the page, visit original site.