span.c
/*
* Copyright 2020 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/
#include "newrelic-telemetry-sdk.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef OS_WINDOWS
#include <windows.h>
#else
#include <sys/time.h>
#endif
/*
* Exercise a span.
*/
int main() {
#ifdef OS_WINDOWS
SYSTEMTIME time;
GetSystemTime(&time);
nrt_time_t time_ms = (time.wSecond * 1000) + time.wMilliseconds;
#else
struct timeval tv;
gettimeofday(&tv, NULL);
nrt_time_t time_ms = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000;
#endif
/* Destroy a NULL span. */
nrt_span_t* span = NULL;
nrt_span_destroy(&span);
/* Initialize a span and add attributes */
assert(span);
nrt_span_set_timestamp(span, time_ms);
nrt_span_set_duration(span, 2000);
assert(attrs);
nrt_span_set_attributes(span, &attrs);
assert(NULL == attrs);
nrt_span_destroy(&span);
assert(NULL == span);
/* Call with NULL parameters */
nrt_span_set_id(NULL, NULL);
nrt_span_set_trace_id(NULL, NULL);
nrt_span_set_timestamp(NULL, time_ms);
nrt_span_set_name(NULL, NULL);
nrt_span_set_duration(NULL, 2000);
nrt_span_set_parent_id(NULL, NULL);
nrt_span_set_service_name(NULL, NULL);
nrt_span_destroy(NULL);
}
bool nrt_attributes_set_string(nrt_attributes_t *attributes, const char *key, const char *value)
Add a string attribute to an attribute collection.
bool nrt_span_set_attributes(nrt_span_t *span, nrt_attributes_t **attributes)
Set attributes on a span.
bool nrt_attributes_set_int(nrt_attributes_t *attributes, const char *key, int64_t value)
Add an int attribute to an attribute collection.
This is a helper library that supports sending New Relic data from within your C/C++ application.
bool nrt_span_set_timestamp(nrt_span_t *span, nrt_time_t timestamp)
Set the start timestamp for a span.
bool nrt_span_set_parent_id(nrt_span_t *span, const char *parent_id)
Set the parent_id of a span.
bool nrt_span_set_service_name(nrt_span_t *span, const char *service_name)
Set the service name of a span.
bool nrt_attributes_set_bool(nrt_attributes_t *attributes, const char *key, bool value)
Add a bool attribute to an attribute collection.
uint64_t nrt_time_t
Indicates a point in time or a duration.
Definition: newrelic-telemetry-sdk.h:68
bool nrt_attributes_set_uint(nrt_attributes_t *attributes, const char *key, uint64_t value)
Add an unsigned int attribute to an attribute collection.
struct _nrt_attributes_t nrt_attributes_t
A collection of attributes.
Definition: newrelic-telemetry-sdk.h:60
bool nrt_span_set_duration(nrt_span_t *span, nrt_time_t duration)
Set the duration for a span.
bool nrt_attributes_set_double(nrt_attributes_t *attributes, const char *key, double value)
Add a double attribute to an attribute collection.
nrt_span_t * nrt_span_new(const char *id, const char *trace_id, uint64_t timestamp)
Create a new span.
bool nrt_span_set_trace_id(nrt_span_t *span, const char *trace_id)
Set the trace_id of a span.
Generated on Wed Sep 16 2020 23:07:29 for New Relic C Telemetry SDK by
