| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
…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>
There was a problem hiding this comment.
LGTM — moving package_version("mcp") inside the try block skips the import-time package scan whenever MCP is not installed, which is a nice small perf win for the common case.
I checked the safety of the move: MCP_PACKAGE_VERSION is still referenced at module level outside the try (the version-gated imports and _patch_* selection), but the module either fully loads (assignment runs) or aborts with DidNotEnable, so there is no path where it is read while undefined. Clean change.
Sorry, something went wrong.
…getsentry#6865) Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
| Back | FazBrowse Home | New Git URL |
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.