• English日本語한국어
  • Log inStart now

Instrument your app with the C SDK

In order to monitor any application on Linux using a language that can import C libraries, you must:

  1. Create a config using newrelic_new_app_config(), connect to the daemon using newrelic_init(), and connect your application using newrelic_create_app(). For more information, see the C SDK installation procedures.
  2. Manually instrument transactions using the C SDK, as described in this document.

New Relic defines a web or non-web transaction as one logical unit of work in a software application. After you manually instrument transactions in your source code by adding New Relic functions, you can view the data on the Transactions page in New Relic. You can also instrument segments of a transaction and errors.

Instrument a transaction

To instrument a transaction so you can monitor it, wrap the New Relic functions that start and stop instrumentation around the transaction. The function that you use depends on whether you want to instrument a web or non-web transaction.

In the following example, the app is created after a call to newrelic_create_app(). For more information, see the C SDK installation procedures as well as the C SDK libnewrelic.h documentation on GitHub.

  1. Add the following code immediately before the transaction that you want to monitor, supplying the required parameters.

    For web transactions:

    // Example code:
    newrelic_txn_t *txn;
    /* ... */
    txn = newrelic_start_web_transaction(app, "NAME_YOUR_TRANSACTION");

    For non-web transactions:

    // Example code:
    newrelic_txn_t *txn;
    /* ... */
    txn = newrelic_start_non_web_transaction(app, "NAME_YOUR_TRANSACTION");
  2. Add newrelic_end_transaction() immediately after the web or non-web transaction that you want to monitor, supplying a pointer the transaction, &txn, as a parameter.

Instrument segments

Once you instrument a transaction using the C SDK, you can instrument segments in it. By instrumenting segments, you can monitor the individual functions and calls inside a transaction.

Segments example

You have a transaction associated with a checkout process, which processes both shipping information and credit card information. You can instrument your application to break that transaction up into two segments: one segment for shipping and one segment for payment.

You can instrument segments to monitor the following kinds of calls:

For more information, see the C SDK installation procedures as well as the C SDK libnewrelic.h documentation on GitHub.

Instrument errors

In order to use the C SDK to monitor errors in transactions, you must manually instrument your source code by adding the newrelic_notice_error() function to it.

Transaction errors and error traces appear on the Error analytics page in New Relic. The C SDK reports the total number of errors and up to 100 error traces per minute. You can also view, query, and visualize transaction errors as APM TransactionError events.

Tip

To include function calls in error traces, use GNU's -rdynamic linker flag to link your apps when compiling. The -rdynamic linker flag gives you more meaningful error traces.

To instrument errors in transactions:

  1. Start a transaction.
  2. Record an error with newrelic_notice_error(), supplying the required parameters.
  3. End the transaction, supplying the required parameters.

For more information, see the C SDK installation procedures as well as the C SDK libnewrelic.h documentation on GitHub.

Avoid metric grouping issues

When an account or application sends many individual metrics that could be better managed in groups, New Relic uses the term metric grouping issue or MGI to describe this situation. If your application sends unnecessarily large amounts of data to New Relic, this reduces the effectiveness of charts, tables, and reports.

Metric grouping issues occur most commonly with web transactions, especially if the name is based on URLs. To help prevent this situation, see Metric grouping issues.

Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.