solarwinds_apm 5.1.6 → 5.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,8 @@
1
1
  /**
2
- * @file oboe_api.hpp - C++ liboboe wrapper primarily for generating SWIG interfaces
3
- * and used by Ruby c++ extension for profiling
4
- *
5
- * TODO: This doc is outdated
6
- * This API should follow https://github.com/tracelytics/tracelons/wiki/Instrumentation-API
2
+ * C++ liboboe wrapper primarily for generating SWIG interfaces
7
3
  */
8
-
9
- #ifndef OBOE_API_HPP
10
- #define OBOE_API_HPP
4
+ #ifndef OBOE_API_H
5
+ #define OBOE_API_H
11
6
 
12
7
  #include <unistd.h>
13
8
  #include <cstdlib>
@@ -39,28 +34,47 @@ typedef struct frame_data {
39
34
  class Metadata : private oboe_metadata_t {
40
35
  friend class Reporter;
41
36
  friend class Context;
42
-
43
- public:
37
+ public:
44
38
  Metadata(const oboe_metadata_t *md);
45
39
  ~Metadata();
46
-
47
- // these new objects are managed by SWIG %newobject
48
40
  /**
49
- * Create a new event object using this Metadata's context.
50
- *
51
- * NOTE: The returned object must be "delete"d.
41
+ * Return an `new` C++ object
42
+ * Object ownership changed via SWIG
43
+ * SWIG managed the de-allocation using %newobject keyword
44
+ * @return Event*
52
45
  */
53
46
  Event *createEvent();
54
-
47
+ /**
48
+ * Return an `new` C++ object
49
+ * Object ownership changed via SWIG
50
+ * SWIG managed the de-allocation using %newobject keyword
51
+ * @return Metadata*
52
+ */
55
53
  Metadata *copy();
56
54
  bool isValid();
57
55
  bool isSampled();
58
-
56
+ /**
57
+ * Return an `new` C++ object
58
+ * Object ownership changed via SWIG
59
+ * SWIG managed the de-allocation using %newobject keyword
60
+ * @param sampled bool default=true
61
+ * @return Metadata*
62
+ */
59
63
  static Metadata *makeRandom(bool sampled = true);
60
- static Metadata *fromString(std::string s);
61
-
64
+ /**
65
+ * Return an `new` C++ object
66
+ * Object ownership changed via SWIG
67
+ * SWIG managed the de-allocation using %newobject keyword
68
+ * @param s std::string
69
+ * @return Metadata*
70
+ */
71
+ static Metadata *fromString(const std::string& s);
72
+ /**
73
+ * Return this pointer
74
+ * No Object ownership changed via SWIG
75
+ * @return oboe_metadata_t*
76
+ */
62
77
  oboe_metadata_t *metadata();
63
-
64
78
  #ifdef SWIGJAVA
65
79
  std::string toStr();
66
80
  #else
@@ -169,10 +183,12 @@ class Context {
169
183
  long header_timestamp = 0);
170
184
 
171
185
  /**
172
- * Get a pointer to the current context (from thread-local storage)
186
+ * Return a pointer to the current context
187
+ * Return a pointer in C++ heap
188
+ * No object ownership changed via SWIG
189
+ * @return oboe_metadata_t*
173
190
  */
174
191
  static oboe_metadata_t *get();
175
-
176
192
  /**
177
193
  * Get the current context as a printable string.
178
194
  */
@@ -189,10 +205,16 @@ class Context {
189
205
 
190
206
  /**
191
207
  * Set the current context from a string.
208
+ * @param s const std::string&
192
209
  */
193
- static void fromString(std::string s);
210
+ static void fromString(const std::string& s);
194
211
 
195
- // this new object is managed by SWIG %newobject
212
+ /**
213
+ * Return an `new` C++ object
214
+ * Object ownership changed via SWIG
215
+ * SWIG managed the de-allocation using %newobject keyword
216
+ * @return Metadata*
217
+ */
196
218
  static Metadata *copy();
197
219
 
198
220
  static void setSampledFlag();
@@ -206,7 +228,7 @@ class Context {
206
228
  /**
207
229
  * Perform validation and replacement of invalid characters on the given service key.
208
230
  */
209
- static std::string validateTransformServiceName(std::string service_key);
231
+ static std::string validateTransformServiceName(const std::string& service_key);
210
232
 
211
233
  /**
212
234
  * Shut down the Oboe library.
@@ -235,31 +257,45 @@ class Context {
235
257
  */
236
258
  static bool isLambda();
237
259
 
238
- // these new objects are managed by SWIG %newobject
239
260
  /**
240
- * Create a new event object using the thread's context.
241
- *
242
- * NOTE: The returned object must be "delete"d.
261
+ * Return an `new` C++ object
262
+ * Object ownership changed via SWIG
263
+ * SWIG managed the de-allocation using %newobject keyword
264
+ * @return Event*
243
265
  */
244
266
  static Event *createEvent();
267
+ /**
268
+ * Return an `new` C++ object
269
+ * Object ownership changed via SWIG
270
+ * SWIG managed the de-allocation using %newobject keyword
271
+ * @return Event*
272
+ */
245
273
  static Event *startTrace();
246
-
247
274
  /**
248
275
  * Create entry event with user-defined metadata and timestamp
276
+ * Return an `new` C++ object
277
+ * Object ownership changed via SWIG
278
+ * SWIG managed the de-allocation using %newobject keyword
249
279
  * @param md const oboe_metadata_t *
250
280
  * @param timestamp int64_t
251
- * @param parent_md const oboe_metadata_t *
281
+ * @param parent_md const oboe_metadata_t * default = nullptr
252
282
  * @return Event*
253
283
  */
254
284
  static Event* createEntry(const oboe_metadata_t *md, int64_t timestamp, const oboe_metadata_t *parent_md = nullptr);
255
285
  /**
256
286
  * Create an continuous event with user-defined timestamp
287
+ * Return an `new` C++ object
288
+ * Object ownership changed via SWIG
289
+ * SWIG managed the de-allocation using %newobject keyword
257
290
  * @param timestamp int64_t
258
291
  * @return Event*
259
292
  */
260
293
  static Event* createEvent(int64_t timestamp);
261
294
  /**
262
295
  * Create exit event with user-defined timestamp
296
+ * Return an `new` C++ object
297
+ * Object ownership changed via SWIG
298
+ * SWIG managed the de-allocation using %newobject keyword
263
299
  * @param timestamp int64_t
264
300
  * @return Event*
265
301
  */
@@ -280,7 +316,7 @@ class Event : private oboe_event_t {
280
316
 
281
317
  // called e.g. from Python e.addInfo("Key", None) & Ruby e.addInfo("Key", nil)
282
318
  bool addInfo(char *key, void *val);
283
- bool addInfo(char *key, const std::string &val);
319
+ bool addInfo(char *key, const std::string& val);
284
320
  bool addInfo(char *key, long val);
285
321
  bool addInfo(char *key, double val);
286
322
  bool addInfo(char *key, bool val);
@@ -296,9 +332,10 @@ class Event : private oboe_event_t {
296
332
  bool addHostname();
297
333
 
298
334
  /**
299
- * Get a new copy of this metadata.
300
- *
301
- * NOTE: The returned object must be "delete"d.
335
+ * Return an `new` C++ object
336
+ * Object ownership changed via SWIG
337
+ * SWIG managed the de-allocation using %newobject keyword
338
+ * @return Metadata*
302
339
  */
303
340
  Metadata *getMetadata();
304
341
  std::string metadataString();
@@ -325,16 +362,15 @@ class Event : private oboe_event_t {
325
362
 
326
363
  bool addSpanRef(const oboe_metadata_t *md);
327
364
  bool addProfileEdge(std::string id);
328
-
329
365
  /**
330
- * Create a new event object using the given metadata context.
331
- *
332
- * NOTE: The metadata context must be unique to the new trace.
333
- *
334
- * NOTE: The returned object must be "delete"d.
335
- *
336
- * @param md The metadata object to use when creating the new event.
337
- */
366
+ * Create a new event object using the given metadata context.
367
+ * NOTE: The metadata context must be unique to the new trace.
368
+ * Return an `new` C++ object
369
+ * Object ownership changed via SWIG
370
+ * SWIG managed the de-allocation using %newobject keyword
371
+ * @param md const oboe_metadata_t*
372
+ * @return Event*
373
+ */
338
374
  static Event *startTrace(const oboe_metadata_t *md);
339
375
  };
340
376
 
@@ -362,6 +398,9 @@ class MetricTags {
362
398
  * Please note that SWIG doesn't have the definition of
363
399
  * oboe_metric_tag_t.
364
400
  * Ruby and Python should not call this method
401
+ *
402
+ * Return tags as pointer.
403
+ * No object ownership changed via SWIG
365
404
  * @return oboe_metric_tag_t*
366
405
  */
367
406
  oboe_metric_tag_t *get() const;
@@ -459,4 +498,4 @@ class Config {
459
498
  static std::string getVersionString();
460
499
  };
461
500
 
462
- #endif // OBOE_API_HPP
501
+ #endif // OBOE_API_H
@@ -1,11 +1,3 @@
1
- /**
2
- * @file: debug.h - Diagnostic logging functions for liboboe.
3
- *
4
- * Most of the diagnostics logging interface is defined in oboe.h but we
5
- * separate some of it out here for special handling when generating
6
- * SWIG interfaces.
7
- */
8
-
9
1
  #ifndef _OBOE_DEBUG_H
10
2
  #define _OBOE_DEBUG_H
11
3
 
@@ -13,6 +5,8 @@
13
5
  extern "C" {
14
6
  #endif
15
7
 
8
+ #include <stdbool.h>
9
+
16
10
  /**
17
11
  * Defined diagnostic log detail levels.
18
12
  */
@@ -44,14 +38,287 @@ enum OBOE_DEBUG_MODULE {
44
38
  OBOE_MODULE_PHP, /*!< PHP interpreter */
45
39
  OBOE_MODULE_DOTNET, /*!< dotnet wrapper */
46
40
  OBOE_MODULE_RUBY, /*!< ruby c++ extension */
41
+ OBOE_MODULE_HOST_ID_SERVICE,
42
+ OBOE_MODULE_AWS_RESOURCE_PROVIDER,
43
+ OBOE_MODULE_AZURE_RESOURCE_PROVIDER,
47
44
  };
48
45
 
46
+ /** Compile time debug logging detail level - cannot log more detailed than this. */
47
+ #define OBOE_DEBUG_LEVEL OBOE_DEBUG_HIGH
48
+
49
49
  /**
50
50
  * Initial debug log detail level.
51
51
  *
52
52
  */
53
53
  #define LOGLEVEL_DEFAULT OBOE_DEBUG_INFO
54
54
 
55
+ /** Limit for number of messages at specified level before demoting to debug MEDIUM. */
56
+ #define MAX_DEBUG_MSG_COUNT 1
57
+
58
+ void oboe_debug_log_init(FILE* output);
59
+
60
+ /**
61
+ * Low-level diagnostics logging function.
62
+ *
63
+ * This is normally used only by the OBOE_DEBUG_LOG_* function macros and not used directly.
64
+ *
65
+ * This function may be adapted to format and route diagnostic log messages as desired.
66
+ *
67
+ * @param module One of the numeric module identifiers defined in debug.h - used to control logging detail by module.
68
+ * @param level Diagnostic detail level of this message - used to control logging volume by detail level.
69
+ * @param source_name Name of the source file, if available, or another useful name, or NULL.
70
+ * @param source_lineno Number of the line in the source file where message is logged from, if available, or zero.
71
+ * @param format A C language printf format specification string.
72
+ * @param args A variable argument list in VA_ARG format containing arguments for each argument specifier in the format.
73
+ */
74
+ void oboe_debug_logger(int module, int level, const char *source_name, int source_lineno, const char *format, ...);
75
+
76
+
77
+ /**
78
+ * Prototype for a logger call-back function.
79
+ *
80
+ * A logging function of this form can be added to the logger chain using
81
+ * oboe_debug_log_add().
82
+ *
83
+ * @param context The context pointer that was registered in the call to
84
+ * oboe_debug_log_add(). Use it to pass the pointer-to-self for
85
+ * objects (ie. "this" in C++) or just a structure in C, May be
86
+ * NULL.
87
+ * @param module The module identifier as passed to oboe_debug_logger().
88
+ * @param level The diagnostic detail level as passed to oboe_debug_logger().
89
+ * @param source_name Name of the source file as passed to oboe_debug_logger().
90
+ * @param source_lineno Number of the line in the source file where message is
91
+ * logged from as passed to oboe_debug_logger().
92
+ * @param msg The formatted message produced from the format string and its
93
+ * arguments as passed to oboe_debug_logger().
94
+ */
95
+ typedef void (*OboeDebugLoggerFcn)(void *context, int module, int level, const char *source_name, int source_lineno, const char *msg);
96
+
97
+ /**
98
+ * Get a printable name for a diagnostics logging level.
99
+ */
100
+ const char *oboe_debug_log_level_name(int level);
101
+
102
+ /**
103
+ * Get a printable name for a diagnostics logging module identifier.
104
+ */
105
+ const char *oboe_debug_module_name(int module);
106
+
107
+ /**
108
+ * Get the maximum logging detail level for a module or for all modules.
109
+ *
110
+ * This level applies to the stderr logger only. Added loggers get all messages
111
+ * below their registed detail level and need to do their own module-specific
112
+ * filtering.
113
+ *
114
+ * @param module One of the OBOE_MODULE_* values. Use OBOE_MODULE_ALL (-1) to
115
+ * get the overall maximum detail level.
116
+ * @return Maximum detail level value for module (or overall) where zero is the
117
+ * lowest and higher values generate more detailed log messages.
118
+ */
119
+ int oboe_debug_log_level_get(int module);
120
+
121
+ /**
122
+ * Set the maximum logging detail level for a module or for all modules.
123
+ *
124
+ * This level applies to the stderr logger only. Added loggers get all messages
125
+ * below their registered detail level and need to do their own module-specific
126
+ * filtering.
127
+ *
128
+ * @param module One of the OBOE_MODULE_* values. Use OBOE_MODULE_ALL to set
129
+ * the overall maximum detail level.
130
+ * @param newLevel Maximum detail level value where zero is the lowest and higher
131
+ * values generate more detailed log messages.
132
+ */
133
+ void oboe_debug_log_level_set(FILE* output, int module, int newLevel);
134
+
135
+ /**
136
+ * Set the output stream for the default logger.
137
+ *
138
+ * @param newStream A valid, open FILE* stream or NULL to disable the default logger.
139
+ * @return Zero on success; otherwise an error code (normally from errno).
140
+ */
141
+ int oboe_debug_log_to_stream(FILE *newStream);
142
+
143
+ /**
144
+ * If we're logging to a stream, flush it.
145
+ *
146
+ * @return Zero on success; otherwise an error code (normally from errno).
147
+ */
148
+ int oboe_debug_log_flush();
149
+
150
+ /**
151
+ * Set the default logger to write to the specified file.
152
+ *
153
+ * A NULL or empty path name will disable the default logger.
154
+ *
155
+ * If the file exists then it will be opened in append mode.
156
+ *
157
+ * @param pathname The path name of the
158
+ * @return Zero on success; otherwise an error code (normally from errno).
159
+ */
160
+ int oboe_debug_log_to_file(const char *pathname);
161
+
162
+ /**
163
+ * Add a logger that takes messages up to a given logging detail level.
164
+ *
165
+ * This adds the logger to a chain in order of the logging level. Log messages
166
+ * are passed to each logger down the chain until the remaining loggers only
167
+ * accept messages of a lower detail level.
168
+ *
169
+ * @return Zero on success, one if re-registered with the new logging level, and
170
+ * otherwise a negative value to indicate an error.
171
+ */
172
+ int oboe_debug_log_add(OboeDebugLoggerFcn newLogger, void *context, int logLevel);
173
+
174
+ /**
175
+ * Remove a logger.
176
+ *
177
+ * Remove the logger from the message handling chain.
178
+ *
179
+ * @return Zero on success, one if it was not found, and otherwise a negative
180
+ * value to indicate an error.
181
+ */
182
+ int oboe_debug_log_remove(OboeDebugLoggerFcn oldLogger, void *context);
183
+
184
+ /*
185
+ * Log the application's Oboe configuration.
186
+ *
187
+ * We use this to get a reasonable standard format between apps.
188
+ *
189
+ * @param module An OBOE_MODULE_* module identifier. Use zero for undefined.
190
+ * @param app_name Either NULL or a pointer to a string containing a name for
191
+ * the application - will prefix the log entry. Useful when multiple
192
+ * apps log to the same destination.
193
+ * @param trace_mode A string identifying the configured tracing mode, one of:
194
+ * "enabled", "disabled", "unset", or "undef" (for invalid values)
195
+ * Use the oboe_tracing_mode_to_string() function to convert from
196
+ * numeric values.
197
+ * @param sample_rate The configured sampling rate: -1 for unset or a
198
+ * integer fraction of 1000000.
199
+ * @param reporter_type String identifying the type of reporter configured:
200
+ * One of 'udp' (the default), 'ssl', or 'file'.
201
+ * @param reporter_args The string of comma-separated key=value settings
202
+ * used to initialize the reporter.
203
+ * @param extra: Either NULL or a pointer to a string to be appended to
204
+ * the log message and designed to include a few other
205
+ * configuration parameters of interest.
206
+ */
207
+ #if OBOE_DEBUG_LEVEL >= OBOE_DEBUG_INFO
208
+ # define OBOE_DEBUG_LOG_CONFIG_EX(module, app_name, trace_mode, sample_rate, reporter_type, reporter_args, extra) \
209
+ { \
210
+ oboe_debug_logger(module, OBOE_DEBUG_INFO, __FILE__, __LINE__, \
211
+ "%s Oboe config: tracing=%s, sampling=%d, reporter=('%s', '%s') %s", \
212
+ (app_name == NULL ? "" : app_name), \
213
+ trace_mode, \
214
+ sample_rate, \
215
+ (reporter_type == NULL ? "?" : reporter_type), \
216
+ (reporter_args == NULL ? "?" : reporter_args), \
217
+ (extra == NULL ? "" : extra)); \
218
+ }
219
+ #else
220
+ # define OBOE_DEBUG_LOG_CONFIG_EX(module, app_name, trace_mode, sample_rate, reporter_type, reporter_args, extra) {}
221
+ #endif
222
+
223
+ /**
224
+ * Log a fatal error.
225
+ */
226
+ #if OBOE_DEBUG_LEVEL >= OBOE_DEBUG_FATAL
227
+ # define OBOE_DEBUG_LOG_FATAL_EX(module, ...) \
228
+ { \
229
+ oboe_debug_logger(module, OBOE_DEBUG_FATAL, __FILE__, __LINE__, __VA_ARGS__); \
230
+ }
231
+ #else
232
+ # define OBOE_DEBUG_LOG_FATAL_EX(module, ...) {}
233
+ #endif
234
+
235
+ /**
236
+ * Log a recoverable error.
237
+ *
238
+ * Each message is limited in the number of times that it will be reported at the
239
+ * ERROR level after which it will be logged at the debug MEDIUM level.
240
+ */
241
+ #if OBOE_DEBUG_LEVEL >= OBOE_DEBUG_ERROR
242
+ # define OBOE_DEBUG_LOG_ERROR_EX(module, ...) \
243
+ { \
244
+ static int usage_counter = 0; \
245
+ int loglev = (++usage_counter <= MAX_DEBUG_MSG_COUNT ? OBOE_DEBUG_ERROR : OBOE_DEBUG_MEDIUM); \
246
+ oboe_debug_logger(module, loglev, __FILE__, __LINE__, __VA_ARGS__); \
247
+ }
248
+ #else
249
+ # define OBOE_DEBUG_LOG_ERROR_EX(module, ...) {}
250
+ #endif
251
+
252
+ /**
253
+ * Log a warning.
254
+ *
255
+ * Each message is limited in the number of times that it will be reported at the
256
+ * WARNING level after which it will be logged at the debug MEDIUM level.
257
+ */
258
+ #if OBOE_DEBUG_LEVEL >= OBOE_DEBUG_WARNING
259
+ # define OBOE_DEBUG_LOG_WARNING_EX(module, ...) \
260
+ { \
261
+ static int usage_counter = 0; \
262
+ int loglev = (++usage_counter <= MAX_DEBUG_MSG_COUNT ? OBOE_DEBUG_WARNING : OBOE_DEBUG_MEDIUM); \
263
+ oboe_debug_logger(module, loglev, __FILE__, __LINE__, __VA_ARGS__); \
264
+ }
265
+ #else
266
+ # define OBOE_DEBUG_LOG_WARNING_EX(module, ...) {}
267
+ #endif
268
+
269
+ /**
270
+ * Log an informative message.
271
+ *
272
+ * Each message is limited in the number of times that it will be reported at the
273
+ * INFO level after which it will be logged at the debug MEDIUM level.
274
+ */
275
+ #if OBOE_DEBUG_LEVEL >= OBOE_DEBUG_INFO
276
+ # define OBOE_DEBUG_LOG_INFO_EX(module, ...) \
277
+ { \
278
+ static int usage_counter = 0; \
279
+ int loglev = (++usage_counter <= MAX_DEBUG_MSG_COUNT ? OBOE_DEBUG_INFO : OBOE_DEBUG_MEDIUM); \
280
+ oboe_debug_logger(module, loglev, __FILE__, __LINE__, __VA_ARGS__); \
281
+ }
282
+ #else
283
+ # define OBOE_DEBUG_LOG_INFO_EX(module, ...) {}
284
+ #endif
285
+
286
+ /**
287
+ * Log a low-detail diagnostic message.
288
+ */
289
+ #if OBOE_DEBUG_LEVEL >= OBOE_DEBUG_LOW
290
+ # define OBOE_DEBUG_LOG_LOW_EX(module, ...) \
291
+ { \
292
+ oboe_debug_logger(module, OBOE_DEBUG_LOW, __FILE__, __LINE__, __VA_ARGS__); \
293
+ }
294
+ #else
295
+ # define OBOE_DEBUG_LOG_LOW_EX(module, ...) {}
296
+ #endif
297
+
298
+ /**
299
+ * Log a medium-detail diagnostic message.
300
+ */
301
+ #if OBOE_DEBUG_LEVEL >= OBOE_DEBUG_MEDIUM
302
+ # define OBOE_DEBUG_LOG_MEDIUM_EX(module, ...) \
303
+ { \
304
+ oboe_debug_logger(module, OBOE_DEBUG_MEDIUM, __FILE__, __LINE__, __VA_ARGS__); \
305
+ }
306
+ #else
307
+ # define OBOE_DEBUG_LOG_MEDIUM_EX(module, ...) {}
308
+ #endif
309
+
310
+ /**
311
+ * Log a high-detail diagnostic message.
312
+ */
313
+ #if OBOE_DEBUG_LEVEL >= OBOE_DEBUG_HIGH
314
+ # define OBOE_DEBUG_LOG_HIGH_EX(module, ...) \
315
+ { \
316
+ oboe_debug_logger(module, OBOE_DEBUG_HIGH, __FILE__, __LINE__, __VA_ARGS__); \
317
+ }
318
+ #else
319
+ # define OBOE_DEBUG_LOG_HIGH_EX(module, ...) {}
320
+ #endif
321
+
55
322
  #ifdef __cplusplus
56
323
  } // extern "C"
57
324
  #endif