-
Notifications
You must be signed in to change notification settings - Fork 439
chore(tracer): add failsafe to package distribution discovery #13343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Bootstrap import analysisComparison of import times between this PR and base. SummaryThe average import time from this PR is: 231 ± 1 ms. The average import time from base is: 233 ± 2 ms. The import time difference between this PR and base is: -2.08 ± 0.06 ms. Import time breakdownThe following import paths have shrunk:
|
BenchmarksBenchmark execution time: 2025-05-14 13:48:19 Comparing candidate commit b51d496 in PR branch Found 0 performance improvements and 3 performance regressions! Performance is the same for 520 metrics, 5 unstable metrics. scenario:iast_aspects-ospathsplitext_aspect
scenario:iast_aspects-strip_aspect
scenario:telemetryaddmetric-1-gauge-metric-1-times
|
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.
just some initial thoughts, I think in general it looks ok, but if we can narrow some of the try/excepts so we can get at least partial data when possible.
@@ -46,15 +46,19 @@ def get_distributions() -> t.Mapping[str, str]: | |||
def get_package_distributions() -> t.Mapping[str, t.List[str]]: | |||
"""a mapping of importable package names to their distribution name(s)""" | |||
global _PACKAGE_DISTRIBUTIONS | |||
if _PACKAGE_DISTRIBUTIONS is None: | |||
if not _PACKAGE_DISTRIBUTIONS: |
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.
I suppose it should never be "empty" so this should be safe?
it would be weird for it to be empty?
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.
it can be empty if the previous call failed
_PACKAGE_DISTRIBUTIONS = importlib_metadata.packages_distributions() | ||
try: | ||
_PACKAGE_DISTRIBUTIONS = importlib_metadata.packages_distributions() | ||
except Exception: |
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.
with this, you could probably just drop the hasattr
, but 🤷🏻
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.
It's related to the issue #APMAPI-1400 where in some circonstances on system tests we get an OSError.
for pkg in _top_level_declared(dist) or _top_level_inferred(dist): | ||
pkg_to_dist[pkg].append(dist.metadata["Name"]) | ||
return dict(pkg_to_dist) | ||
except Exception: |
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.
where is the exception happening? should we try to be more targeted?
e.g. just skip specific dists if an exception occurs?
for dist in importlib_metadata.distributions():
try:
pass
except Exception:
pass
return dict(pkg_to_dist)
?
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.
I just added that to be extra careful here, we don't want unchecked exception here, I suppose.
Add two failsafes to package distribution discovery.
If internal API fails, fall back to vendored version
If vendored version fails, return empty package distribution.
#APMAPI-1400
Checklist
Reviewer Checklist