newrelic-telemetry-sdk.h File Reference

This is a helper library that supports sending New Relic data from within your C/C++ application. More...

Go to the source code of this file.

Typedefs

typedef struct _nrt_client_config_t nrt_client_config_t
 A configuration object used to initialize a nrt_client_t.
 
typedef struct _nrt_client_t nrt_client_t
 A Client is capable of both queuing and sending span and metrics batches to a configured New Relic collector.
 
typedef struct _nrt_span_batch_t nrt_span_batch_t
 A span batch. More...
 
typedef struct _nrt_span_t nrt_span_t
 A span. More...
 
typedef struct _nrt_attributes_t nrt_attributes_t
 A collection of attributes. More...
 
typedef uint64_t nrt_time_t
 Indicates a point in time or a duration. More...
 

Enumerations

enum  nrt_log_level_t {
  NRT_LOG_ERROR = 0, NRT_LOG_WARN = 1, NRT_LOG_INFO = 2, NRT_LOG_DEBUG = 3,
  NRT_LOG_TRACE = 4
}
 Represents the available verbosity levels of the logger.
 

Functions

nrt_attributes_tnrt_attributes_new ()
 Create a new attribute collection. More...
 
bool nrt_log_init (nrt_log_level_t level, const char *filename)
 Initialize logging. More...
 
bool nrt_attributes_set_int (nrt_attributes_t *attributes, const char *key, int64_t value)
 Add an int attribute to an attribute collection. More...
 
bool nrt_attributes_set_uint (nrt_attributes_t *attributes, const char *key, uint64_t value)
 Add an unsigned int attribute to an attribute collection. More...
 
bool nrt_attributes_set_double (nrt_attributes_t *attributes, const char *key, double value)
 Add a double attribute to an attribute collection. More...
 
bool nrt_attributes_set_string (nrt_attributes_t *attributes, const char *key, const char *value)
 Add a string attribute to an attribute collection. More...
 
bool nrt_attributes_set_bool (nrt_attributes_t *attributes, const char *key, bool value)
 Add a bool attribute to an attribute collection. More...
 
void nrt_attributes_destroy (nrt_attributes_t **attributes)
 Destroy an attribute collection. More...
 
nrt_span_tnrt_span_new (const char *id, const char *trace_id, uint64_t timestamp)
 Create a new span. More...
 
bool nrt_span_set_id (nrt_span_t *span, const char *id)
 Set the id of a span. More...
 
bool nrt_span_set_trace_id (nrt_span_t *span, const char *trace_id)
 Set the trace_id of a span. More...
 
bool nrt_span_set_timestamp (nrt_span_t *span, nrt_time_t timestamp)
 Set the start timestamp for a span. More...
 
bool nrt_span_set_name (nrt_span_t *span, const char *name)
 Set the name of a span. More...
 
bool nrt_span_set_service_name (nrt_span_t *span, const char *service_name)
 Set the service name of a span. More...
 
bool nrt_span_set_parent_id (nrt_span_t *span, const char *parent_id)
 Set the parent_id of a span. More...
 
bool nrt_span_set_duration (nrt_span_t *span, nrt_time_t duration)
 Set the duration for a span. More...
 
bool nrt_span_set_attributes (nrt_span_t *span, nrt_attributes_t **attributes)
 Set attributes on a span. More...
 
void nrt_span_destroy (nrt_span_t **span)
 Destroy a span. More...
 
nrt_span_batch_tnrt_span_batch_new ()
 Create a new span batch. More...
 
bool nrt_span_batch_record (nrt_span_batch_t *batch, nrt_span_t **span)
 Add a span to a span batch. More...
 
void nrt_span_batch_destroy (nrt_span_batch_t **batch)
 Destroy a span batch. More...
 
nrt_client_config_tnrt_client_config_new (const char *key)
 Create a new client configuration with an Insights API key. More...
 
void nrt_client_config_set_backoff_factor (nrt_client_config_t *config, nrt_time_t backoff_factor)
 Configures a backoff factor. More...
 
void nrt_client_config_set_retries_max (nrt_client_config_t *config, uint32_t retries)
 Configures the maximum numbers of retries. More...
 
void nrt_client_config_set_endpoint_traces (nrt_client_config_t *config, const char *host, uint16_t port)
 Configure the ingest host for traces. More...
 
void nrt_client_config_set_product_info (nrt_client_config_t *config, const char *product, const char *version)
 Configure a product and version. More...
 
void nrt_client_config_set_queue_max (nrt_client_config_t *config, size_t queue_max)
 Configure the maximum of batches sent in one go. More...
 
void nrt_client_config_destroy (nrt_client_config_t **config)
 Destroy a client configuration. More...
 
nrt_client_tnrt_client_new (nrt_client_config_t **config)
 Create a new client. More...
 
bool nrt_client_send (nrt_client_t *client, nrt_span_batch_t **batch)
 Send a span batch. More...
 
void nrt_client_shutdown (nrt_client_t **client)
 Shutdown a client. More...
 
void nrt_client_destroy (nrt_client_t **client)
 Destroy a client. More...
 

Detailed Description

This is a helper library that supports sending New Relic data from within your C/C++ application.

See accompanying README and LICENSE for more information.

Typedef Documentation

◆ nrt_attributes_t

typedef struct _nrt_attributes_t nrt_attributes_t

A collection of attributes.

Allows you to add custom attributes to spans.

◆ nrt_span_batch_t

typedef struct _nrt_span_batch_t nrt_span_batch_t

A span batch.

This holds a collection of spans. See the specification for further details.

◆ nrt_span_t

typedef struct _nrt_span_t nrt_span_t

A span.

See the specification for further details.

◆ nrt_time_t

typedef uint64_t nrt_time_t

Indicates a point in time or a duration.

A point in time is indicated by a time in Epoch milliseconds, a duration is indicated by milliseconds.

Function Documentation

◆ nrt_attributes_destroy()

void nrt_attributes_destroy ( nrt_attributes_t **  attributes)

Destroy an attribute collection.

This destroys the attribute collection without adding it to a span. The passed pointer will be set to NULL.

Parameters
attributesAn attribute collection.
Examples
attributes.c.

◆ nrt_attributes_new()

nrt_attributes_t* nrt_attributes_new ( )

Create a new attribute collection.

THis allocates and initializes an empty attribute collection.

Returns
An empty attribute collection.
Examples
attributes.c, span.c, and trace_api.c.

◆ nrt_attributes_set_bool()

bool nrt_attributes_set_bool ( nrt_attributes_t attributes,
const char *  key,
bool  value 
)

Add a bool attribute to an attribute collection.

Parameters
attributesAn attribute collection.
keyThe attribute key.
valueThe attribute value.
Returns
True if the attribute was added.
Examples
attributes.c, span.c, and trace_api.c.

◆ nrt_attributes_set_double()

bool nrt_attributes_set_double ( nrt_attributes_t attributes,
const char *  key,
double  value 
)

Add a double attribute to an attribute collection.

Parameters
attributesAn attribute collection.
keyThe attribute key.
valueThe attribute value.
Returns
True if the attribute was added.
Examples
attributes.c, span.c, and trace_api.c.

◆ nrt_attributes_set_int()

bool nrt_attributes_set_int ( nrt_attributes_t attributes,
const char *  key,
int64_t  value 
)

Add an int attribute to an attribute collection.

Parameters
attributesAn attribute collection.
keyThe attribute key.
valueThe attribute value.
Returns
True if the attribute was added.
Examples
attributes.c, span.c, and trace_api.c.

◆ nrt_attributes_set_string()

bool nrt_attributes_set_string ( nrt_attributes_t attributes,
const char *  key,
const char *  value 
)

Add a string attribute to an attribute collection.

Parameters
attributesAn attribute collection.
keyThe attribute key.
valueThe attribute value.
Returns
True if the attribute was added.
Examples
attributes.c, span.c, and trace_api.c.

◆ nrt_attributes_set_uint()

bool nrt_attributes_set_uint ( nrt_attributes_t attributes,
const char *  key,
uint64_t  value 
)

Add an unsigned int attribute to an attribute collection.

Parameters
attributesAn attribute collection.
keyThe attribute key.
valueThe attribute value.
Returns
True if the attribute was added.
Examples
attributes.c, span.c, and trace_api.c.

◆ nrt_client_config_destroy()

void nrt_client_config_destroy ( nrt_client_config_t **  config)

Destroy a client configuration.

This will destroy a client configuration object and set the passed pointer to NULL.

Parameters
configA client configuration.
Examples
configuration.c.

◆ nrt_client_config_new()

nrt_client_config_t* nrt_client_config_new ( const char *  key)

Create a new client configuration with an Insights API key.

Other values will be set to defaults:

  • The default backoff factor will be 5 seconds.
  • The default maximum of retries is 8.
  • The default trace endpoint is * https://trace-api.newrelic.com/trace/v1` on port 80.
  • By default, product information is empty.
  • By default, no more than 100 batches are sent in one go.
Parameters
keyAn Insights API key.
Returns
A client configuration.
Examples
configuration.c, log.c, simple.c, and trace_api.c.

◆ nrt_client_config_set_backoff_factor()

void nrt_client_config_set_backoff_factor ( nrt_client_config_t config,
nrt_time_t  backoff_factor 
)

Configures a backoff factor.

If a request fails, the SDK retries the request at increasing intervals and eventually drops data if the request cannot be completed.

The amount of time to wait after a request can be computed using this logic:

backoff_factor * (2 ^ (number_of_retries - 1))

For a backoff factor of 1 second, and a maximum of 6 retries, the retry delay interval should follow a pattern of [0, 1, 2, 4, 8, 16].

See the specification for further details.

Parameters
configA client configuration.
backoff_factorA time duration used in the backoff calculation.
Examples
configuration.c.

◆ nrt_client_config_set_endpoint_traces()

void nrt_client_config_set_endpoint_traces ( nrt_client_config_t config,
const char *  host,
uint16_t  port 
)

Configure the ingest host for traces.

This overrides the default ingest host for traces to facilitate communication with alternative New Relic backends.

Parameters
configA client configuration.
hostThe name of the ingest host.
portThe port of the ingest host. Pass 0 to indicate usage of the default port.
Examples
configuration.c, and log.c.

◆ nrt_client_config_set_product_info()

void nrt_client_config_set_product_info ( nrt_client_config_t config,
const char *  product,
const char *  version 
)

Configure a product and version.

The specified product and version will be appended to the User-Agent header of payloads.

See the specification for further details.

Parameters
configA client configuration.
productA product name.
versionA product version. Pass NULL to use no version.
Examples
configuration.c.

◆ nrt_client_config_set_queue_max()

void nrt_client_config_set_queue_max ( nrt_client_config_t config,
size_t  queue_max 
)

Configure the maximum of batches sent in one go.

If the number of batches queued exceeds the maximum given here, the additional batches will be dropped. This mechanism avoids accumulating back pressure.

Parameters
configA client configuration.
queue_maxThe maximum queue size.
Examples
configuration.c.

◆ nrt_client_config_set_retries_max()

void nrt_client_config_set_retries_max ( nrt_client_config_t config,
uint32_t  retries 
)

Configures the maximum numbers of retries.

If a request fails, the SDK retries the request at increasing intervals and eventually drops data if the request cannot be completed.

If zero is given as a maximum, no retries will be made for failed requests.

For a backoff factor of 1 second, and a maximum of 6 retries, the retry delay interval should follow a pattern of [0, 1, 2, 4, 8, 16].

See the specification for further details.

Parameters
configA client configuration.
retriesThe maximum number of retries for failed requests.
Examples
configuration.c.

◆ nrt_client_destroy()

void nrt_client_destroy ( nrt_client_t **  client)

Destroy a client.

Destroy the client, without making sure pending data is sent. The passed pointer will be set to NULL.

Parameters
clientA client.

◆ nrt_client_new()

nrt_client_t* nrt_client_new ( nrt_client_config_t **  config)

Create a new client.

The passed configuration will be destroyed and the passed pointer will always be set to NULL.

Parameters
configA client configuration.
Returns
A client.
Examples
log.c, simple.c, and trace_api.c.

◆ nrt_client_send()

bool nrt_client_send ( nrt_client_t client,
nrt_span_batch_t **  batch 
)

Send a span batch.

Put a span batch in the queue of the client. This function returns as soon as the span batch was queued and doesn't wait for it to be sent successfully.

If the span batch is successfully queued, the client takes ownership of the span batch. Otherwise the batch will be destroyed. The passed pointer will always be set to NULL.

Parameters
clientA client.
batchThe span batch to be sent.
Returns
True if the span batch was successfully queued.
Examples
trace_api.c.

◆ nrt_client_shutdown()

void nrt_client_shutdown ( nrt_client_t **  client)

Shutdown a client.

Shuts down the client, sends pending data and frees the client object. The passed pointer will be set to NULL.

Parameters
clientA client.
Examples
simple.c, and trace_api.c.

◆ nrt_log_init()

bool nrt_log_init ( nrt_log_level_t  level,
const char *  filename 
)

Initialize logging.

This will cause the Telemetry SDK to log messages of the given level to the file of the given name.

Parameters
levelThe log level.
filenameThe name of the file to log messages to. For example: if you want to log to stdout or stderr data streams, specify stdout or stderr as the filename.
Returns
True if log was initialized.
Examples
log.c, and trace_api.c.

◆ nrt_span_batch_destroy()

void nrt_span_batch_destroy ( nrt_span_batch_t **  batch)

Destroy a span batch.

This destroys a span batch. Any spans previously added to the span batch will be lost. The passed pointer will be set to NULL.

Parameters
batchA span batch.

◆ nrt_span_batch_new()

nrt_span_batch_t* nrt_span_batch_new ( )

Create a new span batch.

A span batch is a collection of spans that is sent in one payload. This creates an empty span batch collection

Returns
An empty span batch.
Examples
trace_api.c.

◆ nrt_span_batch_record()

bool nrt_span_batch_record ( nrt_span_batch_t batch,
nrt_span_t **  span 
)

Add a span to a span batch.

If the span was successfully added to the batch, the batch takes ownership of the span. Otherwise the span will be destroyed. The passed pointer will always be set to NULL.

Parameters
batchA span batch.
spanA span.
Returns
True if the span was successfully added to the batch.
Examples
trace_api.c.

◆ nrt_span_destroy()

void nrt_span_destroy ( nrt_span_t **  span)

Destroy a span.

This destroys a span without adding it to a batch. The passed pointer will be set to NULL.

Parameters
spanA span.
Examples
span.c.

◆ nrt_span_new()

nrt_span_t* nrt_span_new ( const char *  id,
const char *  trace_id,
uint64_t  timestamp 
)

Create a new span.

This Allocates and initialize a new span.

Parameters
idA span id.
trace_idThe trace id.
timestampThe timestamp.
Returns
A span.
Examples
span.c, and trace_api.c.

◆ nrt_span_set_attributes()

bool nrt_span_set_attributes ( nrt_span_t span,
nrt_attributes_t **  attributes 
)

Set attributes on a span.

If the attributes were successfully added to the span, the span takes ownership of the attribute collection. Otherwise the attribute collection will be destroyed. The passed pointer to the attribute collection will always be set to NULL.

Parameters
spanA span.
attributesAn attribute collection.
Returns
true if the attributes were added.
Examples
span.c, and trace_api.c.

◆ nrt_span_set_duration()

bool nrt_span_set_duration ( nrt_span_t span,
nrt_time_t  duration 
)

Set the duration for a span.

Parameters
spanA span.
durationThe duration for the span in milliseconds.
Returns
True if the duration could be set.
Examples
span.c, and trace_api.c.

◆ nrt_span_set_id()

bool nrt_span_set_id ( nrt_span_t span,
const char *  id 
)

Set the id of a span.

Parameters
spanA span.
idThe unique identifier for the span.
Returns
True if the id could be set.
Examples
span.c.

◆ nrt_span_set_name()

bool nrt_span_set_name ( nrt_span_t span,
const char *  name 
)

Set the name of a span.

Parameters
spanA span.
nameThe name for the span.
Returns
True if the name could be set.
Examples
span.c, and trace_api.c.

◆ nrt_span_set_parent_id()

bool nrt_span_set_parent_id ( nrt_span_t span,
const char *  parent_id 
)

Set the parent_id of a span.

Parameters
spanA span.
parent_idThe parent_id for the span.
Returns
True if the parent_id could be set.
Examples
span.c, and trace_api.c.

◆ nrt_span_set_service_name()

bool nrt_span_set_service_name ( nrt_span_t span,
const char *  service_name 
)

Set the service name of a span.

Parameters
spanA span.
service_nameThe service name for the span.
Returns
True if the service name could be set.
Examples
span.c, and trace_api.c.

◆ nrt_span_set_timestamp()

bool nrt_span_set_timestamp ( nrt_span_t span,
nrt_time_t  timestamp 
)

Set the start timestamp for a span.

Parameters
spanA span.
timestampThe start timestamp for the span.
Returns
True if the start timestamp could be set.
Examples
span.c.

◆ nrt_span_set_trace_id()

bool nrt_span_set_trace_id ( nrt_span_t span,
const char *  trace_id 
)

Set the trace_id of a span.

Parameters
spanA span.
trace_idThe trace_id for the span.
Returns
True if the trace_id could be set.
Examples
span.c.