appoptics_apm 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +43 -0
  3. data/.dockerignore +5 -0
  4. data/.gitignore +23 -0
  5. data/.rubocop.yml +5 -0
  6. data/.travis.yml +82 -0
  7. data/CHANGELOG.md +769 -0
  8. data/CONFIG.md +33 -0
  9. data/Dockerfile +41 -0
  10. data/Dockerfile_test +66 -0
  11. data/Gemfile +41 -0
  12. data/LICENSE +193 -0
  13. data/README.md +351 -0
  14. data/Rakefile +202 -0
  15. data/Vagrantfile +67 -0
  16. data/appoptics_apm.gemspec +55 -0
  17. data/build_gems.sh +15 -0
  18. data/docker-compose.yml +73 -0
  19. data/examples/DNT.md +35 -0
  20. data/examples/carrying_context.rb +220 -0
  21. data/examples/instrumenting_metal_controller.rb +8 -0
  22. data/examples/puma_on_heroku_config.rb +17 -0
  23. data/examples/tracing_async_threads.rb +124 -0
  24. data/examples/tracing_background_jobs.rb +53 -0
  25. data/examples/tracing_forked_processes.rb +99 -0
  26. data/examples/unicorn_on_heroku_config.rb +28 -0
  27. data/ext/oboe_metal/extconf.rb +54 -0
  28. data/ext/oboe_metal/lib/.keep +0 -0
  29. data/ext/oboe_metal/lib/liboboe-1.0.so.0.0.0 +0 -0
  30. data/ext/oboe_metal/noop/noop.c +7 -0
  31. data/ext/oboe_metal/src/VERSION +1 -0
  32. data/ext/oboe_metal/src/bson/bson.h +221 -0
  33. data/ext/oboe_metal/src/bson/platform_hacks.h +91 -0
  34. data/ext/oboe_metal/src/oboe.h +883 -0
  35. data/ext/oboe_metal/src/oboe.hpp +793 -0
  36. data/ext/oboe_metal/src/oboe_debug.h +50 -0
  37. data/ext/oboe_metal/src/oboe_wrap.cxx +6088 -0
  38. data/ext/oboe_metal/tests/test.rb +11 -0
  39. data/gemfiles/delayed_job.gemfile +36 -0
  40. data/gemfiles/frameworks.gemfile +44 -0
  41. data/gemfiles/instrumentation_mocked.gemfile +29 -0
  42. data/gemfiles/libraries.gemfile +85 -0
  43. data/gemfiles/rails23.gemfile +39 -0
  44. data/gemfiles/rails30.gemfile +42 -0
  45. data/gemfiles/rails31.gemfile +44 -0
  46. data/gemfiles/rails32.gemfile +54 -0
  47. data/gemfiles/rails40.gemfile +27 -0
  48. data/gemfiles/rails41.gemfile +27 -0
  49. data/gemfiles/rails42.gemfile +35 -0
  50. data/gemfiles/rails50.gemfile +44 -0
  51. data/gemfiles/rails51.gemfile +44 -0
  52. data/get_version.rb +5 -0
  53. data/init.rb +4 -0
  54. data/lib/appoptics_apm/api/layerinit.rb +39 -0
  55. data/lib/appoptics_apm/api/logging.rb +359 -0
  56. data/lib/appoptics_apm/api/memcache.rb +34 -0
  57. data/lib/appoptics_apm/api/profiling.rb +201 -0
  58. data/lib/appoptics_apm/api/tracing.rb +152 -0
  59. data/lib/appoptics_apm/api/util.rb +128 -0
  60. data/lib/appoptics_apm/api.rb +18 -0
  61. data/lib/appoptics_apm/base.rb +252 -0
  62. data/lib/appoptics_apm/config.rb +281 -0
  63. data/lib/appoptics_apm/frameworks/grape.rb +93 -0
  64. data/lib/appoptics_apm/frameworks/padrino/templates.rb +58 -0
  65. data/lib/appoptics_apm/frameworks/padrino.rb +52 -0
  66. data/lib/appoptics_apm/frameworks/rails/inst/action_controller.rb +106 -0
  67. data/lib/appoptics_apm/frameworks/rails/inst/action_controller2.rb +61 -0
  68. data/lib/appoptics_apm/frameworks/rails/inst/action_controller3.rb +58 -0
  69. data/lib/appoptics_apm/frameworks/rails/inst/action_controller4.rb +48 -0
  70. data/lib/appoptics_apm/frameworks/rails/inst/action_controller5.rb +50 -0
  71. data/lib/appoptics_apm/frameworks/rails/inst/action_controller_api.rb +50 -0
  72. data/lib/appoptics_apm/frameworks/rails/inst/action_view.rb +58 -0
  73. data/lib/appoptics_apm/frameworks/rails/inst/action_view_2x.rb +56 -0
  74. data/lib/appoptics_apm/frameworks/rails/inst/action_view_30.rb +50 -0
  75. data/lib/appoptics_apm/frameworks/rails/inst/active_record.rb +27 -0
  76. data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/mysql.rb +43 -0
  77. data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/mysql2.rb +28 -0
  78. data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/postgresql.rb +30 -0
  79. data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/utils.rb +120 -0
  80. data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/utils5x.rb +101 -0
  81. data/lib/appoptics_apm/frameworks/rails.rb +116 -0
  82. data/lib/appoptics_apm/frameworks/sinatra/templates.rb +56 -0
  83. data/lib/appoptics_apm/frameworks/sinatra.rb +71 -0
  84. data/lib/appoptics_apm/inst/bunny-client.rb +148 -0
  85. data/lib/appoptics_apm/inst/bunny-consumer.rb +92 -0
  86. data/lib/appoptics_apm/inst/curb.rb +329 -0
  87. data/lib/appoptics_apm/inst/dalli.rb +85 -0
  88. data/lib/appoptics_apm/inst/delayed_job.rb +92 -0
  89. data/lib/appoptics_apm/inst/em-http-request.rb +105 -0
  90. data/lib/appoptics_apm/inst/excon.rb +130 -0
  91. data/lib/appoptics_apm/inst/faraday.rb +77 -0
  92. data/lib/appoptics_apm/inst/http.rb +83 -0
  93. data/lib/appoptics_apm/inst/httpclient.rb +176 -0
  94. data/lib/appoptics_apm/inst/memcache.rb +102 -0
  95. data/lib/appoptics_apm/inst/memcached.rb +94 -0
  96. data/lib/appoptics_apm/inst/mongo.rb +242 -0
  97. data/lib/appoptics_apm/inst/mongo2.rb +225 -0
  98. data/lib/appoptics_apm/inst/moped.rb +466 -0
  99. data/lib/appoptics_apm/inst/rack.rb +146 -0
  100. data/lib/appoptics_apm/inst/redis.rb +275 -0
  101. data/lib/appoptics_apm/inst/resque.rb +151 -0
  102. data/lib/appoptics_apm/inst/rest-client.rb +50 -0
  103. data/lib/appoptics_apm/inst/sequel.rb +178 -0
  104. data/lib/appoptics_apm/inst/sidekiq-client.rb +53 -0
  105. data/lib/appoptics_apm/inst/sidekiq-worker.rb +67 -0
  106. data/lib/appoptics_apm/inst/twitter-cassandra.rb +294 -0
  107. data/lib/appoptics_apm/inst/typhoeus.rb +113 -0
  108. data/lib/appoptics_apm/instrumentation.rb +22 -0
  109. data/lib/appoptics_apm/legacy_method_profiling.rb +97 -0
  110. data/lib/appoptics_apm/loading.rb +66 -0
  111. data/lib/appoptics_apm/logger.rb +41 -0
  112. data/lib/appoptics_apm/method_profiling.rb +33 -0
  113. data/lib/appoptics_apm/ruby.rb +35 -0
  114. data/lib/appoptics_apm/support.rb +135 -0
  115. data/lib/appoptics_apm/test.rb +94 -0
  116. data/lib/appoptics_apm/thread_local.rb +26 -0
  117. data/lib/appoptics_apm/util.rb +312 -0
  118. data/lib/appoptics_apm/version.rb +15 -0
  119. data/lib/appoptics_apm/xtrace.rb +103 -0
  120. data/lib/appoptics_apm.rb +72 -0
  121. data/lib/joboe_metal.rb +214 -0
  122. data/lib/oboe/README +2 -0
  123. data/lib/oboe/backward_compatibility.rb +80 -0
  124. data/lib/oboe/inst/rack.rb +11 -0
  125. data/lib/oboe.rb +7 -0
  126. data/lib/oboe_metal.rb +187 -0
  127. data/lib/rails/generators/appoptics_apm/install_generator.rb +45 -0
  128. data/lib/rails/generators/appoptics_apm/templates/appoptics_apm_initializer.rb +222 -0
  129. data/ruby_setup.sh +47 -0
  130. data/run_docker_build_gem_upload_to_packagecloud.sh +20 -0
  131. data/run_tests_docker.rb +32 -0
  132. data/test/benchmark/README.md +65 -0
  133. data/test/benchmark/logging_bench.rb +54 -0
  134. data/test/benchmark/with_libraries_gemfile/bunny_bench.rb +69 -0
  135. data/test/benchmark/with_rails5x_gemfile/action_controller5x_bench.rb +43 -0
  136. data/test/frameworks/apps/grape_nested.rb +33 -0
  137. data/test/frameworks/apps/grape_simple.rb +80 -0
  138. data/test/frameworks/apps/padrino_simple.rb +80 -0
  139. data/test/frameworks/apps/sinatra_simple.rb +55 -0
  140. data/test/frameworks/grape_test.rb +286 -0
  141. data/test/frameworks/padrino_test.rb +222 -0
  142. data/test/frameworks/rails3x_test.rb +554 -0
  143. data/test/frameworks/rails4x_test.rb +570 -0
  144. data/test/frameworks/rails5x_api_test.rb +210 -0
  145. data/test/frameworks/rails5x_test.rb +376 -0
  146. data/test/frameworks/rails_shared_tests.rb +172 -0
  147. data/test/frameworks/sinatra_test.rb +140 -0
  148. data/test/instrumentation/bunny_client_test.rb +276 -0
  149. data/test/instrumentation/bunny_consumer_test.rb +204 -0
  150. data/test/instrumentation/curb_test.rb +398 -0
  151. data/test/instrumentation/dalli_test.rb +177 -0
  152. data/test/instrumentation/em_http_request_test.rb +89 -0
  153. data/test/instrumentation/excon_test.rb +231 -0
  154. data/test/instrumentation/faraday_test.rb +228 -0
  155. data/test/instrumentation/http_test.rb +143 -0
  156. data/test/instrumentation/httpclient_test.rb +320 -0
  157. data/test/instrumentation/memcache_test.rb +260 -0
  158. data/test/instrumentation/memcached_test.rb +229 -0
  159. data/test/instrumentation/mongo_v1_test.rb +479 -0
  160. data/test/instrumentation/mongo_v2_index_test.rb +124 -0
  161. data/test/instrumentation/mongo_v2_test.rb +584 -0
  162. data/test/instrumentation/mongo_v2_view_test.rb +435 -0
  163. data/test/instrumentation/moped_test.rb +517 -0
  164. data/test/instrumentation/rack_test.rb +165 -0
  165. data/test/instrumentation/redis_hashes_test.rb +268 -0
  166. data/test/instrumentation/redis_keys_test.rb +321 -0
  167. data/test/instrumentation/redis_lists_test.rb +310 -0
  168. data/test/instrumentation/redis_misc_test.rb +163 -0
  169. data/test/instrumentation/redis_sets_test.rb +296 -0
  170. data/test/instrumentation/redis_sortedsets_test.rb +328 -0
  171. data/test/instrumentation/redis_strings_test.rb +349 -0
  172. data/test/instrumentation/resque_test.rb +185 -0
  173. data/test/instrumentation/rest-client_test.rb +288 -0
  174. data/test/instrumentation/sequel_mysql2_test.rb +353 -0
  175. data/test/instrumentation/sequel_mysql_test.rb +334 -0
  176. data/test/instrumentation/sequel_pg_test.rb +336 -0
  177. data/test/instrumentation/sidekiq-client_test.rb +159 -0
  178. data/test/instrumentation/sidekiq-worker_test.rb +180 -0
  179. data/test/instrumentation/twitter-cassandra_test.rb +424 -0
  180. data/test/instrumentation/typhoeus_test.rb +284 -0
  181. data/test/jobs/delayed_job/db_worker_job.rb +29 -0
  182. data/test/jobs/delayed_job/error_worker_job.rb +10 -0
  183. data/test/jobs/delayed_job/remote_call_worker_job.rb +20 -0
  184. data/test/jobs/resque/db_worker_job.rb +29 -0
  185. data/test/jobs/resque/error_worker_job.rb +10 -0
  186. data/test/jobs/resque/remote_call_worker_job.rb +20 -0
  187. data/test/jobs/sidekiq/db_worker_job.rb +29 -0
  188. data/test/jobs/sidekiq/error_worker_job.rb +10 -0
  189. data/test/jobs/sidekiq/remote_call_worker_job.rb +20 -0
  190. data/test/minitest_helper.rb +276 -0
  191. data/test/mocked/curb_mocked_test.rb +311 -0
  192. data/test/mocked/excon_mocked_test.rb +166 -0
  193. data/test/mocked/faraday_mocked_test.rb +93 -0
  194. data/test/mocked/http_mocked_test.rb +129 -0
  195. data/test/mocked/httpclient_mocked_test.rb +245 -0
  196. data/test/mocked/rest_client_mocked_test.rb +103 -0
  197. data/test/mocked/typhoeus_mocked_test.rb +192 -0
  198. data/test/models/widget.rb +36 -0
  199. data/test/profiling/legacy_method_profiling_test.rb +201 -0
  200. data/test/profiling/method_profiling_test.rb +631 -0
  201. data/test/queues/delayed_job-client_test.rb +95 -0
  202. data/test/queues/delayed_job-worker_test.rb +91 -0
  203. data/test/reporter/reporter_test.rb +14 -0
  204. data/test/servers/delayed_job.rb +107 -0
  205. data/test/servers/rackapp_8101.rb +29 -0
  206. data/test/servers/rails3x_8140.rb +96 -0
  207. data/test/servers/rails4x_8140.rb +96 -0
  208. data/test/servers/rails5x_8140.rb +95 -0
  209. data/test/servers/rails5x_api_8150.rb +78 -0
  210. data/test/servers/sidekiq.rb +29 -0
  211. data/test/servers/sidekiq.yml +7 -0
  212. data/test/servers/sidekiq_initializer.rb +25 -0
  213. data/test/settings +0 -0
  214. data/test/support/auto_tracing_test.rb +50 -0
  215. data/test/support/backcompat_test.rb +276 -0
  216. data/test/support/config_test.rb +149 -0
  217. data/test/support/dnt_test.rb +98 -0
  218. data/test/support/init_report_test.rb +25 -0
  219. data/test/support/liboboe_settings_test.rb +110 -0
  220. data/test/support/logging_test.rb +130 -0
  221. data/test/support/noop_test.rb +88 -0
  222. data/test/support/sql_sanitize_test.rb +55 -0
  223. data/test/support/tracing_mode_test.rb +33 -0
  224. data/test/support/tvalias_test.rb +15 -0
  225. data/test/support/xtrace_test.rb +41 -0
  226. metadata +475 -0
@@ -0,0 +1,883 @@
1
+ /**
2
+ * @file oboe.h
3
+ *
4
+ * API header for AppOptics' Oboe application tracing library for use with AppOptics.
5
+ *
6
+ * @package Oboe
7
+ * @author AppOptics
8
+ * @copyright Copyright (c) 2016, SolarWinds LLC
9
+ * @license
10
+ * @link https://appoptics.com
11
+ **/
12
+
13
+ #ifndef LIBOBOE_H
14
+ #define LIBOBOE_H
15
+
16
+
17
+ #ifdef __cplusplus
18
+ extern "C" {
19
+ #endif
20
+
21
+ #include <stdio.h>
22
+ #include <sys/types.h>
23
+ #include <sys/time.h>
24
+ #include <inttypes.h>
25
+ #if defined _WIN32
26
+ #include <unistd.h> // On Windows ssize_t definition was put in this header.
27
+ #endif
28
+ #include "bson/bson.h"
29
+ #include "oboe_debug.h"
30
+
31
+ /** Compile time debug logging detail level - cannot log more detailed than this. */
32
+ #define OBOE_DEBUG_LEVEL OBOE_DEBUG_HIGH
33
+
34
+ /** Limit for number of messages at specified level before demoting to debug MEDIUM. */
35
+ #define MAX_DEBUG_MSG_COUNT 1
36
+
37
+ /**
38
+ * Default configuration settings update interval in seconds.
39
+ *
40
+ * Borrowed from the Tracelyzer's oboe.h.
41
+ */
42
+ #define OBOE_DEFAULT_SETTINGS_INTERVAL 30
43
+
44
+ /**
45
+ * Default interval to check for timed out settings records in seconds
46
+ */
47
+ #define OBOE_DEFAULT_TIMEOUT_CHECK_INTERVAL 10
48
+
49
+ /**
50
+ * Default heartbeat status update interval in seconds.
51
+ */
52
+ #define OBOE_DEFAULT_HEARTBEAT_INTERVAL 60
53
+
54
+ /**
55
+ * Default throughput metrics update interval in seconds
56
+ */
57
+ #define OBOE_DEFAULT_COUNTER_INTERVAL_SEC 30
58
+
59
+ /**
60
+ * Default maximum number of transaction names to track when aggregating metric and histogram data by individual service transaction
61
+ */
62
+ #define OBOE_DEFAULT_MAX_TRANSACTIONS 200
63
+
64
+ /**
65
+ * Default maximum number of custom metrics per flash interval
66
+ */
67
+ #define OBOE_DEFAULT_MAX_CUSTOM_METRICS 500
68
+
69
+ /**
70
+ * Default keepalive interval in seconds.
71
+ *
72
+ * A keepalive message will be sent after communications are idle for this interval.
73
+ */
74
+ #define OBOE_DEFAULT_KEEPALIVE_INTERVAL 20
75
+
76
+ #define OBOE_SAMPLE_RESOLUTION 1000000
77
+
78
+ #define OBOE_MAX_TASK_ID_LEN 20
79
+ #define OBOE_MAX_OP_ID_LEN 8
80
+ #define OBOE_MAX_METADATA_PACK_LEN 512
81
+
82
+ #define XTR_CURRENT_VERSION 2
83
+
84
+ #define XTR_FLAGS_NOT_SAMPLED 0x0
85
+ #define XTR_FLAGS_SAMPLED 0x1
86
+
87
+ #define XTR_UDP_PORT 7831
88
+
89
+ #define OBOE_REPORTER_PROTOCOL_FILE "file"
90
+ #define OBOE_REPORTER_PROTOCOL_UDP "udp"
91
+ #define OBOE_REPORTER_PROTOCOL_SSL "ssl"
92
+ #define OBOE_REPORTER_PROTOCOL_DEFAULT OBOE_REPORTER_PROTOCOL_UDP
93
+
94
+ /** Maximum reasonable length of an arguments string for configuring a reporter. */
95
+ #define OBOE_REPORTER_ARGS_SIZE 4000
96
+
97
+ #ifdef _WIN32
98
+ /// SRv1 bitwise value mask for the RUM_ENABLE flag.
99
+ #define SETTINGS_RUM_ENABLE_MASK 0x00000001
100
+ #endif
101
+
102
+ #ifndef HOST_NAME_MAX
103
+ #define HOST_NAME_MAX 256
104
+ #endif
105
+
106
+ // structs
107
+
108
+ typedef struct oboe_ids {
109
+ uint8_t task_id[OBOE_MAX_TASK_ID_LEN];
110
+ uint8_t op_id[OBOE_MAX_OP_ID_LEN];
111
+ } oboe_ids_t;
112
+
113
+ typedef struct oboe_metadata {
114
+ uint8_t version;
115
+ oboe_ids_t ids;
116
+ size_t task_len;
117
+ size_t op_len;
118
+ uint8_t flags;
119
+ #ifdef _FUTURE_PLANS_
120
+ /* Can't add this without breaking the ABI, but someday... */
121
+ int auto_delete;
122
+ #endif /* _FUTURE_PLANS_ */
123
+ } oboe_metadata_t;
124
+
125
+ typedef struct oboe_event {
126
+ oboe_metadata_t metadata;
127
+ bson_buffer bbuf;
128
+ char * bb_str;
129
+ #ifdef _FUTURE_PLANS_
130
+ /* Can't add this without breaking the ABI, but someday... */
131
+ int auto_delete;
132
+ #endif /* _FUTURE_PLANS_ */
133
+ } oboe_event_t;
134
+
135
+ typedef struct oboe_metric_tag {
136
+ char *key;
137
+ char *value;
138
+ } oboe_metric_tag_t;
139
+
140
+
141
+ // oboe_metadata
142
+
143
+ #ifdef _FUTURE_PLANS_
144
+ oboe_metadata_t *oboe_metadata_new();
145
+ #endif /* _FUTURE_PLANS_ */
146
+ int oboe_metadata_init (oboe_metadata_t *);
147
+ int oboe_metadata_destroy (oboe_metadata_t *);
148
+
149
+ int oboe_metadata_is_valid (const oboe_metadata_t *);
150
+
151
+ void oboe_metadata_copy (oboe_metadata_t *, const oboe_metadata_t *);
152
+
153
+ void oboe_metadata_random (oboe_metadata_t *);
154
+
155
+ int oboe_metadata_set_lengths (oboe_metadata_t *, size_t, size_t);
156
+ int oboe_metadata_create_event (const oboe_metadata_t *, oboe_event_t *);
157
+
158
+ int oboe_metadata_tostr (const oboe_metadata_t *, char *, size_t);
159
+ int oboe_metadata_fromstr (oboe_metadata_t *, const char *, size_t);
160
+
161
+ int oboe_metadata_is_sampled(oboe_metadata_t *md);
162
+
163
+ // oboe_event
164
+
165
+ #ifdef _FUTURE_PLANS_
166
+ oboe_event_t *oboe_event_new(const oboe_metadata_t *);
167
+ #endif /* _FUTURE_PLANS_ */
168
+ int oboe_event_init (oboe_event_t *, const oboe_metadata_t *);
169
+ int oboe_event_destroy (oboe_event_t *);
170
+
171
+ int oboe_event_add_info (oboe_event_t *, const char *, const char *);
172
+ int oboe_event_add_info_binary (oboe_event_t *, const char *, const char *, size_t);
173
+ int oboe_event_add_info_int64 (oboe_event_t *, const char *, const int64_t);
174
+ int oboe_event_add_info_double (oboe_event_t *, const char *, const double);
175
+ int oboe_event_add_info_bool (oboe_event_t *, const char *, const int);
176
+ int oboe_event_add_info_fmt (oboe_event_t *, const char *key, const char *fmt, ...);
177
+ int oboe_event_add_info_bson (oboe_event_t *, const char *key, const bson *val);
178
+ int oboe_event_add_edge (oboe_event_t *, const oboe_metadata_t *);
179
+ int oboe_event_add_edge_fromstr(oboe_event_t *, const char *, size_t);
180
+
181
+ /**
182
+ * Send event message using the default reporter.
183
+ *
184
+ * @param channel the channel to send out this message (OBOE_SEND_EVENT or OBOE_SEND_STATUS)
185
+ * @param evt The event message.
186
+ * @param md The X-Trace metadata.
187
+ * @return Length of message sent in bytes on success; otherwise -1.
188
+ */
189
+ int oboe_event_send(int channel, oboe_event_t *evt, oboe_metadata_t *md);
190
+
191
+
192
+ // oboe_context
193
+
194
+ oboe_metadata_t *oboe_context_get();
195
+ void oboe_context_set(oboe_metadata_t *);
196
+ int oboe_context_set_fromstr(const char *, size_t);
197
+
198
+ void oboe_context_clear();
199
+
200
+ int oboe_context_is_valid();
201
+
202
+ int oboe_context_is_sampled();
203
+
204
+ // oboe_reporter
205
+
206
+ struct oboe_reporter;
207
+
208
+ /* TODO: Move struct oboe_reporter to private header. */
209
+ typedef ssize_t (*reporter_send)(void *, int, const char *, size_t);
210
+ typedef int (*reporter_send_span)(void *, const char *, const char *, const int64_t, const int, const char *, const int);
211
+ typedef int (*reporter_add_custom_metric)(void *, const char *, const double, const int, const int, const int, const oboe_metric_tag_t*, const size_t);
212
+ typedef int (*reporter_destroy)(void *);
213
+ typedef struct oboe_reporter {
214
+ void * descriptor; /*!< Reporter's context. */
215
+ reporter_send send; /*!< Send a trace event message. */
216
+ reporter_send_span sendSpan;
217
+ reporter_add_custom_metric addCustomMetric;
218
+ reporter_destroy destroy; /*!< Destroy the reporter - release all resources. */
219
+ } oboe_reporter_t;
220
+
221
+ int oboe_reporter_udp_init (oboe_reporter_t *, const char *, const char *); /* DEPRECATE - Use oboe_init_reporter() */
222
+ int oboe_reporter_udp_init_str(oboe_reporter_t *, const char *); /* DEPRECATE - Use oboe_init_reporter() */
223
+ int oboe_reporter_file_init (oboe_reporter_t *, const char *); /* DEPRECATE - Use oboe_init_reporter() */
224
+ int oboe_reporter_file_init_str(oboe_reporter_t *, const char *); /* DEPRECATE - Use oboe_init_reporter() */
225
+ int oboe_reporter_ssl_init (oboe_reporter_t *, const char *); /* DEPRECATE - Use oboe_init_reporter() */
226
+
227
+
228
+ /**
229
+ * Initialize a reporter structure for use with the specified protocol.
230
+ *
231
+ * @param protocol One of OBOE_REPORTER_PROTOCOL_FILE, OBOE_REPORTER_PROTOCOL_UDP,
232
+ * or OBOE_REPORTER_PROTOCOL_SSL.
233
+ * @param args A configuration string for the specified protocol (protocol dependent syntax).
234
+ * @return Zero on success; otherwise -1.
235
+ */
236
+ int oboe_reporter_init (const char *protocol, const char *args); /* DEPRECATE - Use oboe_init_reporter() */
237
+
238
+ /**
239
+ * Check if the reporter is ready to send.
240
+ *
241
+ * The concept of 'ready' is depends on the specific reporter being used.
242
+ *
243
+ * @param rep The reporter context (optional).
244
+ * @return Non-zero if the reporter is ready to send.
245
+ */
246
+ int oboe_reporter_is_ready(oboe_reporter_t *rep); /* DEPRECATE: Use oboe_is_ready() */
247
+
248
+ /**
249
+ * Release any resources held by the reporter context.
250
+ *
251
+ * @param rep Pointer to a reporter context structure.
252
+ * @return Zero on success; otherwise non-zero to indicate an error.
253
+ */
254
+ int oboe_reporter_destroy(oboe_reporter_t *rep); /* DEPRECATE: Use oboe_shutdown() */
255
+
256
+ /**
257
+ * Disconnect or shut down the Oboe reporter, but allow it to be reconnected.
258
+ *
259
+ * @param rep Pointer to the active reporter object.
260
+ */
261
+ void oboe_disconnect(oboe_reporter_t *rep); /* DEPRECATE: Use oboe_reporter_disconnect() */
262
+
263
+ /**
264
+ * Reconnect or restart the Oboe reporter.
265
+ *
266
+ * @param rep Pointer to the active reporter object.
267
+ */
268
+ void oboe_reconnect(oboe_reporter_t *rep); /* DEPRECATE: Use oboe_reporter_reconnect() */
269
+
270
+ ssize_t oboe_reporter_udp_send(void *desc, const char *data, size_t len); /* DEPRECATE - Use oboe_event_send() */
271
+
272
+
273
+ /* Oboe initialization and reporter management */
274
+
275
+ /**
276
+ * Initialize the Oboe subsystems.
277
+ *
278
+ * One of oboe_init_log and oboe_init should be called before any other
279
+ * oboe_* functions. Use oboe_init_log to specify the log level and log
280
+ * file name when initializing the oboe subsystem. However, in order
281
+ * to make the library easier to work with, checks are in place so that it
282
+ * will be called by any of the other functions that depend on it.
283
+ *
284
+ * Besides initializing the oboe library, this will also initialize a
285
+ * reporter based on the values of environment variables, configuration
286
+ * file options, and whether a tracelyzer is installed.
287
+ *
288
+ * @param access_key Client access key
289
+ * @param hostname_alias optional hostname alias
290
+ * @param log_level Level at which log messages will be written to log file
291
+ * @param log_file_path file name including path for log file
292
+ * @return true if initialization succeeded, false otherwise
293
+ */
294
+ int oboe_init_log(const char *access_key, const char *hostname_alias, int log_level, const char* log_file_path);
295
+
296
+ /**
297
+ * Initialize the Oboe subsystems.
298
+ *
299
+ * See oboe_init_log description above for more information. (Note: Either
300
+ * oboe_init or oboe_init_log should be called to initialize the oboe subsystem).
301
+ *
302
+ * @param access_key Client access key
303
+ * @param hostname_alias optional hostname alias
304
+ * @return true if initialization succeeded, false otherwise
305
+ */
306
+ int oboe_init(const char *access_key, const char *hostname_alias);
307
+
308
+ /**
309
+ * Initialize the Oboe subsytems using a specific reporter configuration.
310
+ *
311
+ * This should be called before any other oboe_* functions butm may also be
312
+ * used to change or re-initialize the current reporter. To reconnect the
313
+ * reporter use oboe_disconnect() and oboe_reconnect() instead.
314
+ *
315
+ * @param protocol One of OBOE_REPORTER_PROTOCOL_FILE, OBOE_REPORTER_PROTOCOL_UDP,
316
+ * or OBOE_REPORTER_PROTOCOL_SSL.
317
+ * @param args A configuration string for the specified protocol (protocol dependent syntax).
318
+ * @return Zero on success; otherwise an error code.
319
+ */
320
+ int oboe_init_reporter(const char *protocol, const char *args);
321
+
322
+ /**
323
+ * Disconnect or shut down the Oboe reporter, but allow it to be reconnect()ed.
324
+ */
325
+ void oboe_reporter_disconnect(); /* TODO: Need implementation. */
326
+
327
+ /**
328
+ * Reconnect or restart the Oboe reporter.
329
+ */
330
+ void oboe_reporter_reconnect(); /* TODO: Need implementation. */
331
+
332
+ /**
333
+ * Check if the Oboe is ready to send.
334
+ *
335
+ * The concept of 'ready' is depends on the specific reporter being used.
336
+ *
337
+ * @return Non-zero if the reporter is ready to send.
338
+ */
339
+ int oboe_is_ready(); /* TODO: Need implementation. */
340
+
341
+ /**
342
+ * Send a raw message using the current reporter.
343
+ *
344
+ * Use oboe_event_send() unless you are handling all the details of constructing
345
+ * the messages for a valid trace.
346
+ *
347
+ * @param channel the channel to send out this message (OBOE_SEND_EVENT or OBOE_SEND_STATUS)
348
+ * @param data A BSON-encoded event message.
349
+ * @param len The length of the message data in bytes.
350
+ * @return Length of message sent in bytes on success; otherwise -1.
351
+ */
352
+ int oboe_raw_send(int channel, const char *data, size_t len);
353
+
354
+ /**
355
+ * Shut down the Oboe subsystems.
356
+ *
357
+ * This may be called on exit in order to release any resources held by
358
+ * the Oboe library including any child threads.
359
+ */
360
+ void oboe_shutdown();
361
+
362
+
363
+ // Settings interface
364
+
365
+ #define OBOE_SETTINGS_VERSION 1
366
+ #define OBOE_SETTINGS_MAGIC_NUMBER 0x6f626f65
367
+ #define OBOE_SETTINGS_TYPE_SKIP 0
368
+ #define OBOE_SETTINGS_TYPE_STOP 1
369
+ #define OBOE_SETTINGS_TYPE_DEFAULT_SAMPLE_RATE 2
370
+ #define OBOE_SETTINGS_TYPE_LAYER_SAMPLE_RATE 3
371
+ #define OBOE_SETTINGS_TYPE_LAYER_APP_SAMPLE_RATE 4
372
+ #define OBOE_SETTINGS_TYPE_LAYER_HTTPHOST_SAMPLE_RATE 5
373
+ #define OBOE_SETTINGS_TYPE_CONFIG_STRING 6
374
+ #define OBOE_SETTINGS_TYPE_CONFIG_INT 7
375
+ #define OBOE_SETTINGS_FLAG_OK 0x0
376
+ #define OBOE_SETTINGS_FLAG_INVALID 0x1
377
+ #define OBOE_SETTINGS_FLAG_OVERRIDE 0x2
378
+ #define OBOE_SETTINGS_FLAG_SAMPLE_START 0x4
379
+ #define OBOE_SETTINGS_FLAG_SAMPLE_THROUGH 0x8
380
+ #define OBOE_SETTINGS_FLAG_SAMPLE_THROUGH_ALWAYS 0x10
381
+ #define OBOE_SETTINGS_FLAG_SAMPLE_AVW_ALWAYS 0x20
382
+ #define OBOE_SETTINGS_MAX_STRLEN 256
383
+
384
+ #define OBOE_SETTINGS_UNSET -1
385
+
386
+ // Value for "SampleSource" info key
387
+ // where was the sample rate specified? (oboe settings, config file, hard-coded default, etc)
388
+ #define OBOE_SAMPLE_RATE_SOURCE_FILE 1
389
+ #define OBOE_SAMPLE_RATE_SOURCE_DEFAULT 2
390
+ #define OBOE_SAMPLE_RATE_SOURCE_OBOE 3
391
+ #define OBOE_SAMPLE_RATE_SOURCE_LAST_OBOE 4
392
+ #define OBOE_SAMPLE_RATE_SOURCE_DEFAULT_MISCONFIGURED 5
393
+ #define OBOE_SAMPLE_RATE_SOURCE_OBOE_DEFAULT 6
394
+ #define OBOE_SAMPLE_RATE_SOURCE_CUSTOM 7
395
+
396
+ #define OBOE_SAMPLE_RESOLUTION 1000000
397
+
398
+ // Used to convert to settings flags:
399
+ #define OBOE_TRACE_NEVER 0
400
+ #define OBOE_TRACE_ALWAYS 1
401
+
402
+ #if defined _WIN32
403
+ #pragma pack(push, 1)
404
+ #endif
405
+
406
+ #define TOKEN_BUCKET_CAPACITY_DEFAULT 16 // bucket capacity (how many tokens fit into the bucket)
407
+ #define TOKEN_BUCKET_RATE_PER_SECOND_DEFAULT 8 // rate per second (number of tokens per second)
408
+
409
+ #define OBOE_SEND_EVENT 0
410
+ #define OBOE_SEND_STATUS 1
411
+
412
+ typedef struct {
413
+ uint32_t magic;
414
+ uint32_t timestamp;
415
+ uint16_t type;
416
+ uint16_t flags;
417
+ uint32_t value;
418
+ uint32_t ttl;
419
+ uint32_t _pad;
420
+ char layer[OBOE_SETTINGS_MAX_STRLEN];
421
+ double bucket_capacity;
422
+ double bucket_rate_per_sec;
423
+ } oboe_settings_t;
424
+
425
+ typedef struct {
426
+ float available;
427
+ double capacity;
428
+ double rate_per_usec; // time is usecs from gettimeofday
429
+ struct timeval last_check;
430
+ } token_bucket_t;
431
+
432
+
433
+ typedef struct {
434
+ char name[OBOE_SETTINGS_MAX_STRLEN];
435
+ token_bucket_t bucket;
436
+ volatile uint32_t request_count; // all the requests that came through this layer
437
+ volatile uint32_t exhaustion_count; // # of times the token bucket limiting caused a trace to not occur
438
+ volatile uint32_t trace_count; // # of traces that were sent (includes "always", "through", or "AVW" traces)
439
+ volatile uint32_t sample_count; // # of traces that caused a random coin-flip (not "through" traces)
440
+ volatile uint32_t through_count; // # of through traces
441
+ volatile uint32_t through_ignored_count; // # of new requests, that are rejected due to start_always_flag == 0
442
+ // that have through_always_flag == 1
443
+ volatile uint32_t last_used_sample_rate;
444
+ volatile uint32_t last_used_sample_source;
445
+ } entry_layer_t;
446
+
447
+ // Current settings configuration:
448
+ typedef struct {
449
+ int tracing_mode; // pushed from server, override from config file
450
+ int sample_rate; // pushed from server, override from config file
451
+ oboe_settings_t *settings; // cached settings, updated by tracelyzer (init to NULL)
452
+ int last_auto_sample_rate; // stores last known automatic sampling rate
453
+ uint16_t last_auto_flags; // stores last known flags associated with above
454
+ uint32_t last_auto_timestamp; // timestamp from last *settings lookup
455
+ uint32_t last_refresh; // last refresh time
456
+ entry_layer_t *entry_layer;
457
+ } oboe_settings_cfg_t;
458
+
459
+ int oboe_settings_init_local();
460
+ oboe_settings_t* oboe_settings_get(uint16_t type, const char* layer, const char* arg);
461
+ oboe_settings_t* oboe_settings_get_layer_tracing_mode(const char* layer);
462
+ oboe_settings_t* oboe_settings_get_layer_sample_rate(const char* layer);
463
+ uint32_t oboe_settings_get_latest_timestamp(const char* layer);
464
+ int oboe_settings_get_value(oboe_settings_t *s, int *outval, unsigned short *outflags, uint32_t *outtimestamp);
465
+ entry_layer_t* oboe_settings_entry_layer_get(const char* name);
466
+
467
+ oboe_settings_cfg_t* oboe_settings_cfg_get();
468
+ void oboe_settings_cfg_init(oboe_settings_cfg_t *cfg);
469
+
470
+ void oboe_settings_set(int sample_rate, int tracing_mode);
471
+ void oboe_settings_rate_set(int sample_rate);
472
+ void oboe_settings_mode_set(int tracing_mode);
473
+
474
+ int oboe_rand_get_value();
475
+
476
+ /**
477
+ * Convert a tracing mode to a printable string.
478
+ */
479
+ const char *oboe_tracing_mode_to_string(int tracing_mode);
480
+
481
+ /**
482
+ * Check if sampling is enabled.
483
+ *
484
+ * @param cfg Optional pointer to the settings configuration for the current
485
+ * thread, as an optimization to avoid retrieving it. May be NULL.
486
+ * @return Non-zero if sampling is now enabled.
487
+ */
488
+ int oboe_sample_is_enabled(oboe_settings_cfg_t *cfg);
489
+
490
+ /**
491
+ * Check if this request should be sampled.
492
+ *
493
+ * Checks for sample rate flags and settings for the specified layer, considers
494
+ * the current tracing mode and any special features in the X-Trace
495
+ * headers, and, if appropriate, rolls the virtual dice to
496
+ * decide if this request should be sampled.
497
+ *
498
+ * This is designed to be called once per layer per request.
499
+ *
500
+ * @param layer Layer name as used in oboe_settings_t.layer (may be NULL to use default settings)
501
+ * @param xtrace X-Trace ID string from an HTTP request or higher layer (NULL or empty string if not present).
502
+ * @param sample_rate_out The sample rate used to check if this request should be sampled
503
+ * (output - may be zero if not used).
504
+ * @param sample_source_out The OBOE_SAMPLE_RATE_SOURCE used to check if this request
505
+ * should be sampled (output - may be zero if not used).
506
+ * @return Non-zero if the given layer should be sampled.
507
+ */
508
+ int oboe_sample_layer(
509
+ const char *layer,
510
+ const char *xtrace,
511
+ int *sample_rate_out,
512
+ int *sample_source_out
513
+ );
514
+
515
+ /**
516
+ * Same as oboe_sample_layer() but accepting custom sample rate and custom tracing mode
517
+ *
518
+ * @param layer Layer name as used in oboe_settings_t.layer (may be NULL to use default settings)
519
+ * @param xtrace X-Trace ID string from an HTTP request or higher layer (NULL or empty string if not present).
520
+ * @param custom_sample_rate a custom sample rate only used for this request (OBOE_SETTINGS_UNSET won't override)
521
+ * @param custom_tracing_mode a custom tracing mode only used for this request (OBOE_SETTINGS_UNSET won't override)
522
+ * @param sample_rate_out The sample rate used to check if this request should be sampled
523
+ * (output - may be zero if not used).
524
+ * @param sample_source_out The OBOE_SAMPLE_RATE_SOURCE used to check if this request
525
+ * should be sampled (output - may be zero if not used).
526
+ */
527
+ int oboe_sample_layer_custom(
528
+ const char *layer,
529
+ const char *in_xtrace,
530
+ int custom_sample_rate,
531
+ int custom_tracing_mode,
532
+ int *sample_rate_out,
533
+ int *sample_source_out
534
+ );
535
+
536
+ /* Oboe configuration interface. */
537
+
538
+ /**
539
+ * Check if the Oboe library is compatible with a given version.revision.
540
+ *
541
+ * This will succeed if the library is at least as recent as specified and if no
542
+ * definitions have been removed since that revision.
543
+ *
544
+ * @param version The library's version number which increments every time the API changes.
545
+ * @param revision The revision of the current version of the library.
546
+ * @return Non-zero if the Oboe library is considered compatible with the specified revision.
547
+ */
548
+ extern int oboe_config_check_version(int version, int revision);
549
+
550
+ /**
551
+ * Get the Oboe library version number.
552
+ *
553
+ * This number increments whenever the API is changed.
554
+ *
555
+ * @return The library's version number or -1 if the version is not known.
556
+ */
557
+ extern int oboe_config_get_version();
558
+
559
+ /**
560
+ * Prototype for a logger call-back function.
561
+ *
562
+ * A logging function of this form can be added to the logger chain using
563
+ * oboe_debug_log_add().
564
+ *
565
+ * @param context The context pointer that was registered in the call to
566
+ * oboe_debug_log_add(). Use it to pass the pointer-to-self for
567
+ * objects (ie. "this" in C++) or just a structure in C, May be
568
+ * NULL.
569
+ * @param module The module identifier as passed to oboe_debug_logger().
570
+ * @param level The diagnostic detail level as passed to oboe_debug_logger().
571
+ * @param source_name Name of the source file as passed to oboe_debug_logger().
572
+ * @param source_lineno Number of the line in the source file where message is
573
+ * logged from as passed to oboe_debug_logger().
574
+ * @param msg The formatted message produced from the format string and its
575
+ * arguments as passed to oboe_debug_logger().
576
+ */
577
+ typedef void (*OboeDebugLoggerFcn)(void *context, int module, int level, const char *source_name, int source_lineno, const char *msg);
578
+
579
+ /**
580
+ * Get a printable name for a diagnostics logging level.
581
+ */
582
+ extern const char *oboe_debug_log_level_name(int level);
583
+
584
+ /**
585
+ * Get a printable name for a diagnostics logging module identifier.
586
+ */
587
+ extern const char *oboe_debug_module_name(int module);
588
+
589
+ /**
590
+ * Get the maximum logging detail level for a module or for all modules.
591
+ *
592
+ * This level applies to the stderr logger only. Added loggers get all messages
593
+ * below their registed detail level and need to do their own module-specific
594
+ * filtering.
595
+ *
596
+ * @param module One of the OBOE_MODULE_* values. Use OBOE_MODULE_ALL (-1) to
597
+ * get the overall maximum detail level.
598
+ * @return Maximum detail level value for module (or overall) where zero is the
599
+ * lowest and higher values generate more detailed log messages.
600
+ */
601
+ extern int oboe_debug_log_level_get(int module);
602
+
603
+ /**
604
+ * Set the maximum logging detail level for a module or for all modules.
605
+ *
606
+ * This level applies to the stderr logger only. Added loggers get all messages
607
+ * below their registered detail level and need to do their own module-specific
608
+ * filtering.
609
+ *
610
+ * @param module One of the OBOE_MODULE_* values. Use OBOE_MODULE_ALL to set
611
+ * the overall maximum detail level.
612
+ * @param newLevel Maximum detail level value where zero is the lowest and higher
613
+ * values generate more detailed log messages.
614
+ */
615
+ extern void oboe_debug_log_level_set(int module, int newLevel);
616
+
617
+ /**
618
+ * Set the output stream for the default logger.
619
+ *
620
+ * @param newStream A valid, open FILE* stream or NULL to disable the default logger.
621
+ * @return Zero on success; otherwise an error code (normally from errno).
622
+ */
623
+ extern int oboe_debug_log_to_stream(FILE *newStream);
624
+
625
+ /**
626
+ * If we're logging to a stream, flush it.
627
+ *
628
+ * @return Zero on success; otherwise an error code (normally from errno).
629
+ */
630
+ extern int oboe_debug_log_flush();
631
+
632
+ /**
633
+ * Set the default logger to write to the specified file.
634
+ *
635
+ * A NULL or empty path name will disable the default logger.
636
+ *
637
+ * If the file exists then it will be opened in append mode.
638
+ *
639
+ * @param pathname The path name of the
640
+ * @return Zero on success; otherwise an error code (normally from errno).
641
+ */
642
+ extern int oboe_debug_log_to_file(const char *pathname);
643
+
644
+ /**
645
+ * Add a logger that takes messages up to a given logging detail level.
646
+ *
647
+ * This adds the logger to a chain in order of the logging level. Log messages
648
+ * are passed to each logger down the chain until the remaining loggers only
649
+ * accept messages of a lower detail level.
650
+ *
651
+ * @return Zero on success, one if re-registered with the new logging level, and
652
+ * otherwise a negative value to indicate an error.
653
+ */
654
+ extern int oboe_debug_log_add(OboeDebugLoggerFcn newLogger, void *context, int logLevel);
655
+
656
+ /**
657
+ * Remove a logger.
658
+ *
659
+ * Remove the logger from the message handling chain.
660
+ *
661
+ * @return Zero on success, one if it was not found, and otherwise a negative
662
+ * value to indicate an error.
663
+ */
664
+ extern int oboe_debug_log_remove(OboeDebugLoggerFcn oldLogger, void *context);
665
+
666
+ /*
667
+ * Log the application's Oboe configuration.
668
+ *
669
+ * We use this to get a reasonable standard format between apps.
670
+ *
671
+ * @param module An OBOE_MODULE_* module identifier. Use zero for undefined.
672
+ * @param app_name Either NULL or a pointer to a string containing a name for
673
+ * the application - will prefix the log entry. Useful when multiple
674
+ * apps log to the same destination.
675
+ * @param trace_mode A string identifying the configured tracing mode, one of:
676
+ * "never", "always", "never", "unset", or "undef" (for invalid values)
677
+ * Use the oboe_tracing_mode_to_string() function to convert from
678
+ * numeric values.
679
+ * @param sample_rate The configured sampling rate: -1 for unset or a
680
+ * integer fraction of 1000000.
681
+ * @param reporter_type String identifying the type of reporter configured:
682
+ * One of 'udp' (the default), 'ssl', or 'file'.
683
+ * @param reporter_args The string of comma-separated key=value settings
684
+ * used to initialize the reporter.
685
+ * @param extra: Either NULL or a pointer to a string to be appended to
686
+ * the log message and designed to include a few other
687
+ * configuration parameters of interest.
688
+ */
689
+ #if OBOE_DEBUG_LEVEL >= OBOE_DEBUG_INFO
690
+ # define OBOE_DEBUG_LOG_CONFIG(module, app_name, trace_mode, sample_rate, reporter_type, reporter_args, extra) \
691
+ { \
692
+ oboe_debug_logger(module, OBOE_DEBUG_INFO, __FILE__, __LINE__, \
693
+ "%s Oboe config: tracing=%s, sampling=%d, reporter=('%s', '%s') %s", \
694
+ (app_name == NULL ? "" : app_name), \
695
+ trace_mode, \
696
+ sample_rate, \
697
+ (reporter_type == NULL ? "?" : reporter_type), \
698
+ (reporter_args == NULL ? "?" : reporter_args), \
699
+ (extra == NULL ? "" : extra)); \
700
+ }
701
+ #else
702
+ # define OBOE_DEBUG_LOG_CONFIG(module, app_name, trace_mode, sample_rate, reporter_type, reporter_args, extra) {}
703
+ #endif
704
+
705
+ /**
706
+ * Log a fatal error.
707
+ */
708
+ #if OBOE_DEBUG_LEVEL >= OBOE_DEBUG_FATAL
709
+ # define OBOE_DEBUG_LOG_FATAL(module, ...) \
710
+ { \
711
+ oboe_debug_logger(module, OBOE_DEBUG_FATAL, __FILE__, __LINE__, __VA_ARGS__); \
712
+ }
713
+ #else
714
+ # define OBOE_DEBUG_LOG_FATAL(module, format_string, ...) {}
715
+ #endif
716
+
717
+ /**
718
+ * Log a recoverable error.
719
+ *
720
+ * Each message is limited in the number of times that it will be reported at the
721
+ * ERROR level after which it will be logged at the debug MEDIUM level.
722
+ */
723
+ #if OBOE_DEBUG_LEVEL >= OBOE_DEBUG_ERROR
724
+ # define OBOE_DEBUG_LOG_ERROR(module, ...) \
725
+ { \
726
+ static int usage_counter = 0; \
727
+ int loglev = (++usage_counter <= MAX_DEBUG_MSG_COUNT ? OBOE_DEBUG_ERROR : OBOE_DEBUG_MEDIUM); \
728
+ oboe_debug_logger(module, loglev, __FILE__, __LINE__, __VA_ARGS__); \
729
+ }
730
+ #else
731
+ # define OBOE_DEBUG_LOG_ERROR(module, format_string, ...) {}
732
+ #endif
733
+
734
+ /**
735
+ * Log a warning.
736
+ *
737
+ * Each message is limited in the number of times that it will be reported at the
738
+ * WARNING level after which it will be logged at the debug MEDIUM level.
739
+ */
740
+ #if OBOE_DEBUG_LEVEL >= OBOE_DEBUG_WARNING
741
+ # define OBOE_DEBUG_LOG_WARNING(module, ...) \
742
+ { \
743
+ static int usage_counter = 0; \
744
+ int loglev = (++usage_counter <= MAX_DEBUG_MSG_COUNT ? OBOE_DEBUG_WARNING : OBOE_DEBUG_MEDIUM); \
745
+ oboe_debug_logger(module, loglev, __FILE__, __LINE__, __VA_ARGS__); \
746
+ }
747
+ #else
748
+ # define OBOE_DEBUG_LOG_WARNING(module, format_string,...) {}
749
+ #endif
750
+
751
+ /**
752
+ * Log an informative message.
753
+ *
754
+ * Each message is limited in the number of times that it will be reported at the
755
+ * INFO level after which it will be logged at the debug MEDIUM level.
756
+ */
757
+ #if OBOE_DEBUG_LEVEL >= OBOE_DEBUG_INFO
758
+ # define OBOE_DEBUG_LOG_INFO(module, ...) \
759
+ { \
760
+ static int usage_counter = 0; \
761
+ int loglev = (++usage_counter <= MAX_DEBUG_MSG_COUNT ? OBOE_DEBUG_INFO : OBOE_DEBUG_MEDIUM); \
762
+ oboe_debug_logger(module, loglev, __FILE__, __LINE__, __VA_ARGS__); \
763
+ }
764
+ #else
765
+ # define OBOE_DEBUG_LOG_INFO(module, format_string, ...) {}
766
+ #endif
767
+
768
+ /**
769
+ * Log a low-detail diagnostic message.
770
+ */
771
+ #if OBOE_DEBUG_LEVEL >= OBOE_DEBUG_LOW
772
+ # define OBOE_DEBUG_LOG_LOW(module, ...) \
773
+ { \
774
+ oboe_debug_logger(module, OBOE_DEBUG_LOW, __FILE__, __LINE__, __VA_ARGS__); \
775
+ }
776
+ #else
777
+ # define OBOE_DEBUG_LOG_LOW(module, format_string, ...) {}
778
+ #endif
779
+
780
+ /**
781
+ * Log a medium-detail diagnostic message.
782
+ */
783
+ #if OBOE_DEBUG_LEVEL >= OBOE_DEBUG_MEDIUM
784
+ # define OBOE_DEBUG_LOG_MEDIUM(module, ...) \
785
+ { \
786
+ oboe_debug_logger(module, OBOE_DEBUG_MEDIUM, __FILE__, __LINE__, __VA_ARGS__); \
787
+ }
788
+ #else
789
+ # define OBOE_DEBUG_LOG_MEDIUM(module, ...) {}
790
+ #endif
791
+
792
+ /**
793
+ * Log a high-detail diagnostic message.
794
+ */
795
+ #if OBOE_DEBUG_LEVEL >= OBOE_DEBUG_HIGH
796
+ # define OBOE_DEBUG_LOG_HIGH(module, ...) \
797
+ { \
798
+ oboe_debug_logger(module, OBOE_DEBUG_HIGH, __FILE__, __LINE__, __VA_ARGS__); \
799
+ }
800
+ #else
801
+ # define OBOE_DEBUG_LOG_HIGH(module, format_string, ...) {}
802
+ #endif
803
+
804
+
805
+ /**
806
+ * Low-level diagnostics logging function.
807
+ *
808
+ * This is normally used only by the OBOE_DEBUG_LOG_* function macros and not used directly.
809
+ *
810
+ * This function may be adapted to format and route diagnostic log messages as desired.
811
+ *
812
+ * @param module One of the numeric module identifiers defined in debug.h - used to control logging detail by module.
813
+ * @param level Diagnostic detail level of this message - used to control logging volume by detail level.
814
+ * @param source_name Name of the source file, if available, or another useful name, or NULL.
815
+ * @param source_lineno Number of the line in the source file where message is logged from, if available, or zero.
816
+ * @param format A C language printf format specification string.
817
+ * @param args A variable argument list in VA_ARG format containing arguments for each argument specifier in the format.
818
+ */
819
+ void oboe_debug_logger(int module, int level, const char *source_name, int source_lineno, const char *format, ...);
820
+
821
+ /**
822
+ * Get the Oboe library revision number.
823
+ *
824
+ * This is the revision of the current version which is updated whenever
825
+ * compatible changes are made to the API/ABI (ie. additions).
826
+ *
827
+ * @return The library's revision number or -1 if not known.
828
+ */
829
+ extern int oboe_config_get_revision();
830
+
831
+ /*
832
+ * Get the Oboe library version as a string.
833
+ *
834
+ * Returns the complete VERSION string or null
835
+ */
836
+ const char* oboe_config_get_version_string();
837
+
838
+ /*
839
+ * Generate UUID for RUM
840
+ *
841
+ * @param access_key User Access Key
842
+ * @param uuid_length Size of the UUID to generate
843
+ * @param digest Pointer to array where the digest value gets stored
844
+ * @param dlen Number of bytes of data stored
845
+ */
846
+ void oboe_rum_create_digest(const char* access_key, unsigned int uuid_length, unsigned char* digest, unsigned int *dlen);
847
+
848
+ // Span reporting
849
+
850
+ /*
851
+ * generate a new HTTP span
852
+ *
853
+ * @param transaction transaction name (will be NULL or empty if url given)
854
+ * @param url the raw url which will be processed and used as transaction name (if transaction is NULL or empty)
855
+ * @param duration the duration of the span in micro seconds (usec)
856
+ * @param status HTTP status code (e.g. 200, 500, ...)
857
+ * @param method HTTP method (e.g. GET, POST, ...)
858
+ * @param error boolean flag whether this transaction contains an error (1) or not (0)
859
+ */
860
+ void oboe_http_span(const char *transaction, const char *url, const int64_t duration,
861
+ const int status, const char *method, const int has_error);
862
+
863
+ /*
864
+ * helper functions to mark the start/end of a span
865
+ *
866
+ * @return monotonic time in micro seconds (usec) since some unspecified starting point
867
+ */
868
+ int64_t oboe_span_start();
869
+ int64_t oboe_span_stop();
870
+
871
+ // Custom metrics
872
+
873
+ int oboe_custom_metric_summary(const char *name, const double value, const int count, const int host_tag,
874
+ const oboe_metric_tag_t tags[], const size_t tags_count);
875
+
876
+ int oboe_custom_metric_increment(const char *name, const int count, const int host_tag,
877
+ const oboe_metric_tag_t tags[], const size_t tags_count);
878
+
879
+ #ifdef __cplusplus
880
+ } // extern "C"
881
+ #endif
882
+
883
+ #endif // LIBOBOE_H