Problem
You are using the latest Python agent, and you see a log entry with a warning message such as:
Attempt to activate application in a process different to where the agent harvest thread was started.
OR:
Attempt to reactivate application or record transactions in a process different to where the agent was already registered.
The application shows as reporting in the New Relic UI, but no data is reported to New Relic.
Solution
To solve this problem with your app:
Move all calls to
newrelic.agent.register_application
ornewrelic.agent.application
inside of functions inside of a__name__ == __main__
check.If you're unsure where the calls to
newrelic.agent.register_application
ornewrelic.agent.application
are occurring, use the agent debug logs to search for an entry containing:newrelic.core.agent DEBUG - Application was activated from:Use the entry's traceback of the call that activated the agent. Refer to the following frames, which are considered normal:
File "newrelic/api/transaction.py", line x, in __init__application.activate()File "newrelic/hooks/application_celery.py", line x, in process_initializerapplication_instance().activate()If the activation is occurring from a different location, correct this issue by following this example:
Before:
import newrelic.agent# This will cause the agent to activate whenever custom_event is importedapp = newrelic.agent.application()def custom_event():newrelic.agent.record_custom_event('CustomEvent', {}, application=app)After:
import newrelic.agentdef custom_event():app = newrelic.agent.application()newrelic.agent.record_custom_event('CustomEvent', {}, application=app)
For other tips when no data appears, see the Python troubleshooting documentation.
Cause
This is usually caused by a call to newrelic.agent.register_application
or newrelic.agent.application
occurring at import time.
Example:
import newrelic.agent# This will cause the agent to activate whenever custom_event is importedapp = newrelic.agent.application()def custom_event(): newrelic.agent.record_custom_event('CustomEvent', {}, application=app)
Code typically is loaded before a fork occurs in frameworks such as Celery or multiprocessing. As a result, the code is imported into the parent process instead of the child, launching the agent. Since the agent is launched in the parent process, no data is collected in the child process.
For more help
If you need more help, check out these support and learning resources:
- Browse the Explorers Hub to get help from the community and join in discussions.
- Find answers on our sites and learn how to use our support portal.
- Run New Relic Diagnostics, our troubleshooting tool for Linux, Windows, and macOS.
- Review New Relic's data security and licenses documentation.