• /
  • EnglishEspañol日本語한국어Português
  • 로그인지금 시작하기

Activate application warning (Python)

Problem

중요

Note this is only an issue if no data is being reported.

You're 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:

  1. Move all calls to newrelic.agent.register_application or newrelic.agent.application inside of functions inside of a __name__ == __main__ check.

  2. If you're unsure where the calls to newrelic.agent.register_application or newrelic.agent.application are occurring, use the agent debug logs to search for an entry containing:

    newrelic.core.agent DEBUG - Application was activated from:
  3. 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_initializer
    application_instance().activate()
  4. 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 imported
    app = newrelic.agent.application()
    def custom_event():
    newrelic.agent.record_custom_event('CustomEvent', {}, application=app)

    After:

    import newrelic.agent
    def 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

There're two primary causes of this issue. The first is creating an application instance multiple times or creating an application instance prior to forking.

  1. 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 imported
    app = newrelic.agent.application()
    def custom_event():
    newrelic.agent.record_custom_event('CustomEvent', {}, application=app)
  2. This issue can also occur when monitoring services like celery where a main parent process launches worker processes. It occurs when an agent application instance is created on the main process prior to forking the worker processes. Since the agent is launched in the parent process, no data is collected in the child process.

Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.