appoptics_apm_mnfst 4.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/.dockerignore +5 -0
  3. data/.github/ISSUE_TEMPLATE/bug-or-feature-request.md +16 -0
  4. data/.gitignore +29 -0
  5. data/.rubocop.yml +8 -0
  6. data/.travis.yml +121 -0
  7. data/.yardopts +4 -0
  8. data/CHANGELOG.md +769 -0
  9. data/CONFIG.md +33 -0
  10. data/Gemfile +29 -0
  11. data/LICENSE +193 -0
  12. data/README.md +393 -0
  13. data/Rakefile +230 -0
  14. data/appoptics_apm.gemspec +61 -0
  15. data/bin/appoptics_apm_config +15 -0
  16. data/build_gem.sh +15 -0
  17. data/build_gem_upload_to_packagecloud.sh +20 -0
  18. data/examples/SDK/01_basic_tracing.rb +67 -0
  19. data/examples/carrying_context.rb +220 -0
  20. data/ext/oboe_metal/extconf.rb +114 -0
  21. data/ext/oboe_metal/lib/.keep +0 -0
  22. data/ext/oboe_metal/noop/noop.c +7 -0
  23. data/ext/oboe_metal/src/VERSION +1 -0
  24. data/init.rb +4 -0
  25. data/lib/appoptics_apm.rb +76 -0
  26. data/lib/appoptics_apm/api.rb +20 -0
  27. data/lib/appoptics_apm/api/layerinit.rb +41 -0
  28. data/lib/appoptics_apm/api/logging.rb +375 -0
  29. data/lib/appoptics_apm/api/memcache.rb +37 -0
  30. data/lib/appoptics_apm/api/metrics.rb +55 -0
  31. data/lib/appoptics_apm/api/profiling.rb +203 -0
  32. data/lib/appoptics_apm/api/tracing.rb +53 -0
  33. data/lib/appoptics_apm/api/util.rb +122 -0
  34. data/lib/appoptics_apm/base.rb +230 -0
  35. data/lib/appoptics_apm/config.rb +254 -0
  36. data/lib/appoptics_apm/frameworks/grape.rb +97 -0
  37. data/lib/appoptics_apm/frameworks/padrino.rb +108 -0
  38. data/lib/appoptics_apm/frameworks/rails.rb +94 -0
  39. data/lib/appoptics_apm/frameworks/rails/inst/action_controller.rb +104 -0
  40. data/lib/appoptics_apm/frameworks/rails/inst/action_controller3.rb +55 -0
  41. data/lib/appoptics_apm/frameworks/rails/inst/action_controller4.rb +48 -0
  42. data/lib/appoptics_apm/frameworks/rails/inst/action_controller5.rb +50 -0
  43. data/lib/appoptics_apm/frameworks/rails/inst/action_controller_api.rb +50 -0
  44. data/lib/appoptics_apm/frameworks/rails/inst/action_view.rb +58 -0
  45. data/lib/appoptics_apm/frameworks/rails/inst/action_view_30.rb +50 -0
  46. data/lib/appoptics_apm/frameworks/rails/inst/active_record.rb +27 -0
  47. data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/mysql.rb +43 -0
  48. data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/mysql2.rb +29 -0
  49. data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/postgresql.rb +31 -0
  50. data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/utils.rb +119 -0
  51. data/lib/appoptics_apm/frameworks/rails/inst/connection_adapters/utils5x.rb +108 -0
  52. data/lib/appoptics_apm/frameworks/sinatra.rb +125 -0
  53. data/lib/appoptics_apm/inst/bunny-client.rb +148 -0
  54. data/lib/appoptics_apm/inst/bunny-consumer.rb +89 -0
  55. data/lib/appoptics_apm/inst/curb.rb +330 -0
  56. data/lib/appoptics_apm/inst/dalli.rb +85 -0
  57. data/lib/appoptics_apm/inst/delayed_job.rb +92 -0
  58. data/lib/appoptics_apm/inst/em-http-request.rb +101 -0
  59. data/lib/appoptics_apm/inst/excon.rb +125 -0
  60. data/lib/appoptics_apm/inst/faraday.rb +94 -0
  61. data/lib/appoptics_apm/inst/grpc_client.rb +162 -0
  62. data/lib/appoptics_apm/inst/grpc_server.rb +120 -0
  63. data/lib/appoptics_apm/inst/http.rb +73 -0
  64. data/lib/appoptics_apm/inst/httpclient.rb +174 -0
  65. data/lib/appoptics_apm/inst/memcached.rb +86 -0
  66. data/lib/appoptics_apm/inst/mongo.rb +246 -0
  67. data/lib/appoptics_apm/inst/mongo2.rb +225 -0
  68. data/lib/appoptics_apm/inst/moped.rb +466 -0
  69. data/lib/appoptics_apm/inst/rack.rb +199 -0
  70. data/lib/appoptics_apm/inst/redis.rb +275 -0
  71. data/lib/appoptics_apm/inst/resque.rb +151 -0
  72. data/lib/appoptics_apm/inst/rest-client.rb +48 -0
  73. data/lib/appoptics_apm/inst/sequel.rb +178 -0
  74. data/lib/appoptics_apm/inst/sidekiq-client.rb +55 -0
  75. data/lib/appoptics_apm/inst/sidekiq-worker.rb +65 -0
  76. data/lib/appoptics_apm/inst/twitter-cassandra.rb +294 -0
  77. data/lib/appoptics_apm/inst/typhoeus.rb +108 -0
  78. data/lib/appoptics_apm/instrumentation.rb +22 -0
  79. data/lib/appoptics_apm/legacy_method_profiling.rb +90 -0
  80. data/lib/appoptics_apm/loading.rb +65 -0
  81. data/lib/appoptics_apm/logger.rb +42 -0
  82. data/lib/appoptics_apm/method_profiling.rb +33 -0
  83. data/lib/appoptics_apm/noop/README.md +9 -0
  84. data/lib/appoptics_apm/noop/context.rb +26 -0
  85. data/lib/appoptics_apm/noop/metadata.rb +22 -0
  86. data/lib/appoptics_apm/ruby.rb +35 -0
  87. data/lib/appoptics_apm/sdk/custom_metrics.rb +92 -0
  88. data/lib/appoptics_apm/sdk/tracing.rb +315 -0
  89. data/lib/appoptics_apm/support.rb +119 -0
  90. data/lib/appoptics_apm/test.rb +94 -0
  91. data/lib/appoptics_apm/thread_local.rb +26 -0
  92. data/lib/appoptics_apm/util.rb +319 -0
  93. data/lib/appoptics_apm/version.rb +15 -0
  94. data/lib/appoptics_apm/xtrace.rb +103 -0
  95. data/lib/joboe_metal.rb +212 -0
  96. data/lib/oboe.rb +7 -0
  97. data/lib/oboe/README +2 -0
  98. data/lib/oboe/backward_compatibility.rb +80 -0
  99. data/lib/oboe/inst/rack.rb +11 -0
  100. data/lib/oboe_metal.rb +198 -0
  101. data/lib/rails/generators/appoptics_apm/install_generator.rb +45 -0
  102. data/lib/rails/generators/appoptics_apm/templates/appoptics_apm_initializer.rb +265 -0
  103. data/yardoc_frontpage.md +26 -0
  104. metadata +266 -0
@@ -0,0 +1,466 @@
1
+ # Copyright (c) 2016 SolarWinds, LLC.
2
+ # All rights reserved.
3
+
4
+ require 'json'
5
+
6
+ module AppOpticsAPM
7
+ module Inst
8
+ ##
9
+ # Moped
10
+ #
11
+ module Moped
12
+ FLAVOR = :mongodb
13
+
14
+ # Moped::Database
15
+ DB_OPS = [:command, :drop].freeze
16
+
17
+ # Moped::Indexes
18
+ INDEX_OPS = [:create, :drop].freeze
19
+
20
+ # Moped::Query
21
+ QUERY_OPS = [:count, :sort, :limit, :distinct, :update, :update_all, :upsert,
22
+ :explain, :modify, :remove, :remove_all].freeze
23
+
24
+ # Moped::Collection
25
+ COLLECTION_OPS = [:drop, :find, :indexes, :insert, :aggregate].freeze
26
+
27
+ ##
28
+ # remote_host
29
+ #
30
+ # This utility method converts the server into a host:port
31
+ # pair for reporting
32
+ #
33
+ def remote_host(server)
34
+ if ::Moped::VERSION < '2.0.0'
35
+ server
36
+ else
37
+ "#{server.address.host}:#{server.address.port}"
38
+ end
39
+ end
40
+ end
41
+
42
+ ##
43
+ # MopedDatabase
44
+ #
45
+ module MopedDatabase
46
+ include AppOpticsAPM::Inst::Moped
47
+
48
+ def self.included(klass)
49
+ AppOpticsAPM::Inst::Moped::DB_OPS.each do |m|
50
+ AppOpticsAPM::Util.method_alias(klass, m)
51
+ end
52
+ end
53
+
54
+ def extract_trace_details(op)
55
+ report_kvs = {}
56
+ report_kvs[:Flavor] = AppOpticsAPM::Inst::Moped::FLAVOR
57
+ # FIXME: We're only grabbing the first of potentially multiple servers here
58
+ report_kvs[:RemoteHost] = remote_host(session.cluster.seeds.first)
59
+ report_kvs[:Database] = name
60
+ report_kvs[:QueryOp] = op.to_s
61
+ report_kvs[:Backtrace] = AppOpticsAPM::API.backtrace if AppOpticsAPM::Config[:moped][:collect_backtraces]
62
+ rescue StandardError => e
63
+ AppOpticsAPM.logger.debug "[appoptics_apm/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
64
+ ensure
65
+ return report_kvs
66
+ end
67
+
68
+ def command_with_appoptics(command)
69
+ if AppOpticsAPM.tracing? && !AppOpticsAPM.layer_op && command.key?(:mapreduce)
70
+ begin
71
+ report_kvs = extract_trace_details(:map_reduce)
72
+ report_kvs[:Map_Function] = command[:map]
73
+ report_kvs[:Reduce_Function] = command[:reduce]
74
+ rescue => e
75
+ AppOpticsAPM.logger.debug "[appoptics_apm/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
76
+ end
77
+
78
+ AppOpticsAPM::API.trace(:mongo, report_kvs) do
79
+ command_without_appoptics(command)
80
+ end
81
+ else
82
+ command_without_appoptics(command)
83
+ end
84
+ end
85
+
86
+ def drop_with_appoptics
87
+ return drop_without_appoptics unless AppOpticsAPM.tracing?
88
+
89
+ report_kvs = extract_trace_details(:drop_database)
90
+
91
+ AppOpticsAPM::API.trace(:mongo, report_kvs) do
92
+ drop_without_appoptics
93
+ end
94
+ end
95
+ end
96
+
97
+ ##
98
+ # MopedIndexes
99
+ #
100
+ module MopedIndexes
101
+ include AppOpticsAPM::Inst::Moped
102
+
103
+ def self.included(klass)
104
+ AppOpticsAPM::Inst::Moped::INDEX_OPS.each do |m|
105
+ AppOpticsAPM::Util.method_alias(klass, m)
106
+ end
107
+ end
108
+
109
+ def extract_trace_details(op)
110
+ report_kvs = {}
111
+ report_kvs[:Flavor] = AppOpticsAPM::Inst::Moped::FLAVOR
112
+
113
+ # FIXME: We're only grabbing the first of potentially multiple servers here
114
+ first = database.session.cluster.seeds.first
115
+ if ::Moped::VERSION < '2.0.0'
116
+ report_kvs[:RemoteHost] = first
117
+ else
118
+ report_kvs[:RemoteHost] = "#{first.address.host}:#{first.address.port}"
119
+ end
120
+ report_kvs[:Database] = database.name
121
+ report_kvs[:QueryOp] = op.to_s
122
+ report_kvs[:Backtrace] = AppOpticsAPM::API.backtrace if AppOpticsAPM::Config[:moped][:collect_backtraces]
123
+ rescue StandardError => e
124
+ AppOpticsAPM.logger.debug "[appoptics_apm/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
125
+ ensure
126
+ return report_kvs
127
+ end
128
+
129
+ def create_with_appoptics(key, options = {})
130
+ return create_without_appoptics(key, options) unless AppOpticsAPM.tracing?
131
+
132
+ begin
133
+ # We report :create_index here to be consistent
134
+ # with other mongo implementations
135
+ report_kvs = extract_trace_details(:create_index)
136
+ report_kvs[:Key] = key.to_json
137
+ report_kvs[:Options] = options.to_json
138
+ rescue StandardError => e
139
+ AppOpticsAPM.logger.debug "[appoptics_apm/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
140
+ end
141
+
142
+ AppOpticsAPM::API.trace(:mongo, report_kvs, :create_index) do
143
+ create_without_appoptics(key, options = {})
144
+ end
145
+ end
146
+
147
+ def drop_with_appoptics(key = nil)
148
+ return drop_without_appoptics(key) unless AppOpticsAPM.tracing?
149
+
150
+ begin
151
+ # We report :drop_indexes here to be consistent
152
+ # with other mongo implementations
153
+ report_kvs = extract_trace_details(:drop_indexes)
154
+ report_kvs[:Key] = key.nil? ? :all : key.to_json
155
+ rescue StandardError => e
156
+ AppOpticsAPM.logger.debug "[appoptics_apm/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
157
+ end
158
+
159
+ AppOpticsAPM::API.trace(:mongo, report_kvs) do
160
+ drop_without_appoptics(key = nil)
161
+ end
162
+ end
163
+ end
164
+
165
+ ##
166
+ # MopedQuery
167
+ #
168
+ module MopedQuery
169
+ include AppOpticsAPM::Inst::Moped
170
+
171
+ def self.included(klass)
172
+ AppOpticsAPM::Inst::Moped::QUERY_OPS.each do |m|
173
+ AppOpticsAPM::Util.method_alias(klass, m)
174
+ end
175
+ end
176
+
177
+ def extract_trace_details(op)
178
+ report_kvs = {}
179
+ report_kvs[:Flavor] = AppOpticsAPM::Inst::Moped::FLAVOR
180
+ # FIXME: We're only grabbing the first of potentially multiple servers here
181
+ first = collection.database.session.cluster.seeds.first
182
+ report_kvs[:RemoteHost] = remote_host(first)
183
+ report_kvs[:Database] = collection.database.name
184
+ report_kvs[:Collection] = collection.name
185
+ report_kvs[:QueryOp] = op.to_s
186
+ report_kvs[:Backtrace] = AppOpticsAPM::API.backtrace if AppOpticsAPM::Config[:moped][:collect_backtraces]
187
+ rescue StandardError => e
188
+ AppOpticsAPM.logger.debug "[appoptics_apm/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
189
+ ensure
190
+ return report_kvs
191
+ end
192
+
193
+ def count_with_appoptics
194
+ return count_without_appoptics unless AppOpticsAPM.tracing?
195
+
196
+ begin
197
+ report_kvs = extract_trace_details(:count)
198
+ report_kvs[:Query] = selector.empty? ? :all : selector.to_json
199
+ rescue StandardError => e
200
+ AppOpticsAPM.logger.debug "[appoptics_apm/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
201
+ end
202
+
203
+ AppOpticsAPM::API.trace(:mongo, report_kvs) do
204
+ count_without_appoptics
205
+ end
206
+ end
207
+
208
+ def sort_with_appoptics(sort)
209
+ return sort_without_appoptics(sort) unless AppOpticsAPM.tracing?
210
+
211
+ begin
212
+ report_kvs = extract_trace_details(:sort)
213
+ report_kvs[:Query] = selector.empty? ? :all : selector.to_json
214
+ report_kvs[:Order] = sort.to_s
215
+ rescue StandardError => e
216
+ AppOpticsAPM.logger.debug "[appoptics_apm/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
217
+ end
218
+
219
+ AppOpticsAPM::API.trace(:mongo, report_kvs) do
220
+ sort_without_appoptics(sort)
221
+ end
222
+ end
223
+
224
+ def limit_with_appoptics(limit)
225
+ if AppOpticsAPM.tracing? && !AppOpticsAPM.tracing_layer_op?(:explain)
226
+ begin
227
+ report_kvs = extract_trace_details(:limit)
228
+ report_kvs[:Query] = selector.empty? ? :all : selector.to_json
229
+ report_kvs[:Limit] = limit.to_s
230
+ rescue StandardError => e
231
+ AppOpticsAPM.logger.debug "[appoptics_apm/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
232
+ end
233
+
234
+ AppOpticsAPM::API.trace(:mongo, report_kvs) do
235
+ limit_without_appoptics(limit)
236
+ end
237
+ else
238
+ limit_without_appoptics(limit)
239
+ end
240
+ end
241
+
242
+ def distinct_with_appoptics(key)
243
+ return distinct_without_appoptics(key) unless AppOpticsAPM.tracing?
244
+
245
+ begin
246
+ report_kvs = extract_trace_details(:distinct)
247
+ report_kvs[:Query] = selector.empty? ? :all : selector.to_json
248
+ report_kvs[:Key] = key.to_s
249
+ rescue StandardError => e
250
+ AppOpticsAPM.logger.debug "[appoptics_apm/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
251
+ end
252
+
253
+ AppOpticsAPM::API.trace(:mongo, report_kvs) do
254
+ distinct_without_appoptics(key)
255
+ end
256
+ end
257
+
258
+ def update_with_appoptics(change, flags = nil)
259
+ if AppOpticsAPM.tracing? && !AppOpticsAPM.tracing_layer_op?(:update_all) && !AppOpticsAPM.tracing_layer_op?(:upsert)
260
+ begin
261
+ report_kvs = extract_trace_details(:update)
262
+ report_kvs[:Flags] = flags.to_s if flags
263
+ report_kvs[:Update_Document] = change.to_json
264
+ rescue StandardError => e
265
+ AppOpticsAPM.logger.debug "[appoptics_apm/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
266
+ end
267
+
268
+ AppOpticsAPM::API.trace(:mongo, report_kvs) do
269
+ update_without_appoptics(change, flags)
270
+ end
271
+ else
272
+ update_without_appoptics(change, flags)
273
+ end
274
+ end
275
+
276
+ def update_all_with_appoptics(change)
277
+ return update_all_without_appoptics(change) unless AppOpticsAPM.tracing?
278
+
279
+ begin
280
+ report_kvs = extract_trace_details(:update_all)
281
+ report_kvs[:Update_Document] = change.to_json
282
+ rescue StandardError => e
283
+ AppOpticsAPM.logger.debug "[appoptics_apm/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
284
+ end
285
+
286
+ AppOpticsAPM::API.trace(:mongo, report_kvs, :update_all) do
287
+ update_all_without_appoptics(change)
288
+ end
289
+ end
290
+
291
+ def upsert_with_appoptics(change)
292
+ return upsert_without_appoptics(change) unless AppOpticsAPM.tracing?
293
+
294
+ begin
295
+ report_kvs = extract_trace_details(:upsert)
296
+ report_kvs[:Query] = selector.to_json
297
+ report_kvs[:Update_Document] = change.to_json
298
+ rescue StandardError => e
299
+ AppOpticsAPM.logger.debug "[appoptics_apm/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
300
+ end
301
+
302
+ AppOpticsAPM::API.trace(:mongo, report_kvs, :upsert) do
303
+ upsert_without_appoptics(change)
304
+ end
305
+ end
306
+
307
+ def explain_with_appoptics
308
+ return explain_without_appoptics unless AppOpticsAPM.tracing?
309
+
310
+ begin
311
+ report_kvs = extract_trace_details(:explain)
312
+ report_kvs[:Query] = selector.empty? ? :all : selector.to_json
313
+ rescue StandardError => e
314
+ AppOpticsAPM.logger.debug "[appoptics_apm/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
315
+ end
316
+
317
+ AppOpticsAPM::API.trace(:mongo, report_kvs, :explain) do
318
+ explain_without_appoptics
319
+ end
320
+ end
321
+
322
+ def modify_with_appoptics(change, options = {})
323
+ return modify_without_appoptics(change, options) unless AppOpticsAPM.tracing?
324
+
325
+ begin
326
+ report_kvs = extract_trace_details(:modify)
327
+ report_kvs[:Update_Document] = selector.empty? ? :all : selector.to_json
328
+ report_kvs[:Change] = change.to_json
329
+ report_kvs[:Options] = options.to_json
330
+ rescue StandardError => e
331
+ AppOpticsAPM.logger.debug "[appoptics_apm/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
332
+ end
333
+
334
+ AppOpticsAPM::API.trace(:mongo, report_kvs) do
335
+ modify_without_appoptics(change, options)
336
+ end
337
+ end
338
+
339
+ def remove_with_appoptics
340
+ return remove_without_appoptics unless AppOpticsAPM.tracing?
341
+
342
+ begin
343
+ report_kvs = extract_trace_details(:remove)
344
+ report_kvs[:Query] = selector.to_json
345
+ rescue StandardError => e
346
+ AppOpticsAPM.logger.debug "[appoptics_apm/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
347
+ end
348
+
349
+ AppOpticsAPM::API.trace(:mongo, report_kvs) do
350
+ remove_without_appoptics
351
+ end
352
+ end
353
+
354
+ def remove_all_with_appoptics
355
+ return remove_all_without_appoptics unless AppOpticsAPM.tracing?
356
+
357
+ begin
358
+ report_kvs = extract_trace_details(:remove_all)
359
+ report_kvs[:Query] = selector.to_json
360
+ rescue StandardError => e
361
+ AppOpticsAPM.logger.debug "[appoptics_apm/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
362
+ end
363
+
364
+ AppOpticsAPM::API.trace(:mongo, report_kvs) do
365
+ remove_all_without_appoptics
366
+ end
367
+ end
368
+ end
369
+
370
+ ##
371
+ # MopedCollection
372
+ #
373
+ module MopedCollection
374
+ include AppOpticsAPM::Inst::Moped
375
+
376
+ def self.included(klass)
377
+ AppOpticsAPM::Inst::Moped::COLLECTION_OPS.each do |m|
378
+ AppOpticsAPM::Util.method_alias(klass, m)
379
+ end
380
+ end
381
+
382
+ def extract_trace_details(op)
383
+ report_kvs = {}
384
+ report_kvs[:Flavor] = AppOpticsAPM::Inst::Moped::FLAVOR
385
+ # FIXME: We're only grabbing the first of potentially multiple servers here
386
+ report_kvs[:RemoteHost] = remote_host(database.session.cluster.seeds.first)
387
+ report_kvs[:Database] = database.name
388
+ report_kvs[:Collection] = name
389
+ report_kvs[:QueryOp] = op.to_s
390
+ report_kvs[:Backtrace] = AppOpticsAPM::API.backtrace if AppOpticsAPM::Config[:moped][:collect_backtraces]
391
+ rescue StandardError => e
392
+ AppOpticsAPM.logger.debug "[appoptics_apm/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
393
+ ensure
394
+ return report_kvs
395
+ end
396
+
397
+ def drop_with_appoptics
398
+ return drop_without_appoptics unless AppOpticsAPM.tracing?
399
+
400
+ # We report :drop_collection here to be consistent
401
+ # with other mongo implementations
402
+ report_kvs = extract_trace_details(:drop_collection)
403
+
404
+ AppOpticsAPM::API.trace(:mongo, report_kvs) do
405
+ drop_without_appoptics
406
+ end
407
+ end
408
+
409
+ def find_with_appoptics(selector = {})
410
+ return find_without_appoptics(selector) unless AppOpticsAPM.tracing?
411
+
412
+ begin
413
+ report_kvs = extract_trace_details(:find)
414
+ report_kvs[:Query] = selector.empty? ? 'all' : selector.to_json
415
+ rescue StandardError => e
416
+ AppOpticsAPM.logger.debug "[appoptics_apm/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
417
+ end
418
+
419
+ AppOpticsAPM::API.trace(:mongo, report_kvs) do
420
+ find_without_appoptics(selector)
421
+ end
422
+ end
423
+
424
+ def indexes_with_appoptics
425
+ return indexes_without_appoptics unless AppOpticsAPM.tracing?
426
+
427
+ report_kvs = extract_trace_details(:indexes)
428
+
429
+ AppOpticsAPM::API.trace(:mongo, report_kvs) do
430
+ indexes_without_appoptics
431
+ end
432
+ end
433
+
434
+ def insert_with_appoptics(documents, flags = nil)
435
+ if AppOpticsAPM.tracing? && !AppOpticsAPM.tracing_layer_op?(:create_index)
436
+ report_kvs = extract_trace_details(:insert)
437
+
438
+ AppOpticsAPM::API.trace(:mongo, report_kvs) do
439
+ insert_without_appoptics(documents, flags)
440
+ end
441
+ else
442
+ insert_without_appoptics(documents, flags)
443
+ end
444
+ end
445
+
446
+ def aggregate_with_appoptics(*pipeline)
447
+ return aggregate_without_appoptics(*pipeline) unless AppOpticsAPM.tracing?
448
+
449
+ report_kvs = extract_trace_details(:aggregate)
450
+ report_kvs[:Query] = pipeline
451
+
452
+ AppOpticsAPM::API.trace(:mongo, report_kvs) do
453
+ aggregate_without_appoptics(pipeline)
454
+ end
455
+ end
456
+ end
457
+ end
458
+ end
459
+
460
+ if defined?(Moped) && AppOpticsAPM::Config[:moped][:enabled]
461
+ AppOpticsAPM.logger.info '[appoptics_apm/loading] Instrumenting moped' if AppOpticsAPM::Config[:verbose]
462
+ AppOpticsAPM::Util.send_include(Moped::Database, AppOpticsAPM::Inst::MopedDatabase)
463
+ AppOpticsAPM::Util.send_include(Moped::Collection, AppOpticsAPM::Inst::MopedCollection)
464
+ AppOpticsAPM::Util.send_include(Moped::Query, AppOpticsAPM::Inst::MopedQuery)
465
+ AppOpticsAPM::Util.send_include(Moped::Indexes, AppOpticsAPM::Inst::MopedIndexes)
466
+ end