Skip to content

Fix package reporting implementation#1670

Open
lrafeei wants to merge 55 commits into
mainfrom
loaded-modules-fix
Open

Fix package reporting implementation#1670
lrafeei wants to merge 55 commits into
mainfrom
loaded-modules-fix

Conversation

@lrafeei
Copy link
Copy Markdown
Contributor

@lrafeei lrafeei commented Feb 25, 2026

This PR attempts to fix an issue where some modules are not loaded in the environment section of the UI (the modules do not get passed into the update_loaded_modules endpoint). It also fixes a bug where it does not reload the modules upon agent restart.

Previously the logic attempted to load as many modules as possible during a 2 second window by iterating through a plugins generator. However, it seems that some modules that have a longer loading time get missed.

The logic here has been changed to continue to load the next module if the previous module took less than 0.5 seconds and the amount of time uploading modules is less than 5.0 seconds. If the previous module takes longer than 0.5 seconds to load, the agent will wait until the next harvest cycle to resume.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 25, 2026

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ ACTION actionlint 8 0 0 0.84s
✅ MARKDOWN markdownlint 7 0 0 0 1.15s
✅ PYTHON ruff 1036 0 0 0 0.96s
✅ PYTHON ruff-format 1036 0 0 0 0.39s
✅ YAML prettier 19 0 0 0 1.45s
✅ YAML v8r 19 0 0 5.15s
✅ YAML yamllint 19 0 0 0.63s

See detailed reports in MegaLinter artifacts

MegaLinter is graciously provided by OX Security
Show us your support by starring ⭐ the repository

@mergify mergify Bot added the tests-failing Tests failing in CI. label Feb 25, 2026
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Feb 25, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.00%. Comparing base (6e429d2) to head (bf214f6).

Files with missing lines Patch % Lines
newrelic/core/application.py 50.00% 3 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1670      +/-   ##
==========================================
- Coverage   82.00%   82.00%   -0.01%     
==========================================
  Files         215      215              
  Lines       26309    26300       -9     
  Branches     4150     4151       +1     
==========================================
- Hits        21575    21567       -8     
+ Misses       3319     3317       -2     
- Partials     1415     1416       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mergify mergify Bot removed the tests-failing Tests failing in CI. label Mar 6, 2026
@lrafeei lrafeei marked this pull request as ready for review March 6, 2026 23:29
@lrafeei lrafeei requested a review from a team as a code owner March 6, 2026 23:29
@mergify mergify Bot added the tests-failing Tests failing in CI. label Mar 7, 2026
@lrafeei lrafeei changed the title Load one module at a time per harvest cycle Fix package reporting implementation Mar 10, 2026
@mergify mergify Bot removed the tests-failing Tests failing in CI. label Mar 10, 2026
@mergify mergify Bot added the tests-failing Tests failing in CI. label Mar 10, 2026
Copy link
Copy Markdown
Contributor

@hmstepanek hmstepanek left a comment

Choose a reason for hiding this comment

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

A couple thoughts here-I'm not sure exactly why it would not be reporting the module(s) again but I had one thought. Seems unlikely to be the reason but I didn't see anything else that would cause that. You could add some log statements or a metric in or something to maybe help you debug what's going on.

Comment thread newrelic/core/application.py Outdated
# harvest cycle before resuming.
if self._remaining_plugins and self.configuration and self.configuration.package_reporting.enabled:
start = stopwatch_start = time.time()
while ((time.time() - stopwatch_start) < 0.5) and (
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder-can you just simplify this to be the following and leave MAX_PACKAGE_CAPTURE_TIME_PER_SLOW_HARVEST=2:

Suggested change
while ((time.time() - stopwatch_start) < 0.5) and (
while (time.time() - start) < MAX_PACKAGE_CAPTURE_TIME_PER_SLOW_HARVEST:

This way it will at least load 1 module before exiting. I realize this is slow harvest but I wonder if 5s is a bit long.

Comment thread newrelic/core/application.py Outdated
# 0.5 seconds to upload. Then, wait for the next
# harvest cycle before resuming.
if self._remaining_plugins and self.configuration and self.configuration.package_reporting.enabled:
start = stopwatch_start = time.time()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems unlikely but I wonder if what's happening for the AI team who is testing this is they are never entering the while loop because of that less than .5 check? Are they seeing any modules reporting at all? Another way you could implement this that might be simpler and avoid this potential issue is:

start = time.time()
for module in self.plugins:
    self._active_session.send_loaded_modules([module])
    if time.time() - start > MAX_PACKAGE_CAPTURE_TIME_PER_SLOW_HARVEST:
        break
else:
    self._remaining_plugins = False

Comment thread newrelic/core/application.py Outdated
if self.modules:
self._active_session.send_loaded_modules(self.modules)
self.modules = []
if self._remaining_plugins and self.configuration and self.configuration.package_reporting.enabled:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm wondering if we really need the self._remaining_plugins or can we just set self.plugins = False?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, like override the generator object to be a boolean when it runs out and use that as the conditional?

@mergify mergify Bot removed the tests-failing Tests failing in CI. label Mar 12, 2026
@lrafeei lrafeei requested a review from hmstepanek March 12, 2026 21:07
@mergify mergify Bot added the tests-failing Tests failing in CI. label Mar 12, 2026
@mergify mergify Bot removed the tests-failing Tests failing in CI. label May 6, 2026
@mergify mergify Bot added the tests-failing Tests failing in CI. label May 6, 2026
@mergify mergify Bot removed the tests-failing Tests failing in CI. label May 11, 2026
@mergify mergify Bot added the tests-failing Tests failing in CI. label May 11, 2026
@mergify mergify Bot removed the tests-failing Tests failing in CI. label May 12, 2026
@mergify mergify Bot added the tests-failing Tests failing in CI. label May 12, 2026
@mergify mergify Bot removed the tests-failing Tests failing in CI. label May 12, 2026
@mergify mergify Bot added the tests-failing Tests failing in CI. label May 21, 2026
@mergify mergify Bot removed the tests-failing Tests failing in CI. label May 21, 2026
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.

4 participants