Monitor LangChain Applications

Splunk AppDynamics Python Agent helps you to monitor GenAI apps built using the LangChain framework. When you instrument the app with Python Agent, it captures the following:

  • Exit calls to vector databases: pgvector and chroma.
  • Prompts and responses in the exit call.
  • Counts of documents retrieved, similarity search score, and errors in vector databases
  • Calls per minute

To monitor LLMs using LangChain, such as Ollama, the Python Agent records these metrics:

  • Input Tokens
  • Output Tokens
  • Time to first token metric (ms)
  • Time per output token (ms)
  • Average Response Time (ms)
  • Prompt count
  • Embedding queries count
  • Errors

Prerequisites

Ensure to set the enable-langchain flag to true in /path/to/appdynamics.cfg file of the Python Agent. See [instrumentation].

LangChain Ollama API のモニタリング

Ollama コールをモニターするために、Python エージェントは次のメトリックをレポートします。

  • 入力トークン = 0.5$
  • 出力トークン
  • 最初のトークンメトリックまでの時間(ミリ秒)
  • 出力トークンあたりの時間(ミリ秒)
  • 平均応答時間(ms)
  • プロンプト数
  • 組み込みクエリ数
  • エラー
注:

トークンメトリックを取得するには、transformers Python ライブラリをインストールしてください。「Transformers」を参照してください。

CODE
pip install transformers

メトリックパスの例Agent|Langchain|LLM|llama3.2_latest|Average Response Time (ms))

Ollama API をモニターするためのカスタムダッシュボードの作成

  1. Custom_dashboard_script.zip をダウンロードします。これには次のものが含まれています。
    ディレクトリ(Directory) 説明
    templates ダッシュボードファイルを作成するための json テンプレートが含まれています。
    dashboard ダッシュボード json ファイルがここで作成されます。サンプル json ファイルが含まれています。
    main.py ダッシュボードを作成するための Python スクリプト。
    readme.md ソリューションの説明。
  2. 以下のコマンドを実行します:
    CODE
    cd Custom_dashboard_script
    python3 main.py

    上記のコマンドでは、作成するダッシュボードのタイプ(アプリケーションまたは階層)を指定するように求められます。

  3. 選択したダッシュボードのタイプに基づいて、次のダッシュボードの詳細を指定するように求められます。
  4. コントローラ UI でダッシュボードをインポートします。カスタムダッシュボードおよびテンプレートの作成と管理 を参照してください
    ヒント: [Tiers & Nodes] > [My Dashboards] の順に移動し、既存のダッシュボードからウィジェットをコピーして貼り付け、選択したアプリケーションのダッシュボードを作成して簡単にナビゲーションできるようにします。
ダッシュボードの例Ollama API をモニターするためのカスタムダッシュボード

LangChain ベクトルストアのモニタリング

Python エージェントでアプリケーションをインストゥルメント化すると、ベクトルストアの次のメトリックがキャプチャされます。

  • langchain_community および langchain_{vendor} ベクトルストアの場合、Python エージェントでは次のメトリックがキャプチャされます。
    • 検索スコア
    • 平均応答時間(ms)
    • エラー
    • コール
    • ベクトル挿入数
    • ベクトル削除数
    注:

    デフォルトでは、 は langchain_{vendor} ベクトルストアの次のメトリックをキャプチャします。

    • langchain_milvus
    • langchain_chroma
    • langchain_postgres

    ただし、 langchain-vectorstores-instrumented-modules フラグを設定して、 /path/to/appdynamics.cfg の特定の LangChain ベンダーからメトリックをキャプチャすることができます。詳細については、「インストゥルメンテーション」を参照してください。

  • ベクトルデータベース(pgvector および chroma)へのコールを終了します。

スナップショット exit コールの詳細で、PGVector およびChroma ベクトルストアの要求と応答をキャプチャするには、Python エージェントの /path/to/appdynamics.cfg ファイルで enable-genai-data-capture フラグを true に設定します。「[instrumentation]」を参照してください。