• EnglishEspañol日本語한국어Português
  • ログイン今すぐ開始

この機械翻訳は、参考として提供されています。

In the event of any inconsistency between the English version and the translated version, the English versionwill take priority. Please visit this page for more information.

問題を作成する

アプリケーション警告の有効化(Python)

問題

重要

これは、データが報告されていない場合にのみ問題になることに注意してください。

最新の Python エージェントを使用しており、次のような警告メッセージを含むログ エントリが表示されます。

Attempt to activate application in a process different to where the agent harvest thread was started.

または

Attempt to reactivate application or record transactions in a process different to where the agent was already registered.

アプリケーションは New Relic UI でレポートしているように表示されますが、データは New Relic に報告されません。

解決

この問題をあなたのアプリで解決するために

  1. __name__ == __main__ チェック内の関数内の newrelic.agent.register_application または newrelic.agent.application へのすべての呼び出しを移動します。

  2. newrelic.agent.register_application または newrelic.agent.application への呼び出しが発生している場所がわからない場合は、 エージェントのデバッグ ログ を使用して、次を含むエントリを検索します。

    newrelic.core.agent DEBUG - Application was activated from:
  3. エージェントを起動したコールのエントリーのトレースバックを使用します。正常と考えられる以下のフレームを参照してください。

    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. 別の場所でアクティベーションが発生している場合は、以下の例を参考にして修正してください。

    前です。

    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)

    :

    import newrelic.agent
    def custom_event():
    app = newrelic.agent.application()
    newrelic.agent.record_custom_event('CustomEvent', {}, application=app)

データが表示されない場合のその他のヒントについては、 Pythonのトラブルシューティング・ドキュメント を参照してください。

原因

この問題の主な原因は 2 つあります。1 つ目は、アプリケーション インスタンスを複数回作成するか、フォークする前にアプリケーション インスタンスを作成することです。

  1. これは通常、インポート時に発生する newrelic.agent.register_application または newrelic.agent.application への呼び出しが原因です。

    :

    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. この問題は、メインの親プロセスがワーカー プロセスを起動するセロリなどのサービスを監視するときにも発生する可能性があります。これは、エージェント アプリケーション インスタンスがワーカー プロセスを分岐する前にメイン プロセスで作成されるときに発生します。エージェントは親プロセスで起動されるため、子プロセスではデータが収集されません。

Copyright © 2024 New Relic株式会社。

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