Manage Business Transaction Snapshots
When the agent is monitoring a business transaction, it automatically creates transaction snapshots, which describe instances of the business transaction at certain points in time. Transaction snapshots are extremely useful for troubleshooting poor performance because they contain a lot of detail.
You do not have to modify anything to create these snapshots, other than create the business transaction, but you can add calls to:
- Find out if a snapshot is being taken
- Provide additional data in a snapshot
- Set the URL for a snapshot
Determine if the Agent is Taking a Snapshot Now
The agent does not constantly collect screenshot due to high cost. By default, it collects a snapshot every ten minutes, but this schedule is configurable. See Configure Snapshot Periodic Collection Frequency.
You can determine if a snapshot is happening using
appd_bt_is_snapshotting()
, which returns non-zero if the agent is
collecting a snapshot. The main reason to do this is to avoid the wasted overhead for
collecting user data for a snapshot or setting the snapshot URL if no snapshot is currently
being collected.
Add Business Transaction User Data
You can optionally add data to transaction snapshots. For example, you might want to know which users are getting a lot of errors, from which regions users are experiencing slow response times or which methods are slow. In the Controller UI, the data appears in the USER DATA tab of the transaction snapshot.
If a snapshot is occurring, use appd_bt_add_user_data()
passing a key and
value for the data that you want the snapshot to collect. For the function
{{appd_bt_add_user_data,}}
, the Controller database truncates log
messages that exceed 5,000 characters.
Add Snapshot URL
A snapshot URL allows Controller users to share a snapshot with others. You can set a URL
for the current snapshot using appd_bt_set_url()
.
Set Snapshot Example
void setSnapshotAttributes(appd_bt_handle btHandle, int minute, int halfsec)
{
// do this only if the agent is collecting a snapshot
if (appd_bt_is_snapshotting(btHandle))
{
char nameBuf[30];
char valueBuf[30];
// add custom data to the snapshot
snprintf(nameBuf, sizeof(nameBuf), "BT:%p\n", btHandle);
snprintf(valueBuf, sizeof(valueBuf), "Minute:%d Second:%d\n", minute, halfsec/2);
appd_bt_add_user_data(btHandle, nameBuf, valueBuf);
static int snapCount = 0;
int switchVal = snapCount % 4;
// report errors, but only ERROR_LEVEL errors are marked as error transactions
if (switchVal)
{
appd_error_level errorLevel;
bool markBtAsError;
switch (switchVal)
{
case 1:
errorLevel = APPD_LEVEL_NOTICE;
markBtAsError = false;
snprintf(nameBuf, sizeof(nameBuf), "NOTICE BT:%p M:%d S:%d\n", btHandle, minute, halfsec/2);
break;
case 2:
errorLevel = APPD_LEVEL_WARNING;
markBtAsError = false;
snprintf(nameBuf, sizeof(nameBuf), "WARNING BT:%p M:%d S:%d\n", btHandle, minute, halfsec/2);
break;
case 3:
errorLevel = APPD_LEVEL_ERROR;
markBtAsError = true;
snprintf(nameBuf, sizeof(nameBuf), "ERROR BT:%p M:%d S:%d\n", btHandle, minute, halfsec/2);
break;
}
appd_bt_add_error(btHandle, errorLevel, nameBuf, markBtAsError, markbtaserror);
}
snapCount++;
// set the snapshot url
snprintf(nameBuf, sizeof(nameBuf), "http://bt-%p.com", btHandle);
appd_bt_set_url(btHandle, nameBuf);
}
}