ex_simple.c
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
/*
* A standalone example that demonstrates to users how to
* configure logging, configure an app, connect an app,
* start a transaction and a segment, and cleanly destroy
* everything.
*/
#include "libnewrelic.h"
int main(void) {
config
= newrelic_create_app_config("YOUR_APP_NAME", "_NEW_RELIC_LICENSE_KEY_");
if (!newrelic_configure_log("./c_sdk.log", NEWRELIC_LOG_INFO)) {
printf("Error configuring logging.\n");
return -1;
}
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);
/* Start a web transaction and a segment */
txn = newrelic_start_web_transaction(app, "Transaction name");
seg = newrelic_start_segment(txn, "Segment name", "Custom");
/* Interesting application code happens here */
sleep(2);
/* End the segment and web transaction */
return 0;
}
struct _newrelic_txn_t newrelic_txn_t
A New Relic transaction.
Definition: libnewrelic.h:106
bool newrelic_init(const char *daemon_socket, int time_limit_ms)
Initialise the C SDK with non-default settings.
newrelic_txn_t * newrelic_start_web_transaction(newrelic_app_t *app, const char *name)
Start a web based transaction.
Configuration used to describe application name, license key, as well as optional transaction tracer ...
Definition: libnewrelic.h:347
struct _nr_app_and_info_t newrelic_app_t
A New Relic application. Once an application configuration is created with newrelic_create_app_config...
Definition: libnewrelic.h:95
bool newrelic_end_segment(newrelic_txn_t *transaction, newrelic_segment_t **segment_ptr)
Record the completion of a segment in a transaction.
bool newrelic_configure_log(const char *filename, newrelic_loglevel_t level)
Configure the C SDK's logging system.
Definition: libnewrelic.h:135
newrelic_app_config_t * newrelic_create_app_config(const char *app_name, const char *license_key)
Create a populated application configuration.
newrelic_app_t * newrelic_create_app(const newrelic_app_config_t *config, unsigned short timeout_ms)
Create an application.
bool newrelic_destroy_app_config(newrelic_app_config_t **config)
Destroy the application configuration.
newrelic_segment_t * newrelic_start_segment(newrelic_txn_t *transaction, const char *name, const char *category)
Record the start of a custom segment in a transaction.
struct _newrelic_segment_t newrelic_segment_t
A segment within a transaction.
Definition: libnewrelic.h:840
bool newrelic_end_transaction(newrelic_txn_t **transaction_ptr)
End a transaction.
This is the New Relic C SDK! If your application does not use other New Relic APM agent languages,...
bool newrelic_destroy_app(newrelic_app_t **app)
Destroy the application.