Example: lr_user_data_point_instance
In the following example,lr_start_transaction_instance measures the duration a withdrawal from a bank server. Once the server API call is completed and returns a value to the status variable, the transaction instance is complete. Each successful instance of the transaction is accompanied by a data point instance that records the amount overdrawn with the transaction. This is achieved by passing the instance_id of the transaction to lr_user_data_point_instance.
int LIMIT=1000; long instance_id; int amount_overdrawn = get_amount_overdrawn(); /* Call to server API */ while (amount_overdrawn < LIMIT) { /* Notify that a transaction is starting */ instance_id = lr_start_transaction_instance("withdraw", 0); status = bank_withdraw(500); /* Call to server API */ /* End transaction with operation result - pass or fail */ if (status == 0) { /* Before ending the transaction, record the amount * overdrawn as a data point and associate it with * the specific transaction instance by using the * instance's id */ lr_user_data_point_instance("Amount Overdrawn", (double)amount_overdrawn, instance_id); lr_end_transaction_instance(instance_id, LR_PASS); } else lr_end_transaction_instance(instance_id, LR_FAIL); amount_overdrawn = get_amount_overdrawn(); }