exit コールの管理
アプリケーションが別のコンポーネント(検出されたバックエンドまたは別のアプリケーションサーバ)を呼び出すと、エージェントはこれらの呼び出しに関するメトリックを報告します。
appd_exitcall_begin() と appd_exitcall_end() コールの間に終了コールを構成するコードを囲み、終了コールを定義します。appd_exitcall_begin() はその終了コールに影響を与える後続のルーチンで使用するハンドルを返します。exit コールは、ビジネストランザクションのコンテキスト内で発生します。
オプションで、終了コールハンドルを GUID とともにグローバル ハンドル レジストリに格納すると、後で appd_exitcall_store() を使用して簡単に取得できます。appd_exitcall_get() によって、グローバル ハンドル レジストリからハンドルを取得します。
ビジネス トランザクション ハンドルおよび宛先バックエンドを appd_exitcall_end() に渡します。
必要に応じて、任意の文字列として exit コールに詳細を追加することができます。詳細はコントローラ UI のトランザクションスナップショットの exit コール詳細に報告されます。
appd_exitcall_add_error() を使用して exit コールにエラーを追加することもできます。エラーレベルには列挙型を使用します。また、エラーメッセージを追加することもできます。
単純な exit コールの例
// start the exit call to backendOne
appd_exitcall_handle ecHandle = appd_exitcall_begin(btHandle, backendOne);
...
// optionally store the handle in the global registry
appd_exitcall_store(ecHandle, my_ec_guid);
...
// retrieve a stored handle from the global registry
appd_exitcall_handle myEcHandle = appd_exitcall_get(my_ec_guid);
// set the exit call details
rc = appd_exitcall_set_details(ecHandle, "backend ONE");
if (rc) {
std:cerr << "Error: exitcall details1";
return -1;
}
// add an error to the exit call
appd_exitcall_add_error(ecHandle, APPD_LEVEL_ERROR, "exitcall1 error!", true);
// end the exit call
appd_exitcall_end(ecHandle)
他のビジネストランザクションとの相関
相関ヘッダーには、エージェントが複数のティアにわたるビジネストランザクションのフローを継続できるようにする情報が含まれています。
SDK は、他の SDK や特定のタイプのエントリポイントとイグジットポイントに自動で相関を実行する他の AppDynamics エージェント(Java、.NET、PHP など)と相互に関連付けることができます。
アップストリームティアとの相関
インストゥルメント化されたプロセスが、自動相関に対応するアップストリームエージェントからの継続的なトランザクションを受信したら、以下を行います。
- サードパーティの
http_get_header()関数を使用して、受信 HTTP ペイロードからAPPD_CORRELATION_HEADER_NAMEという名前のヘッダーを抽出します。 - ヘッダーを
appd_bt_begin()に渡す。例:
const char* hdr = http_get_header(req, APPD_CORRELATION_HEADER_NAME); appd_bt_handle bt = appd_bt_begin("fraud detection", hdr);
http_get_header() 関数で取得したヘッダーが有効な場合、appd_bt_begin() コールにより開始したビジネストランザクションは、アップストリームサービスにより開始したビジネストランザクションを継続します。
ダウンストリームティアとの相関
ダウンストリーム エージェントは、HTTP ペイロード内にある singularityheader という名前の相関ヘッダーをモニターしています。
SDKエージェントが、自動相関に対応するダウンストリームエージェントへの exit コールを行っている場合は、以下を実行します。
APPD_CORRELATION_HEADER_NAMEを使用して相関ヘッダーの名前を設定します。- exit コールを開始。
appd_exitcall_get_correlation_header()関数を使用して exit コールから相関ヘッダーを取得します。- サードパーティのHTTP関数を使用して、HTTP POST要求を準備。
- ステップ 3 で取得した相関ヘッダーの値とともに、
APPD_CORRELATION_HEADER_NAMEという名前のヘッダーを HTTP リクエストの送信ペイロードに挿入します。 - リクエストを実行することができます。
例:
const char* const APPD_CORRELATION_HEADER_NAME = "singularityheader"; appd_exitcall_handle inventory = appd_exitcall_begin(bt, "inventory"); const char* hdr = appd_exitcall_get_correlation_header(inventory); http_request req; http_init(&req, HTTP_POST, "https: //inventory/holds/%s", sku); http_set_header(&req, APPD_CORRELATION_HEADER_NAME, hdr); http_perform(&req); ...
cURLダウンストリーム相関の例
以下は、cURL ライブラリを使用してダウンストリーム トランザクションと相関する例です。
#include <curl/curl.h>
. . .
. . .
// get the correlation header into the response
class LibcurlURLGet
{
public:
LibcurlURLGet(const std::string& url) : url(url), curlHandle(NULL) {}
std::string GetResponse(const char* correlationHeader)
{
CURLcode res;
Response response;
curlHandle = curl_easy_init();
if (curlHandle)
{
curl_easy_setopt(curlHandle, CURLOPT_URL, url.c_str());
curl_easy_setopt(curlHandle, CURLOPT_WRITEFUNCTION, WriteDataCallback);
curl_easy_setopt(curlHandle, CURLOPT_WRITEDATA, &response);
if(correlationHeader && strlen(correlationHeader))
{
// start new added code
std::string singularityHeader(APPD_CORRELATION_HEADER_NAME);
singularityHeader.append(": ");
singularityHeader.append(correlationHeader);
// end new added code
curl_slist* slistNewHeaders = 0;
slistNewHeaders = curl_slist_append(slistNewHeaders, correlationHeader);
curl_easy_setopt(curlHandle, CURLOPT_HTTPHEADER, slistNewHeaders);
}
res = curl_easy_perform(curlHandle);
if(res != CURLE_OK)
{
}
}
curl_easy_cleanup(curlHandle);
return response.GetResponseString();
}
private:
class Response
{
public:
std::string GetResponseString()
{
return sResponse;
}
void AppendResponse(void* ptr, size_t sizeBytes)
{
sResponse.append((char*)ptr, sizeBytes);
}
private:
std::string sResponse;
};
static size_t WriteDataCallback(void* ptr, size_t size, size_t nmemb, Response* response)
{
response->AppendResponse(ptr, size * nmemb);
return size * nmemb;
}
std::string url;
CURL* curlHandle;
};
...
// start an exit call from the current transaction
appd_exitcall_handle ecHandle1 = appd_exitcall_begin(btHandle1, tier2);
...
// before exiting get the correlation header
const char* corrHeader1 = appd_exitcall_get_correlation_header(ecHandle1);
// put the correlation in the HTTP response
std::string response = urlGet.GetResponse(corrHeader1);
...
// start the next business transaction to correlate with the previous one
appd_bt_handle btHandle = appd_bt_begin("Verify", response)