ex_custom.c

A list of examples for Doxygen to cross-reference. If a function in libnewrelic.h appears in one of these examples, the example source file appears under the "Examples" header.

#include <stdlib.h>
#include <unistd.h>
#include "common.h"
#include "libnewrelic.h"
int main(void) {
newrelic_app_t* app = 0;
newrelic_txn_t* txn = 0;
newrelic_app_config_t* config = 0;
newrelic_custom_event_t* custom_event = 0;
example_init();
char* app_name = get_app_name();
if (NULL == app_name)
return -1;
char* license_key = get_license_key();
if (NULL == license_key)
return -1;
config = newrelic_create_app_config(app_name, license_key);
customize_config(&config);
/* Change the transaction tracer threshold to ensure a trace is generated */
/* Wait up to 10 seconds for the SDK to connect to the daemon */
app = newrelic_create_app(config, 10000);
/* Start a web transaction */
txn = newrelic_start_web_transaction(app, "ExampleWebTransaction");
seg = newrelic_start_segment(txn, NULL, NULL);
sleep(1);
/* Record a metric value of 100ms in the transaction txn */
newrelic_record_custom_metric(txn, "Custom/YourMetric/Label", 100);
/* Record a custom event with each type of attribute available in the API */
custom_event = newrelic_create_custom_event("aTypeForYourEvent");
newrelic_custom_event_add_attribute_int(custom_event, "keya", 42);
newrelic_custom_event_add_attribute_long(custom_event, "keyb", 84);
newrelic_custom_event_add_attribute_double(custom_event, "keyc", 42.42);
newrelic_custom_event_add_attribute_string(custom_event, "keyd", "A string");
newrelic_record_custom_event(txn, &custom_event);
/* End the one and only segment */
/* End web transaction */
return 0;
}
newrelic_transaction_tracer_threshold_t threshold
Whether to consider transactions for trace generation based on the apdex configuration or a specific ...
Definition: libnewrelic.h:209
struct _newrelic_txn_t newrelic_txn_t
A New Relic transaction.
Definition: libnewrelic.h:106
Definition: libnewrelic.h:191
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
newrelic_custom_event_t * newrelic_create_custom_event(const char *event_type)
Creates a custom event.
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.
newrelic_transaction_tracer_config_t transaction_tracer
Optional. The transaction tracer configuration.
Definition: libnewrelic.h:390
newrelic_app_config_t * newrelic_create_app_config(const char *app_name, const char *license_key)
Create a populated application configuration.
bool newrelic_custom_event_add_attribute_long(newrelic_custom_event_t *event, const char *key, long value)
Adds a long key/value pair to the custom event's attributes.
newrelic_app_t * newrelic_create_app(const newrelic_app_config_t *config, unsigned short timeout_ms)
Create an application.
newrelic_time_us_t duration_us
If the SDK configuration threshold is set to NEWRELIC_THRESHOLD_IS_OVER_DURATION, this field specifie...
Definition: libnewrelic.h:218
bool newrelic_record_custom_metric(newrelic_txn_t *transaction, const char *metric_name, double milliseconds)
Generate a custom metric.
void newrelic_record_custom_event(newrelic_txn_t *transaction, newrelic_custom_event_t **event)
Records the custom event.
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_custom_event_add_attribute_string(newrelic_custom_event_t *event, const char *key, const char *value)
Adds a string key/value pair to the custom event's attributes.
struct _newrelic_custom_event_t newrelic_custom_event_t
A Custom Event.
Definition: libnewrelic.h:851
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_custom_event_add_attribute_int(newrelic_custom_event_t *event, const char *key, int value)
Adds an int key/value pair to the custom event's attributes.
bool newrelic_custom_event_add_attribute_double(newrelic_custom_event_t *event, const char *key, double value)
Adds a double key/value pair to the custom event's attributes.
bool newrelic_destroy_app(newrelic_app_t **app)
Destroy the application.