カスタム exit コール

start_exit_call() および end_exit_call() メソッドを使用して、特定のビジネストランザクションから Python エージェントが自動的に検出しないバックエンドへのカスタム exit コールを作成できます。

ビジネストランザクションは、カスタムビジネストランザクションである必要があります。
ヒント: 通常自動検出されるビジネストランザクションからカスタム exit コールを作成する場合、そのビジネストランザクションを除外して自動検出されないようにし、カスタムビジネストランザクションとして作成することができます。これにより、カスタム exit コールを作成するために必要な BtHandle を取得できるようになります。ビジネストランザクションの除外については、「Python Web のカスタム一致と除外ルールの構成」を参照してください。
以下のコードの場合
try:
    db = custom_db.connect(host='financials-lb', port=3456)
    all_employees = db.query_path('/financials/employees')
    individual_contributors = all_employees.filter(lambda r: r.level < 3)
    salaries_by_dept = individual_contributors.sum(value='salary', group='dept', as='total')

    for dept, total in salaries_by_dept.extract('dept', 'total'):
        report_salary_data(dept, total)

独自のデータベースへの exit コールを介してクエリを送信します。

コントローラ UI で、データベースに「Financials Database」というラベルを付ける必要があります。

バックエンドダッシュボードに表示されるバックエンドプロパティを次のように表示します。

ホスト
financials-lb
ポート
3456
ベンダー
custom db

以下の例では、コードの別の部分に作成された「department rollup」という名前のカスタム ビジネス トランザクションで終了コールをまとめることを仮定しています。

start_exit_call() および end_exit_call()の使用

この例では、start_exit_call()end_exit_call() を使用します。
from appdynamics.agent import api as appd
appd.init()

# Set the identifying properties
FINANCIALS_ID_PROPS = {'Host': 'financials-lb', 'Port': 3456, 'Vendor': 'custom db'}

with appd.bt('department rollup') as bt_handle:
    # Start the exit call
    exit_call = appd.start_exit_call(bt_handle, appd.EXIT_DB, 'Financials Database', FINANCIALS_ID_PROPS)
    exc = None

    try:
        db = custom_db.connect(host='financials-lb', port=3456)
        all_employees = db.query_path('/financials/employees')
        individual_contributors = all_employees.filter(lambda r: r.level < 3)
        salaries_by_dept = individual_contributors.sum(value='salary', group='dept', as='total')

        for dept, total in salaries_by_dept.extract('dept', 'total'):
            report_salary_data(dept, total)
    except Exception as exc:
        raise  # Assuming something above handles exceptions for you
    finally:
        #End the exit call
        end_exit_call(exit_call, exc)

exit_call コンテキストマネージャの使用

ビジネストランザクションが同じコンテキストで開始および終了する場合は、exit_call コンテキストマネージャを使用するほうが簡単です。
from appdynamics.agent import api as appd
appd.init()

with appd.bt('department rollup') as bt_handle:
    with appd.exit_call(bt_handle, appd.EXIT_DB, 'Financials Database', FINANCIALS_ID_PROPS):
        db = custom_db.connect(host='financials-lb', port=3456)
        all_employees = db.query_path('/financials/employees')
        individual_contributors = all_employees.filter(lambda r: r.level < 3)
        salaries_by_dept = individual_contributors.sum(value='salary', group='dept', as='total')

        for dept, total in salaries_by_dept.extract('dept', 'total'):
            report_salary_data(dept, total)

次の例では、Python エージェントのデフォルト Flask インストルメンテーションにより自動検出されたビジネストランザクションから、Cassandra バックエンドへのカスタム exit コールを開始します。Flask のインポート機能を使用して、要求オブジェクトを取得し appd_get_active_bt_handle() に渡します。

Flask リクエストコンテキストを使用して BT ハンドルを取得します:
from flask import request
from appdynamics.agent import api as appd

@app.route('/metrics/recent')
def metrics_recent():
    bt = appd.get_active_bt_handle(request)  # Get the active BT from the Flask request object
    with appd.exit_call(bt, appd.EXIT_DB, 'cassandra time-series', {'VENDOR': 'Cassandra', 'SERVER POOL': '10.0.0.1'}):
        load_recent_data_from_cassandra()

他の対応フレームワークは、要求オブジェクトを取得するためのメカニズムが異なります。