solarwinds_apm 5.1.9 → 6.0.0.preV1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (150) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +0 -1
  3. data/ext/oboe_metal/extconf.rb +19 -23
  4. data/ext/oboe_metal/lib/liboboe-1.0-aarch64.so.sha256 +1 -1
  5. data/ext/oboe_metal/lib/liboboe-1.0-alpine-aarch64.so.sha256 +1 -1
  6. data/ext/oboe_metal/lib/liboboe-1.0-alpine-x86_64.so.sha256 +1 -1
  7. data/ext/oboe_metal/lib/liboboe-1.0-x86_64.so.sha256 +1 -1
  8. data/ext/oboe_metal/src/VERSION +1 -1
  9. data/ext/oboe_metal/src/oboe_debug.h +1 -0
  10. data/lib/oboe_metal.rb +116 -80
  11. data/lib/rails/generators/solarwinds_apm/install_generator.rb +1 -2
  12. data/lib/rails/generators/solarwinds_apm/templates/solarwinds_apm_initializer.rb +44 -260
  13. data/lib/solarwinds_apm/api/current_trace_info.rb +148 -0
  14. data/lib/solarwinds_apm/api/tracing.rb +30 -0
  15. data/lib/solarwinds_apm/api/transaction_name.rb +57 -0
  16. data/lib/solarwinds_apm/api.rb +8 -15
  17. data/lib/solarwinds_apm/base.rb +4 -131
  18. data/lib/solarwinds_apm/config.rb +128 -175
  19. data/lib/solarwinds_apm/constants.rb +32 -0
  20. data/lib/solarwinds_apm/logger.rb +1 -1
  21. data/lib/solarwinds_apm/noop/context.rb +2 -5
  22. data/lib/solarwinds_apm/noop/metadata.rb +1 -2
  23. data/lib/solarwinds_apm/noop/profiling.rb +3 -7
  24. data/lib/solarwinds_apm/oboe_init_options.rb +71 -33
  25. data/lib/solarwinds_apm/opentelemetry/solarwinds_exporter.rb +204 -0
  26. data/lib/solarwinds_apm/opentelemetry/solarwinds_processor.rb +163 -0
  27. data/lib/solarwinds_apm/opentelemetry/solarwinds_propagator.rb +92 -0
  28. data/lib/solarwinds_apm/opentelemetry/solarwinds_response_propagator.rb +72 -0
  29. data/lib/solarwinds_apm/opentelemetry/solarwinds_sampler.rb +330 -0
  30. data/lib/solarwinds_apm/opentelemetry.rb +8 -0
  31. data/lib/solarwinds_apm/otel_config.rb +161 -0
  32. data/lib/solarwinds_apm/{inst → support}/logger_formatter.rb +5 -6
  33. data/lib/solarwinds_apm/{inst → support}/logging_log_event.rb +3 -6
  34. data/lib/solarwinds_apm/{inst → support}/lumberjack_formatter.rb +1 -4
  35. data/lib/solarwinds_apm/support/oboe_tracing_mode.rb +27 -0
  36. data/lib/solarwinds_apm/support/swomarginalia/LICENSE +20 -0
  37. data/lib/solarwinds_apm/support/swomarginalia/README.md +41 -0
  38. data/lib/solarwinds_apm/support/swomarginalia/comment.rb +205 -0
  39. data/lib/solarwinds_apm/support/swomarginalia/load_swomarginalia.rb +48 -0
  40. data/lib/solarwinds_apm/support/swomarginalia/railtie.rb +22 -0
  41. data/lib/solarwinds_apm/support/swomarginalia/swomarginalia.rb +86 -0
  42. data/lib/solarwinds_apm/support/transaction_cache.rb +24 -0
  43. data/lib/solarwinds_apm/support/transaction_settings.rb +26 -209
  44. data/lib/solarwinds_apm/support/transformer.rb +56 -0
  45. data/lib/solarwinds_apm/support/txn_name_manager.rb +25 -0
  46. data/lib/solarwinds_apm/support/x_trace_options.rb +42 -26
  47. data/lib/solarwinds_apm/support.rb +33 -10
  48. data/lib/solarwinds_apm/support_report.rb +10 -32
  49. data/lib/solarwinds_apm/thread_local.rb +1 -1
  50. data/lib/solarwinds_apm/version.rb +4 -4
  51. data/lib/solarwinds_apm.rb +31 -26
  52. metadata +76 -121
  53. data/.dockerignore +0 -5
  54. data/.gitignore +0 -58
  55. data/.rubocop.yml +0 -29
  56. data/.whitesource +0 -22
  57. data/.yardopts +0 -7
  58. data/CHANGELOG-appoptics.md +0 -766
  59. data/CHANGELOG.md +0 -82
  60. data/CONFIG.md +0 -31
  61. data/Gemfile +0 -15
  62. data/README.md +0 -385
  63. data/bin/solarwinds_apm_config +0 -15
  64. data/examples/prepend.rb +0 -13
  65. data/examples/sdk_examples.rb +0 -158
  66. data/ext/oboe_metal/README.md +0 -69
  67. data/ext/oboe_metal/extconf_local.rb +0 -75
  68. data/ext/oboe_metal/lib/.keep +0 -0
  69. data/ext/oboe_metal/noop/noop.c +0 -8
  70. data/ext/oboe_metal/src/README.md +0 -6
  71. data/ext/oboe_metal/src/frames.cc +0 -247
  72. data/ext/oboe_metal/src/frames.h +0 -40
  73. data/ext/oboe_metal/src/logging.cc +0 -97
  74. data/ext/oboe_metal/src/logging.h +0 -34
  75. data/ext/oboe_metal/src/profiling.cc +0 -435
  76. data/ext/oboe_metal/src/profiling.h +0 -78
  77. data/ext/oboe_metal/test/CMakeLists.txt +0 -53
  78. data/ext/oboe_metal/test/FindGMock.cmake +0 -43
  79. data/ext/oboe_metal/test/README.md +0 -56
  80. data/ext/oboe_metal/test/frames_test.cc +0 -164
  81. data/ext/oboe_metal/test/profiling_test.cc +0 -93
  82. data/ext/oboe_metal/test/ruby_inc_dir.rb +0 -8
  83. data/ext/oboe_metal/test/ruby_prefix.rb +0 -8
  84. data/ext/oboe_metal/test/ruby_test_helper.rb +0 -67
  85. data/ext/oboe_metal/test/test.h +0 -11
  86. data/ext/oboe_metal/test/test_main.cc +0 -32
  87. data/init.rb +0 -4
  88. data/lib/solarwinds_apm/api/layerinit.rb +0 -41
  89. data/lib/solarwinds_apm/api/logging.rb +0 -356
  90. data/lib/solarwinds_apm/api/memcache.rb +0 -37
  91. data/lib/solarwinds_apm/api/metrics.rb +0 -63
  92. data/lib/solarwinds_apm/api/util.rb +0 -98
  93. data/lib/solarwinds_apm/frameworks/grape.rb +0 -96
  94. data/lib/solarwinds_apm/frameworks/padrino.rb +0 -78
  95. data/lib/solarwinds_apm/frameworks/rails/inst/action_controller.rb +0 -100
  96. data/lib/solarwinds_apm/frameworks/rails/inst/action_controller5.rb +0 -50
  97. data/lib/solarwinds_apm/frameworks/rails/inst/action_controller_api.rb +0 -50
  98. data/lib/solarwinds_apm/frameworks/rails/inst/action_view.rb +0 -88
  99. data/lib/solarwinds_apm/frameworks/rails/inst/active_record.rb +0 -26
  100. data/lib/solarwinds_apm/frameworks/rails/inst/connection_adapters/mysql2.rb +0 -29
  101. data/lib/solarwinds_apm/frameworks/rails/inst/connection_adapters/postgresql.rb +0 -22
  102. data/lib/solarwinds_apm/frameworks/rails/inst/connection_adapters/utils5x.rb +0 -103
  103. data/lib/solarwinds_apm/frameworks/rails/inst/logger_formatters.rb +0 -14
  104. data/lib/solarwinds_apm/frameworks/rails.rb +0 -100
  105. data/lib/solarwinds_apm/frameworks/sinatra.rb +0 -96
  106. data/lib/solarwinds_apm/inst/bunny-client.rb +0 -157
  107. data/lib/solarwinds_apm/inst/bunny-consumer.rb +0 -102
  108. data/lib/solarwinds_apm/inst/curb.rb +0 -289
  109. data/lib/solarwinds_apm/inst/dalli.rb +0 -89
  110. data/lib/solarwinds_apm/inst/delayed_job.rb +0 -100
  111. data/lib/solarwinds_apm/inst/excon.rb +0 -113
  112. data/lib/solarwinds_apm/inst/faraday.rb +0 -96
  113. data/lib/solarwinds_apm/inst/graphql.rb +0 -206
  114. data/lib/solarwinds_apm/inst/grpc_client.rb +0 -147
  115. data/lib/solarwinds_apm/inst/grpc_server.rb +0 -119
  116. data/lib/solarwinds_apm/inst/httpclient.rb +0 -182
  117. data/lib/solarwinds_apm/inst/memcached.rb +0 -86
  118. data/lib/solarwinds_apm/inst/mongo.rb +0 -246
  119. data/lib/solarwinds_apm/inst/mongo2.rb +0 -225
  120. data/lib/solarwinds_apm/inst/moped.rb +0 -466
  121. data/lib/solarwinds_apm/inst/net_http.rb +0 -60
  122. data/lib/solarwinds_apm/inst/rack.rb +0 -223
  123. data/lib/solarwinds_apm/inst/rack_cache.rb +0 -35
  124. data/lib/solarwinds_apm/inst/redis.rb +0 -280
  125. data/lib/solarwinds_apm/inst/redis_v4.rb +0 -273
  126. data/lib/solarwinds_apm/inst/resque.rb +0 -129
  127. data/lib/solarwinds_apm/inst/rest-client.rb +0 -43
  128. data/lib/solarwinds_apm/inst/sequel.rb +0 -241
  129. data/lib/solarwinds_apm/inst/sidekiq-client.rb +0 -63
  130. data/lib/solarwinds_apm/inst/sidekiq-worker.rb +0 -64
  131. data/lib/solarwinds_apm/inst/typhoeus.rb +0 -90
  132. data/lib/solarwinds_apm/instrumentation.rb +0 -22
  133. data/lib/solarwinds_apm/loading.rb +0 -65
  134. data/lib/solarwinds_apm/ruby.rb +0 -35
  135. data/lib/solarwinds_apm/sdk/current_trace_info.rb +0 -123
  136. data/lib/solarwinds_apm/sdk/custom_metrics.rb +0 -94
  137. data/lib/solarwinds_apm/sdk/logging.rb +0 -37
  138. data/lib/solarwinds_apm/sdk/trace_context_headers.rb +0 -69
  139. data/lib/solarwinds_apm/sdk/tracing.rb +0 -432
  140. data/lib/solarwinds_apm/support/profiling.rb +0 -25
  141. data/lib/solarwinds_apm/support/trace_context.rb +0 -53
  142. data/lib/solarwinds_apm/support/trace_state.rb +0 -69
  143. data/lib/solarwinds_apm/support/trace_string.rb +0 -89
  144. data/lib/solarwinds_apm/support/transaction_metrics.rb +0 -67
  145. data/lib/solarwinds_apm/test.rb +0 -165
  146. data/lib/solarwinds_apm/util.rb +0 -426
  147. data/log/.keep +0 -0
  148. data/log/postgresql/.keep +0 -0
  149. data/solarwinds_apm.gemspec +0 -55
  150. data/yardoc_frontpage.md +0 -24
@@ -1,356 +0,0 @@
1
- #--
2
- # Copyright (c) 2016 SolarWinds, LLC.
3
- # All rights reserved.
4
- #++
5
-
6
- # Make sure Set is loaded if possible.
7
- begin
8
- require 'set'
9
- rescue LoadError
10
- class Set; end # :nodoc:
11
- end
12
-
13
- module SolarWindsAPM
14
- module API
15
- ##
16
- # This modules provides the X-Trace logging facilities.
17
- #
18
- # These are the lower level methods, please see SolarWindsAPM::SDK
19
- # for the higher level methods
20
- #
21
- # If using these directly make sure to always match a start/end and entry/exit to
22
- # avoid broken traces.
23
- module Logging
24
- @@ints_or_nil = [Integer, Float, NilClass, String]
25
-
26
- ##
27
- # Public: Report an event in an active trace.
28
- #
29
- # ==== Arguments
30
- #
31
- # * +layer+ - The layer the reported event belongs to
32
- # * +label+ - The label for the reported event. See SDK documentation for reserved labels and usage.
33
- # * +kvs+ - A hash containing key/value pairs that will be reported along with this event (optional).
34
- # * +event+ - An event to be used instead of generating a new one (see also start_trace_with_target)
35
- #
36
- # ==== Example
37
- #
38
- # SolarWindsAPM::API.log('logical_layer', 'entry')
39
- # SolarWindsAPM::API.log('logical_layer', 'info', { :list_length => 20 })
40
- # SolarWindsAPM::API.log('logical_layer', 'exit')
41
- #
42
- # Returns nothing.
43
- def log(layer, label, kvs = {}, event = nil)
44
- return SolarWindsAPM::Context.toString unless SolarWindsAPM.tracing?
45
-
46
- event ||= SolarWindsAPM::Context.createEvent
47
- log_event(layer, label, event, kvs)
48
- end
49
-
50
- ##
51
- # Public: Report an exception.
52
- #
53
- # ==== Arguments
54
- #
55
- # * +layer+ - The layer the reported event belongs to
56
- # * +exception+ - The exception to report, responds to :message and :backtrace(optional)
57
- # * +kvs+ - Custom params if you want to log extra information
58
- #
59
- # ==== Example
60
- #
61
- # begin
62
- # my_iffy_method
63
- # rescue Exception => e
64
- # SolarWindsAPM::API.log_exception('rails', e, { user: user_id })
65
- # raise
66
- # end
67
- #
68
- # Returns nothing.
69
- def log_exception(layer, exception, kvs = {})
70
- return SolarWindsAPM::Context.toString if !SolarWindsAPM.tracing? || exception.instance_variable_get(:@exn_logged)
71
-
72
- unless exception
73
- SolarWindsAPM.logger.debug '[solarwinds_apm/debug] log_exception called with nil exception'
74
- return SolarWindsAPM::Context.toString
75
- end
76
-
77
- exception.message << exception.class.name if exception.message.length < 4
78
- kvs.merge!(:Spec => 'error',
79
- :ErrorClass => exception.class.name,
80
- :ErrorMsg => exception.message)
81
-
82
- if exception.respond_to?(:backtrace) && exception.backtrace
83
- kvs.merge!(:Backtrace => exception.backtrace.join("\r\n"))
84
- end
85
-
86
- exception.instance_variable_set(:@exn_logged, true)
87
- log(layer, :error, kvs)
88
- end
89
-
90
- ##
91
- # Public: Start a trace depending on TransactionSettings
92
- # or decide whether or not to start a trace, and report an entry event
93
- # appropriately.
94
- #
95
- # ==== Arguments
96
- #
97
- # * +layer+ - The layer the reported event belongs to
98
- # * +kvs+ - A hash containing key/value pairs that will be reported along with this event (optional).
99
- # * +headers+ - the request headers, they may contain w3c trace_context data
100
- # * +settings+ - An instance of TransactionSettings
101
- # * +url+ - String of the current url, it may be configured to be excluded from tracing
102
- #
103
- # ==== Example
104
- #
105
- # SolarWindsAPM::API.log_start(:layer_name, { :id => @user.id })
106
- #
107
- # Returns a metadata string if we are tracing
108
- #
109
- def log_start(layer, kvs = {}, headers = {}, settings = nil, url = nil)
110
- return unless SolarWindsAPM.loaded
111
-
112
- # This is a bit ugly, but here is the best place to reset the layer_op thread local var.
113
- SolarWindsAPM.layer_op = nil
114
-
115
- settings ||= SolarWindsAPM::TransactionSettings.new(url, headers)
116
- SolarWindsAPM.trace_context.add_traceinfo(kvs)
117
- tracestring = SolarWindsAPM.trace_context.tracestring
118
-
119
- if settings.do_sample
120
- kvs[:SampleRate] = settings.rate
121
- kvs[:SampleSource] = settings.source
122
-
123
- SolarWindsAPM::TraceString.set_sampled(tracestring) if tracestring
124
- event = create_start_event(tracestring)
125
- log_event(layer, :entry, event, kvs)
126
- else
127
- create_nontracing_context(tracestring)
128
- SolarWindsAPM::Context.toString
129
- end
130
- end
131
-
132
- ##
133
- # Public: Report an exit event and potentially clear the tracing context.
134
- #
135
- # ==== Arguments
136
- #
137
- # * +layer+ - The layer the reported event belongs to
138
- # * +kvs+ - A hash containing key/value pairs that will be reported along with this event (optional).
139
- #
140
- # ==== Example
141
- #
142
- # SolarWindsAPM::API.log_end(:layer_name, { :id => @user.id })
143
- #
144
- # Returns a metadata string if we are tracing
145
- #
146
- def log_end(layer, kvs = {}, event = nil)
147
- return SolarWindsAPM::Context.toString unless SolarWindsAPM.tracing?
148
-
149
- event ||= SolarWindsAPM::Context.createEvent
150
- log_event(layer, :exit, event, kvs)
151
- ensure
152
- SolarWindsAPM::Context.clear
153
- SolarWindsAPM.trace_context = nil
154
- SolarWindsAPM.transaction_name = nil
155
- end
156
-
157
- ##
158
- # Public: Log an entry event
159
- #
160
- # A helper method to create and log an entry event
161
- #
162
- # ==== Arguments
163
- #
164
- # * +layer+ - The layer the reported event belongs to
165
- # * +kvs+ - A hash containing key/value pairs that will be reported along with this event (optional).
166
- # * +op+ - To identify the current operation being traced. Used to avoid double tracing recursive calls.
167
- #
168
- # ==== Example
169
- #
170
- # SolarWindsAPM::API.log_entry(:layer_name, { :id => @user.id })
171
- #
172
- # Returns a metadata string
173
- #
174
- def log_entry(layer, kvs = {}, op = nil)
175
- return SolarWindsAPM::Context.toString unless SolarWindsAPM.tracing?
176
-
177
- if op
178
- # check if re-entry but also add op to list for log_exit
179
- re_entry = SolarWindsAPM.layer_op&.last == op.to_sym
180
- SolarWindsAPM.layer_op = (SolarWindsAPM.layer_op || []) << op.to_sym
181
- return SolarWindsAPM::Context.toString if re_entry
182
- end
183
-
184
- event ||= SolarWindsAPM::Context.createEvent
185
- log_event(layer, :entry, event, kvs)
186
- end
187
-
188
- ##
189
- # Public: Log an info event
190
- #
191
- # A helper method to create and log an info event
192
- #
193
- # ==== Arguments
194
- #
195
- # * +layer+ - The layer the reported event belongs to
196
- # * +kvs+ - A hash containing key/value pairs that will be reported along with this event (optional).
197
- #
198
- # ==== Example
199
- #
200
- # SolarWindsAPM::API.log_info(:layer_name, { :id => @user.id })
201
- #
202
- # Returns a metadata string if we are tracing
203
- #
204
- def log_info(layer, kvs = {})
205
- return SolarWindsAPM::Context.toString unless SolarWindsAPM.tracing?
206
-
207
- kvs[:Spec] = 'info'
208
- log_event(layer, :info, SolarWindsAPM::Context.createEvent, kvs)
209
- end
210
-
211
- ##
212
- # Public: Log an exit event
213
- #
214
- # A helper method to create and log an exit event
215
- #
216
- # ==== Arguments
217
- #
218
- # * +layer+ - The layer the reported event belongs to
219
- # * +kvs+ - A hash containing key/value pairs that will be reported along with this event (optional).
220
- # * +op+ - Used to avoid double tracing recursive calls, needs to be the same in +log_exit+ that corresponds to a
221
- # +log_entry+
222
- #
223
- # ==== Example
224
- #
225
- # SolarWindsAPM::API.log_exit(:layer_name, { :id => @user.id })
226
- #
227
- # Returns a metadata string if we are tracing
228
- def log_exit(layer, kvs = {}, op = nil)
229
- return SolarWindsAPM::Context.toString unless SolarWindsAPM.tracing?
230
-
231
- if op
232
- if SolarWindsAPM.layer_op&.last == op.to_sym
233
- SolarWindsAPM.layer_op.pop
234
- else
235
- SolarWindsAPM.logger.warn "[ruby/logging] op parameter of exit event doesn't correspond to an entry event op"
236
- end
237
- # check if the next op is the same, don't log event if so
238
- return SolarWindsAPM::Context.toString if SolarWindsAPM.layer_op&.last == op.to_sym
239
- end
240
-
241
- log_event(layer, :exit, SolarWindsAPM::Context.createEvent, kvs)
242
- end
243
-
244
- ##
245
- #:nodoc:
246
- # Internal: Reports agent init to the collector
247
- #
248
- # ==== Arguments
249
- #
250
- # * +layer+ - The layer the reported event belongs to
251
- # * +kvs+ - A hash containing key/value pairs that will be reported along with this event
252
- def log_init(layer = :rack, kvs = {})
253
- context = SolarWindsAPM::Metadata.makeRandom
254
- return SolarWindsAPM::Context.toString unless context.isValid
255
-
256
- event = context.createEvent
257
- event.addInfo(SW_APM_STR_LAYER, layer.to_s)
258
- event.addInfo(SW_APM_STR_LABEL, 'single')
259
- kvs.each do |k, v|
260
- event.addInfo(k, v.to_s)
261
- end
262
-
263
- SolarWindsAPM::Reporter.sendStatus(event, context)
264
- SolarWindsAPM::Context.toString
265
- end
266
-
267
- private
268
-
269
- ##
270
- #:nodoc:
271
- # @private
272
- # Internal: Report an event.
273
- #
274
- # ==== Arguments
275
- #
276
- # * +layer+ - The layer the reported event belongs to
277
- # * +label+ - The label for the reported event. See API documentation for reserved labels and usage.
278
- # * +event+ - The pre-existing SolarWindsAPM context event. See SolarWindsAPM::Context.createEvent
279
- # * +kvs+ - A hash containing key/value pairs that will be reported along with this event (optional).
280
- #
281
- # ==== Example
282
- #
283
- # entry = SolarWindsAPM::Context.createEvent
284
- # SolarWindsAPM::API.log_event(:layer_name, 'entry', entry_event, { :id => @user.id })
285
- #
286
- # exit_event = SolarWindsAPM::Context.createEvent
287
- # exit_event.addEdge(entry.getMetadata)
288
- # SolarWindsAPM::API.log_event(:layer_name, 'exit', exit_event, { :id => @user.id })
289
- #
290
- def log_event(layer, label, event, kvs = {})
291
- event.addInfo(SW_APM_STR_LAYER, layer.to_s.freeze) if layer
292
- event.addInfo(SW_APM_STR_LABEL, label.to_s.freeze)
293
-
294
- SolarWindsAPM.layer = layer.to_sym if label == :entry
295
- SolarWindsAPM.layer = nil if label == :exit
296
-
297
- kvs.each do |k, v|
298
- value = nil
299
-
300
- next unless valid_key? k
301
-
302
- if @@ints_or_nil.include?(v.class)
303
- value = v
304
- elsif v.class == Set
305
- value = v.to_a.to_s
306
- else
307
- value = v.to_s if v.respond_to?(:to_s)
308
- end
309
-
310
- begin
311
- event.addInfo(k.to_s, value)
312
- rescue ArgumentError => e
313
- SolarWindsAPM.logger.debug "[solarwinds_apm/debug] Couldn't add event KV: #{k} => #{v.class}"
314
- SolarWindsAPM.logger.debug "[solarwinds_apm/debug] #{e.message}"
315
- end
316
- end if !kvs.nil? && kvs.any?
317
-
318
- SolarWindsAPM::Reporter.sendReport(event)
319
- SolarWindsAPM::Context.toString
320
- end
321
-
322
- def create_start_event(tracestring = nil)
323
- if SolarWindsAPM::TraceString.sampled?(tracestring)
324
- md = SolarWindsAPM::Metadata.fromString(tracestring)
325
- SolarWindsAPM::Context.fromString(tracestring)
326
- md.createEvent
327
- else
328
- md = SolarWindsAPM::Metadata.makeRandom(true)
329
- SolarWindsAPM::Context.set(md)
330
- SolarWindsAPM::Event.startTrace(md)
331
- end
332
- end
333
-
334
- public
335
-
336
- def create_nontracing_context(tracestring)
337
- if SolarWindsAPM::TraceString.valid?(tracestring)
338
- # continue valid incoming tracestring
339
- # use it for current context, ensuring sample bit is not set
340
- SolarWindsAPM::TraceString.unset_sampled(tracestring)
341
- SolarWindsAPM::Context.fromString(tracestring)
342
- else
343
- # discard invalid incoming tracestring
344
- # create a new context, ensuring sample bit not set
345
- md = SolarWindsAPM::Metadata.makeRandom(false)
346
- SolarWindsAPM::Context.fromString(md.toString)
347
- end
348
- end
349
-
350
- # need to set the module context to public, otherwise the following `extends` will be private in api.rb
351
-
352
- public
353
-
354
- end
355
- end
356
- end
@@ -1,37 +0,0 @@
1
- #--
2
- # Copyright (c) 2016 SolarWinds, LLC.
3
- # All rights reserved.
4
- #++
5
-
6
- # TODO remove Memcache from API and into some Util module to be included in Modules that need
7
- # ____ these methods
8
- module SolarWindsAPM
9
- module API
10
- ##
11
- # Utility methods for the Memcache instrumentation
12
- # currently used by dalli and memcached
13
- module Memcache #:nodoc:
14
- MEMCACHE_OPS = %w(add append cas decr decrement delete fetch get incr increment prepend replace set)
15
-
16
- def memcache_hit?(result)
17
- result.nil? ? 0 : 1
18
- end
19
-
20
- def remote_host(key)
21
- return unless defined?(Lib.memcached_server_by_key) &&
22
- defined?(@struct) && defined?(is_unix_socket?)
23
-
24
- server_as_array = Lib.memcached_server_by_key(@struct, key.to_s)
25
-
26
- return unless server_as_array.is_a?(Array)
27
-
28
- server = server_as_array.first
29
- if is_unix_socket?(server)
30
- 'localhost'
31
- elsif defined?(server.hostname)
32
- server.hostname
33
- end
34
- end
35
- end
36
- end
37
- end
@@ -1,63 +0,0 @@
1
- # Copyright (c) 2019 SolarWinds, LLC.
2
- # All rights reserved.
3
-
4
- module SolarWindsAPM
5
- module API
6
- module Metrics
7
-
8
- ##
9
- # Internal: method to send duration for a transaction
10
- # it checks if it can send metrics with the current transaction name
11
- # or a default transaction name and sets the transaction name accordingly
12
- #
13
- # === Arguments:
14
- #
15
- # * +span+ the name of the current span (used to construct a transaction name if none is defined)
16
- # * +kvs+ A hash containing key/value pairs, only the value of :TransactionName will be relevant
17
- #
18
- # === Returns:
19
- # The result of the block.
20
- #
21
- # === Assigns:
22
- # The transaction_name to kvs[:TransactionName]
23
-
24
- def send_metrics(span, kvs)
25
- start = Time.now
26
- yield
27
- ensure
28
- # TODO send_metrics is currently used in grpc, sdk
29
- # ____ the error (0,1) would have to be returned from yield
30
- error = 0
31
- duration = (1000 * 1000 * (Time.now - start)).to_i
32
- transaction_name = determine_transaction_name(span, kvs)
33
- kvs[:TransactionName] = SolarWindsAPM::Span.createSpan(transaction_name, nil, duration, error)
34
- SolarWindsAPM.transaction_name = nil
35
- end
36
-
37
- private
38
-
39
- ##
40
- # Determine the transaction name to be set on the trace.
41
- #
42
- # === Argument:
43
- # * +span+ the name of the current span (used to construct a transaction name if none is defined)
44
- # * +kvs+ (hash, optional) the hash that may have values for 'Controller' and 'Action'
45
- #
46
- # === Returns:
47
- # (string) the determined transaction name
48
- #
49
- def determine_transaction_name(span, kvs = {})
50
- if SolarWindsAPM.transaction_name
51
- SolarWindsAPM.transaction_name
52
- elsif kvs['Controller'] && kvs['Action']
53
- [kvs['Controller'], kvs['Action']].join('.')
54
- elsif kvs[:Controller] && kvs[:Action]
55
- [kvs[:Controller], kvs[:Action]].join('.')
56
- else
57
- "custom-#{span}"
58
- end
59
- end
60
-
61
- end
62
- end
63
- end
@@ -1,98 +0,0 @@
1
- #--
2
- # Copyright (c) 2016 SolarWinds, LLC.
3
- # All rights reserved.
4
- #++
5
-
6
- require 'pp'
7
-
8
- module SolarWindsAPM
9
- module API
10
- ##
11
- # General utility methods for the gem
12
- module Util #:nodoc:
13
- BACKTRACE_CUTOFF = 200
14
-
15
- # Internal: Check whether the provided key is reserved or not. Reserved
16
- # keys are either keys that are handled by liboboe calls or the solarwinds_apm gem.
17
- #
18
- # key - the key to check.
19
- #
20
- # Return a boolean indicating whether or not key is reserved.
21
- def valid_key?(key)
22
- ![:Label, :Layer, :Timestamp, :Timestamp_u].include?(key.to_sym)
23
- end
24
-
25
- # Internal: Get the current backtrace.
26
- #
27
- # from - int, from position in array of backtraces
28
- # to - int, end position in array of backtraces, can be negative to count from the end
29
- #
30
- # Returns a string with each frame of the backtrace separated by '\r\n'.
31
- #
32
- def backtrace(from = 0, to = -1)
33
- bt = Kernel.caller
34
- trim_backtrace(bt[from..to]).join("\r\n")
35
- end
36
-
37
- # Internal: Trim a backtrace to a manageable size
38
- #
39
- # backtrace - the backtrace (an array of stack frames/from Kernel.caller)
40
- #
41
- # Returns a trimmed backtrace
42
- def trim_backtrace(backtrace)
43
- return backtrace unless backtrace.is_a?(Array) && backtrace.size > BACKTRACE_CUTOFF
44
-
45
- # Trim backtraces by getting the first 180 and last 20 lines
46
- backtrace[0, 180] + ['...[snip]...'] + backtrace[backtrace.size - 20, 20]
47
- end
48
-
49
- # Internal: Pretty print a list of arguments for reporting
50
- #
51
- # args - the list of arguments to work on
52
- #
53
- # Returns a pretty string representation of arguments
54
- def pps(*args)
55
- old_out = $stdout
56
- begin
57
- s = StringIO.new
58
- $stdout = s
59
- pp(*args)
60
- ensure
61
- $stdout = old_out
62
- end
63
- s.string
64
- end
65
-
66
- # Internal: Determine a string to report representing klass
67
- #
68
- # args - an instance of a Class, a Class or a Module
69
- #
70
- # Returns a string representation of klass
71
- def get_class_name(klass)
72
- kv = {}
73
-
74
- if klass.to_s =~ /::/
75
- klass.class.to_s.rpartition('::').last
76
- else
77
- if klass.is_a?(Class) && klass.is_a?(Module)
78
- # Class
79
- kv['Class'] = klass.to_s
80
-
81
- elsif !klass.is_a?(Class) && !klass.is_a?(Module)
82
- # Class instance
83
- kv['Class'] = klass.class.to_s
84
-
85
- else
86
- # Module
87
- kv['Module'] = klass.to_s
88
- end
89
- end
90
- kv
91
- end
92
-
93
- def xtrace_v2?(xtr)
94
- xtr && xtr.start_with?('2B')
95
- end
96
- end
97
- end
98
- end
@@ -1,96 +0,0 @@
1
- # Copyright (c) 2016 SolarWinds, LLC.
2
- # All rights reserved.
3
- #
4
- class GrapeError < StandardError; end
5
-
6
- module SolarWindsAPM
7
- module Grape
8
- module API
9
- def self.extended(klass)
10
- SolarWindsAPM::Util.class_method_alias(klass, :inherited, ::Grape::API)
11
- end
12
-
13
- def inherited_with_sw_apm(subclass)
14
- inherited_without_sw_apm(subclass)
15
-
16
- subclass.use SolarWindsAPM::Rack
17
- end
18
- end
19
-
20
- module Endpoint
21
- def self.included(klass)
22
- SolarWindsAPM::Util.method_alias(klass, :run, ::Grape::Endpoint)
23
- end
24
-
25
- def run_with_sw_apm(*args)
26
- # Report Controller/Action and Transaction as best possible
27
- report_kvs = {}
28
-
29
- report_kvs[:Controller] = options[:for].to_s
30
- report_kvs[:Action] =
31
- if route&.pattern
32
- route.options ? "#{route.options[:method]}#{route.pattern.origin}" : route.pattern.origin
33
- else
34
- args.empty? ? env['PATH_INFO'] : args[0]['PATH_INFO']
35
- end
36
- report_kvs[:Backtrace] = SolarWindsAPM::API.backtrace if SolarWindsAPM::Config[:grape][:collect_backtraces]
37
-
38
- env['solarwinds_apm.controller'] = report_kvs[:Controller]
39
- env['solarwinds_apm.action'] = report_kvs[:Action]
40
-
41
- SolarWindsAPM::API.log_entry('grape', report_kvs)
42
-
43
- run_without_sw_apm(*args)
44
- ensure
45
- SolarWindsAPM::API.log_exit('grape')
46
- end
47
- end
48
-
49
- module Middleware
50
- module Error
51
- def self.included(klass)
52
- SolarWindsAPM::Util.method_alias(klass, :error_response, ::Grape::Middleware::Error)
53
- end
54
-
55
- def error_response_with_sw_apm(error = {})
56
- response = error_response_without_sw_apm(error)
57
- status, headers, _body = response.finish
58
-
59
- tracestring = SolarWindsAPM::Context.toString
60
-
61
- if SolarWindsAPM.tracing?
62
- # Since Grape uses throw/catch and not Exceptions, we have to create an exception here
63
- exception = GrapeError.new(error[:message] ? error[:message] : "No message given.")
64
- exception.set_backtrace(SolarWindsAPM::API.backtrace)
65
-
66
- SolarWindsAPM::API.log_exception('rack', exception)
67
-
68
- # Since calls to error() are handled similar to abort in Grape. We
69
- # manually log the rack exit here since the original code won't
70
- # be returned to
71
- tracestring = SolarWindsAPM::API.log_end('rack', :Status => status)
72
- end
73
-
74
- if headers && headers.is_a?(Hash) && SolarWindsAPM::TraceString.valid?(tracestring)
75
- # TODO this will change, w3c outgoing headers have not been standardized yet
76
- headers['X-Trace'] = tracestring
77
- end
78
-
79
- response
80
- end
81
- end
82
- end
83
- end
84
- end
85
-
86
- if SolarWindsAPM::Config[:grape][:enabled] && defined?(Grape)
87
- require 'solarwinds_apm/inst/rack'
88
-
89
- SolarWindsAPM.logger.info "[solarwinds_apm/loading] Instrumenting Grape" if SolarWindsAPM::Config[:verbose]
90
-
91
- SolarWindsAPM::Inst.load_instrumentation
92
-
93
- SolarWindsAPM::Util.send_extend(Grape::API, SolarWindsAPM::Grape::API)
94
- SolarWindsAPM::Util.send_include(Grape::Endpoint, SolarWindsAPM::Grape::Endpoint)
95
- SolarWindsAPM::Util.send_include(Grape::Middleware::Error, SolarWindsAPM::Grape::Middleware::Error)
96
- end