Instrumenting your code with the Agent SDK


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
  5. Measure segments; for example:

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

  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:

Recommendations for learning more:

  • See the Docs site's landing page for APM agent SDK documentation.
  • Browse New Relic's Explorers Hub for community discussions about the APM agent SDK.
  • Use your preferred search engine to find other New Relic resources.