AppDynamics IoT C++ SDK
AppDynamics IoT C++ library contains code that facilitates capturing availability, usage, network performance and errors of an IoT Application.
error_event.cpp File Reference
#include "beacon.hpp"
#include "log.hpp"
#include "config.hpp"
#include "custom_event.hpp"
#include "appd_iot_interface.h"

Functions

static appd_iot_error_code_t appd_iot_copy_stack_trace (std::list< stack_trace_t > *dest_stack_trace_list, appd_iot_stack_trace_t *src_stack_trace, int src_stack_trace_count)
 Copies User Defined Stack Trace to SDK Defined Stack Trace. More...
 
appd_iot_error_code_t appd_iot_add_error_event (appd_iot_error_event_t error_event)
 converts error event data to beacon format and adds to beacon More...
 

Variables

static const char * severity_str [APPD_IOT_ERR_MAX_SEVERITY_LEVELS] = {"alert", "critical", "fatal"}
 

Function Documentation

◆ appd_iot_copy_stack_trace()

static appd_iot_error_code_t appd_iot_copy_stack_trace ( std::list< stack_trace_t > *  dest_stack_trace_list,
appd_iot_stack_trace_t src_stack_trace,
int  src_stack_trace_count 
)
static

Copies User Defined Stack Trace to SDK Defined Stack Trace.

Parameters
dest_stack_trace_listcontains stack trace list to be copied to
src_stack_tracecontains stack trace list to be copied from
src_stack_trace_countcontains number of stack traces
Returns
appd_iot_error_code_t indicating function execution status
136 {
137 
138  if (dest_stack_trace_list == NULL)
139  {
140  appd_iot_log(APPD_IOT_LOG_ERROR, "List to copy stack trace is NULL");
141  return APPD_IOT_ERR_INTERNAL;
142  }
143 
144  if (src_stack_trace == NULL)
145  {
146  appd_iot_log(APPD_IOT_LOG_ERROR, "Error Event Stack Trace is NULL");
147  return APPD_IOT_ERR_NULL_PTR;
148  }
149 
150  for (int i = 0; i < src_stack_trace_count; i++)
151  {
152  stack_trace_t dest_stack_trace;
153 
154  dest_stack_trace.runtime = "native";
155 
156  //dest_stack_trace has default values as empty strings
157  if (src_stack_trace->thread != NULL)
158  {
159  dest_stack_trace.thread = src_stack_trace->thread;
160  }
161 
162  for (int j = 0; j < src_stack_trace->stack_frame_count; j++)
163  {
164  stack_frame_t dest_stack_frame;
165 
166  if ((src_stack_trace->stack_frame + j) == NULL)
167  {
168  appd_iot_log(APPD_IOT_LOG_ERROR, "NULL stack frame found inside stack trace");
169  return APPD_IOT_ERR_NULL_PTR;
170  }
171 
172  appd_iot_stack_frame_t src_stack_frame = src_stack_trace->stack_frame[j];
173 
174  //dest_stack_frame has default values as empty strings
175  if (src_stack_frame.symbol_name != NULL)
176  {
177  dest_stack_frame.symbol_name = src_stack_frame.symbol_name;
178  }
179 
180  if (src_stack_frame.package_name != NULL)
181  {
182  dest_stack_frame.package_name = src_stack_frame.package_name;
183  }
184 
185  if (src_stack_frame.file_name != NULL)
186  {
187  dest_stack_frame.file_name = src_stack_frame.file_name;
188  }
189 
190  dest_stack_frame.lineno = src_stack_frame.lineno;
191  dest_stack_frame.absolute_addr = src_stack_frame.absolute_addr;
192  dest_stack_frame.image_offset = src_stack_frame.image_offset;
193  dest_stack_frame.symbol_offset = src_stack_frame.symbol_offset;
194 
195  dest_stack_trace.stack_frame_list.push_back(dest_stack_frame);
196  }
197 
198  dest_stack_trace_list->push_back(dest_stack_trace);
199  }
200 
201  return APPD_IOT_SUCCESS;
202 }
int image_offset
Definition: beacon.hpp:67
int symbol_offset
Definition: beacon.hpp:68
Definition: appd_iot_def.h:44
std::string package_name
Definition: beacon.hpp:63
uint64_t absolute_addr
Definition: beacon.hpp:66
void appd_iot_log(appd_iot_log_level_t log_level, const char *format,...)
Reads log message, appends log header and triggers log write callback function.
Definition: log.cpp:89
const char * thread
Definition: appd_iot_def.h:302
const char * symbol_name
Definition: appd_iot_def.h:279
Definition: beacon.hpp:60
int image_offset
Definition: appd_iot_def.h:289
Definition: beacon.hpp:71
const char * package_name
Definition: appd_iot_def.h:281
AppDynamics Stack Frame This structure captures a single element in the stack frame Each stack fr...
Definition: appd_iot_def.h:276
uint64_t absolute_addr
Definition: appd_iot_def.h:287
std::string symbol_name
Definition: beacon.hpp:62
const char * file_name
Definition: appd_iot_def.h:283
int lineno
Definition: appd_iot_def.h:285
int stack_frame_count
Definition: appd_iot_def.h:306
int lineno
Definition: beacon.hpp:65
Definition: appd_iot_def.h:30
Definition: appd_iot_def.h:99
std::list< stack_frame_t > stack_frame_list
Definition: beacon.hpp:75
int symbol_offset
Definition: appd_iot_def.h:291
std::string thread
Definition: beacon.hpp:73
Definition: appd_iot_def.h:46
std::string file_name
Definition: beacon.hpp:64
appd_iot_stack_frame_t * stack_frame
Definition: appd_iot_def.h:304
std::string runtime
Definition: beacon.hpp:74

◆ appd_iot_add_error_event()

appd_iot_error_code_t appd_iot_add_error_event ( appd_iot_error_event_t  error_event)

converts error event data to beacon format and adds to beacon

This method adds event data
Each call to add event will create a new event.

Parameters
error_eventcontains event data
Returns
appd_iot_error_code_t indicating function execution status
35 {
36  appd_iot_error_code_t retcode;
37  appd_iot_sdk_state_t sdk_state;
38  error_event_t event;
39 
40  if ((sdk_state = appd_iot_get_sdk_state()) != APPD_IOT_SDK_ENABLED)
41  {
42  appd_iot_log(APPD_IOT_LOG_ERROR, "Add Error Event Failed. SDK Not in Enabled State:%s",
43  appd_iot_sdk_state_to_str(sdk_state));
44 
46  }
47 
48  retcode = APPD_IOT_SUCCESS;
49  event.timestamp_ms = error_event.timestamp_ms;
50  event.duration_ms = error_event.duration_ms;
51 
52  if (error_event.name != NULL)
53  {
54  event.name = error_event.name;
55  }
56  else
57  {
58  appd_iot_log(APPD_IOT_LOG_WARN, "Error Event Name cannot be NULL");
59  }
60 
61  if (error_event.message != NULL)
62  {
63  event.message = error_event.message;
64  }
65 
67  {
68  event.severity = severity_str[error_event.severity];
69  }
70  else
71  {
73  }
74 
75  if (error_event.stack_trace_count > 0)
76  {
77  if (error_event.error_stack_trace_index >= error_event.stack_trace_count)
78  {
79  appd_iot_log(APPD_IOT_LOG_ERROR, "Invalid error stack trace index, setting to index 0");
80 
81  event.error_stack_trace_index = 0;
82  }
83  else
84  {
85  event.error_stack_trace_index = error_event.error_stack_trace_index;
86  }
87 
89  error_event.stack_trace,
90  error_event.stack_trace_count);
91 
92  if (retcode != APPD_IOT_SUCCESS)
93  {
94  appd_iot_log(APPD_IOT_LOG_ERROR, "Failed to parse stack traces, error:%s",
96 
97  event.stack_trace_list.clear();
98  }
99  }
100  else
101  {
102  appd_iot_log(APPD_IOT_LOG_INFO, "No stack traces present");
103  }
104 
105  if (error_event.data_count > 0)
106  {
107  retcode = appd_iot_copy_event_data(&event.data, error_event.data,
108  error_event.data_count);
109 
110  if (retcode != APPD_IOT_SUCCESS)
111  {
112  appd_iot_log(APPD_IOT_LOG_ERROR, "Failed to parse error event data, error:%s",
113  appd_iot_error_code_to_str(retcode));
114 
116  }
117  }
118 
119  appd_iot_log(APPD_IOT_LOG_INFO, "Adding Error Event with name:%s", error_event.name);
120 
121  retcode = appd_iot_add_error_event_to_beacon(event);
122 
123  return retcode;
124 }
Definition: appd_iot_def.h:50
appd_iot_sdk_state_t
Enums for SDK State.
Definition: appd_iot_def.h:59
int duration_ms
Definition: appd_iot_def.h:326
void appd_iot_log(appd_iot_log_level_t log_level, const char *format,...)
Reads log message, appends log header and triggers log write callback function.
Definition: log.cpp:89
Definition: appd_iot_def.h:101
appd_iot_error_code_t appd_iot_copy_event_data(data_t *destdata, appd_iot_data_t *srcdata, int srcdata_count)
Copies User Defined Event Data to SDK Defined Event Data.
Definition: custom_event.cpp:110
int data_count
Definition: appd_iot_def.h:334
appd_iot_sdk_state_t appd_iot_get_sdk_state(void)
Get Current SDK State.
Definition: config.cpp:236
int error_stack_trace_index
Definition: appd_iot_def.h:330
data_t data
Definition: beacon.hpp:87
appd_iot_stack_trace_t * stack_trace
Definition: appd_iot_def.h:332
const char * appd_iot_error_code_to_str(appd_iot_error_code_t error_code) __APPD_IOT_API
Convert error code to string.
Definition: log.cpp:193
const char * message
Definition: appd_iot_def.h:320
int stack_trace_count
Definition: appd_iot_def.h:328
Definition: appd_iot_def.h:64
appd_iot_error_code_t
Error Code Enums for SDK log.
Definition: appd_iot_def.h:27
int64_t timestamp_ms
Definition: appd_iot_def.h:324
Definition: appd_iot_def.h:103
std::list< stack_trace_t > stack_trace_list
Definition: beacon.hpp:86
static const char * severity_str[APPD_IOT_ERR_MAX_SEVERITY_LEVELS]
Definition: error_event.cpp:23
appd_iot_error_code_t appd_iot_add_error_event_to_beacon(error_event_t event)
Adds Error Event to Beacon.
Definition: beacon.cpp:141
Definition: appd_iot_def.h:87
appd_iot_data_t * data
Definition: appd_iot_def.h:336
Definition: appd_iot_def.h:83
const char * name
Definition: appd_iot_def.h:318
static appd_iot_error_code_t appd_iot_copy_stack_trace(std::list< stack_trace_t > *dest_stack_trace_list, appd_iot_stack_trace_t *src_stack_trace, int src_stack_trace_count)
Copies User Defined Stack Trace to SDK Defined Stack Trace.
Definition: error_event.cpp:134
appd_iot_error_severity_t severity
Definition: appd_iot_def.h:322
Definition: beacon.hpp:78
Definition: appd_iot_def.h:30
Definition: appd_iot_def.h:99
const char * appd_iot_sdk_state_to_str(appd_iot_sdk_state_t sdk_state) __APPD_IOT_API
Convert sdk state to string.
Definition: log.cpp:203
appd_iot_error_code_t appd_iot_clear_event_data(data_t *data)
Clear event data.
Definition: custom_event.cpp:91

Variable Documentation

◆ severity_str

const char* severity_str[APPD_IOT_ERR_MAX_SEVERITY_LEVELS] = {"alert", "critical", "fatal"}
static