newrelic / newrelic-python-agent

New Relic Python Agent
https://docs.newrelic.com/docs/agents/python-agent
Apache License 2.0
178 stars 102 forks source link

Disable package capture when testing #1165

Closed hmstepanek closed 5 months ago

hmstepanek commented 5 months ago

Overview

Package capturing is slow and we don't need to do it for every test. Disable package capturing unless we are explicitly testing it.

Previously, when it took too long to capture the package info, it caused application connect timeouts that raised an AssertionError of application.active.

github-actions[bot] commented 5 months ago

🦙 MegaLinter status: ❌ ERROR

Descriptor Linter Files Fixed Errors Elapsed time
✅ PYTHON black 79 0 0 1.39s
✅ PYTHON flake8 79 0 0.86s
✅ PYTHON isort 79 0 0 0.29s
❌ PYTHON pylint 79 27 10.21s

See detailed report in MegaLinter reports _Set VALIDATE_ALL_CODEBASE: true in mega-linter.yml to validate all sources, not only the diff_

_MegaLinter is graciously provided by OX Security_

codecov-commenter commented 5 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Please upload report for BASE (main@44ccef0). Learn more about missing BASE report.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1165 +/- ## ======================================= Coverage ? 81.76% ======================================= Files ? 195 Lines ? 21643 Branches ? 3779 ======================================= Hits ? 17696 Misses ? 2850 Partials ? 1097 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

hmstepanek commented 5 months ago

I see the flag being set in the tests that do not need the package capture, but I am not seeing where the flag's status does anything with the function itself (in the config.py to set the setting/flag or the package capture function itself)

The package capture setting is in the config file here: https://github.com/newrelic/newrelic-python-agent/blob/main/newrelic/config.py#L567. It is used here inside the environment_settings function to skip capturing the plugins if it is disabled: https://github.com/newrelic/newrelic-python-agent/blob/main/newrelic/core/environment.py#L207.

lrafeei commented 5 months ago

I see the flag being set in the tests that do not need the package capture, but I am not seeing where the flag's status does anything with the function itself (in the config.py to set the setting/flag or the package capture function itself)

The package capture setting is in the config file here: https://github.com/newrelic/newrelic-python-agent/blob/main/newrelic/config.py#L567. It is used here inside the environment_settings function to skip capturing the plugins if it is disabled: https://github.com/newrelic/newrelic-python-agent/blob/main/newrelic/core/environment.py#L207.

Oh, OK, that's what I was missing--I did not realize this was a flag we already had. Looks good to me!