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 in package_version by Jackevansevo · Pull Request #8191 · getsentry/sentry-python

Conversation

@Jackevansevo

@Jackevansevo Jackevansevo commented Nov 5, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

Description

package_version parsed every installed package's metadata to read one version. It now looks up only that package, as suggested in #2316, which covers all 7 places that call it.

Same scan as #6865 (fixed there for MCP only), and the same lookup as the pydantic_ai integration (direct importlib.metadata call).

#2338 chose the cached list because importlib.metadata needs Python 3.8+. That path stays as the fallback, so this only avoids the first scan's cost. ModulesIntegration still builds the full list on the first error event.

With ~250 packages, package_version("flask") goes from 106 ms to 5 ms (-95%).

Draft: the test suite hasn't been run on this yet.

Issues

  • resolves: package_version() parses every installed package's metadata, slowing sentry_sdk.init() #8190

🤖 Generated with Claude Code

Sorry, something went wrong.

Uh oh!

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

All reactions
@Jackevansevo
Jackevansevo force-pushed the perf/package-version-lookup branch from 30fc342 to 3f7480b Compare November 5, 2026 00:06
@Jackevansevo Jackevansevo changed the title perf: Avoid scanning installed packages in package_version perf(flask): Avoid scanning installed packages for the version check Nov 5, 2026
@Jackevansevo
Jackevansevo force-pushed the perf/package-version-lookup branch 2 times, most recently from 4fa731a to 3f7480b Compare November 5, 2026 00:12
@sentrivana

sentrivana commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

Hey @Jackevansevo, thanks for the PR. The change itself is good, but it's very targeted (just to Flask). Is there a way to generalize it so that any integration that needs a version check first checks via the less expensive route?

All reactions

Sorry, something went wrong.

Uh oh!

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

@Jackevansevo @claude
perf: Avoid scanning installed packages in package_version
ea2c4c6
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Jackevansevo
Jackevansevo force-pushed the perf/package-version-lookup branch from 3f7480b to ea2c4c6 Compare November 5, 2026 14:39
@Jackevansevo Jackevansevo changed the title perf(flask): Avoid scanning installed packages for the version check perf: Avoid scanning installed packages in package_version Nov 5, 2026
@Jackevansevo @claude
fix: Fall back to the existing lookup when package metadata is broken
f47e6a4
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Jackevansevo

Jackevansevo commented Nov 5, 2026

Copy link
Copy Markdown
Author

Hey @Jackevansevo, thanks for the PR. The change itself is good, but it's very targeted (just to Flask). Is there a way to generalize it so that any integration that needs a version check first checks via the less expensive route?

Thanks for the feedback.

I've moved the fast path check into package_version. Which should effect the following integrations:

  • Flask
  • Anthropic
  • Ariadne
  • Graphene
  • Ray
  • Strawberry
  • MCP

If importlib.metadata fails, there's nothing found or we're on older versions of Python it will just fall back to what is was doing previously (calling _get_installed_modules()).


It's worth flagging here that if we skip calling _get_installed_modules() on startup this result is no longer being cached. So that (potentially) expensive check potentially gets run on first error instead of startup.

But only integrations using package_version() would have cached this anyway.

All reactions

Sorry, something went wrong.

Uh oh!

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

@Jackevansevo
Jackevansevo marked this pull request as ready for review November 5, 2026 17:27
@Jackevansevo
Jackevansevo requested a review from a team as a code owner November 5, 2026 17:27
cursor[bot]
cursor Bot reviewed Nov 5, 2026
View reviewed changes

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit f47e6a4. Configure here.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread tests/test_utils.py Resolved

Uh oh!

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

Jackevansevo and others added 2 commits November 5, 2026 14:53
@Jackevansevo @claude
test: Skip the package_version scan test below Python 3.8
06ac994
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Jackevansevo
Merge branch 'master' into perf/package-version-lookup
ab895ff
@sentrivana

sentrivana commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Hey, I went with #8215 because I thought it was a new PR from you -- didn't check the author. Will close this one 🙏🏻

All reactions

Sorry, something went wrong.

Uh oh!

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

@sentrivana sentrivana closed this Nov 9, 2026
@Jackevansevo

Jackevansevo commented Nov 9, 2026

Copy link
Copy Markdown
Author

Hey, I went with #8215 because I thought it was a new PR from you -- didn't check the author. Will close this one 🙏🏻

No problem! As long as it's fixed. Thanks for merging.

All reactions

Sorry, something went wrong.

Uh oh!

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@cursor cursor[bot] cursor[bot] left review comments

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.

package_version() parses every installed package's metadata, slowing sentry_sdk.init()

Uh oh!

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

2 participants

@Jackevansevo @sentrivana
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.