Instrumenting your code with the Agent SDK

BETA

To measure transactions and important segments of code in your application:

  1. Include the newrelic_transaction.h and newrelic_common.h header files.
  2. Link your application to the libnewrelic-transaction and libnewrelic-common libraries.
  3. Create a transaction; for example:

    long transaction_id = newrelic_transaction_begin();
  4. Optional: Set a name for the transaction any time before the transaction ends. For example:

    int return_code = newrelic_transaction_set_name
        (
        transaction_id,
        "create_account"
        );
        
  5. Measure segments; for example:

    long segment_id = newrelic_segment_generic_begin
        (
        transaction_id,
        parent_id,
        "check_if_account_exists"
        );
        <call check_if_account_exists>
        int return_code = newrelic_segment_end
        (
        transaction_id,
        segment_id
        );
        
  6. Optional: If this is not a web transaction, set the transaction type any time before the transaction ends. For example:

    newrelic_transaction_set_type_other(transaction_id);
  7. End your transaction; for example:

    int error_code = newrelic_transaction_end(transaction_id);
  8. Start your app, and then wait a few minutes to start seeing data in your New Relic dashboards.

For more help

Additional documentation resources include:

Troubleshoot and ask questions about the Agent SDK in New Relic's Online Technical Community!

If you need additional help, get support at support.newrelic.com.