GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — perf: Avoid scanning installed packages when MCP SDK is not installed by mangodxd · Pull Request #6865 · getsentry/sentry-python

Conversation

@mangodxd

@mangodxd mangodxd commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

sentry[bot] reacted with hooray emoji
All reactions
  • 🎉 1 reaction
@mangodxd @claude
perf: Avoid scanning installed packages when MCP SDK is not installed (…
07564c8
…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 <[email protected]>
@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
Chenghao999
Chenghao999 reviewed Aug 6, 2026
View reviewed changes

@Chenghao999 Chenghao999 left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

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.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
alexander-alderman-webb
alexander-alderman-webb approved these changes Aug 7, 2026
View reviewed changes
@alexander-alderman-webb
alexander-alderman-webb merged commit 5bd85b4 into getsentry:master Aug 7, 2026
140 checks passed

Uh oh!

There was an error while loading. Please reload this page.

mgaligniana pushed a commit to mgaligniana/sentry-python that referenced this pull request Aug 9, 2026
@mangodxd @claude @mgaligniana
perf: Avoid scanning installed packages when MCP SDK is not installed (…
6d501b7
…getsentry#6865)

Co-authored-by: Claude Opus 4.6 <[email protected]>
@sentry-release-bot sentry-release-bot Bot mentioned this pull request Aug 10, 2026
publish: getsentry/[email protected] getsentry/publish#9190
Closed
6 tasks
This was referenced Nov 4, 2026
package_version() parses every installed package's metadata, slowing sentry_sdk.init() #8190
Closed
perf: Avoid scanning installed packages in package_version #8191
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@alexander-alderman-webb alexander-alderman-webb alexander-alderman-webb approved these changes
+1 more reviewer
@Chenghao999 Chenghao999 Chenghao999 left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@mangodxd @Chenghao999 @alexander-alderman-webb
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.