Install the C SDK: Compile and link your code

Our C SDK auto-instruments your code so you can start monitoring applications. You can use our launcher, or follow the instructions in this document to complete a basic C SDK installation.

To use the C SDK or any other agent, as well as the rest of our observability platform, join the New Relic family! Sign up to create your free account in only a few seconds. Then ingest up to 100GB of data for free each month. Forever.

Add the C SDK to your code

To monitor your application with New Relic's C SDK, instrument the features you want to use:

  • Web transactions, transaction events, non-web transactions
  • Segments (for additional levels of timing details)
  • Attributes
  • Errors

Then compile and link your app against the C SDK static library.

To install the C SDK into your application's code library, follow this procedure.

1. Verify requirements.
  1. Make sure your application meets New Relic's compatibility and requirements for the C SDK.
  2. Make sure you have a New Relic license key.
2. Include the provided header file.
#include "libnewrelic.h"
3. Configure logging.

Follow the procedures to configure logging for both the C SDK and the daemon. For example:

if (!newrelic_configure_log("./c_sdk.log", NEWRELIC_LOG_INFO)) {
    printf("Error configuring logging.\n");
    return -1;
4. Be ready to provide a meaningful app name.

Be prepared to provide a meaningful app name in your initial application configuration; for example:

newrelic_app_config_t* config;
/* ... */
config = newrelic_create_app_config("Your Application Name", "LICENSE_KEY_HERE");

You may give your application up to three different names, separated by ;. Giving your application multiple names allows you to aggregate metrics for multiple agents across an entire app or service; for example:

config = newrelic_create_app_config("YOUR_APP_NAME;APP_GROUP_1;ALL_APPS", "LICENSE_KEY_HERE");

With the application configured, you can create a new application to connect to the daemon.

newrelic_app_t* app;

/* ... */

if (!newrelic_init(NULL, 0)) {
  printf("Error connecting to daemon.\n");
  return -1;

/* Wait up to 10 seconds for the SDK to connect to the daemon */
app = newrelic_create_app(config, 10000);
5. Finish instrumenting your code.

To finish instrumenting your code, refer to the example programs in the C SDK Examples documentation on GitHub. For more information about source code and features, see the C SDK's source documentation for libnewrelic.h on GitHub.

6. Compile and link your app.

The C SDK's libnewrelic.a is a static library that is already linked with the libpcre and libpthread libraries. To avoid symbol collisions in this linking step, be sure to link against each of these libraries.

In addition, to take full advantage of error traces in APM's Error analytics page, link your application using GNU's -rdynamic linker flag. This will allow more meaningful information to appear in the stack trace for the error recording on a transaction using the C SDK's newrelic_notice_error API call.

For example:

gcc -o test_app test_app.c -L. -lnewrelic -lpcre -lm -pthread -rdynamic
7. Start the daemon and check logs.
  1. Start the C SDK's daemon. For example:

    ./newrelic-daemon -f -logfile newrelic-daemon.log -loglevel debug
  2. Check the output in the c_sdk.log and newrelic-daemon.log files.

The C SDK's architecture requires that the daemon must be invoked first before your instrumented application is invoked.

To see all of the available options for the C daemon: At the command line, type:

./newrelic-daemon --help

For more information, see the C SDK

View app performance in New Relic

To view your app's performance with APM:

  1. Generate some traffic for your app, then wait a few minutes for your app to send data to New Relic.
  2. Explore your app's data in the APM UI.

If no data appears within a few minutes, check your c_sdk.log and newrelic-daemon.log files for errors. If you still have problems, follow the troubleshooting tips.

For more help

If you need more help, check out these support and learning resources: