traceview 3.8.1 → 3.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +43 -0
- data/.travis.yml +5 -4
- data/CHANGELOG.md +114 -114
- data/Gemfile +5 -6
- data/README.md +3 -3
- data/Rakefile +18 -21
- data/examples/DNT.md +3 -3
- data/examples/carrying_context.rb +26 -31
- data/examples/instrumenting_metal_controller.rb +1 -1
- data/examples/puma_on_heroku_config.rb +3 -3
- data/examples/tracing_async_threads.rb +9 -9
- data/examples/tracing_background_jobs.rb +5 -7
- data/examples/tracing_forked_processes.rb +13 -14
- data/examples/unicorn_on_heroku_config.rb +4 -4
- data/gemfiles/rails50.gemfile +1 -1
- data/lib/joboe_metal.rb +2 -5
- data/lib/oboe/backward_compatibility.rb +3 -5
- data/lib/oboe_metal.rb +37 -43
- data/lib/traceview/api/logging.rb +1 -2
- data/lib/traceview/base.rb +3 -0
- data/lib/traceview/config.rb +19 -3
- data/lib/traceview/frameworks/rails/inst/action_controller.rb +2 -2
- data/lib/traceview/frameworks/rails/inst/{action_controller5_api.rb → action_controller_api.rb} +0 -0
- data/lib/traceview/frameworks/rails/inst/connection_adapters/utils.rb +2 -2
- data/lib/traceview/frameworks/rails/inst/connection_adapters/utils5x.rb +3 -4
- data/lib/traceview/inst/httpclient.rb +12 -12
- data/lib/traceview/inst/mongo2.rb +7 -8
- data/lib/traceview/inst/moped.rb +334 -343
- data/lib/traceview/inst/rack.rb +14 -2
- data/lib/traceview/inst/redis.rb +104 -110
- data/lib/traceview/inst/sequel.rb +43 -37
- data/lib/traceview/inst/twitter-cassandra.rb +12 -6
- data/lib/traceview/support.rb +34 -32
- data/lib/traceview/util.rb +7 -4
- data/lib/traceview/version.rb +1 -1
- data/test/instrumentation/curb_test.rb +2 -24
- data/test/instrumentation/httpclient_test.rb +7 -18
- data/test/instrumentation/{cassandra_test.rb → twitter-cassandra_test.rb} +32 -0
- data/test/minitest_helper.rb +0 -3
- data/test/settings +0 -0
- data/test/support/avw_handling_test.rb +13 -23
- data/test/support/config_test.rb +1 -1
- data/test/support/tracing_mode_test.rb +44 -0
- metadata +10 -6
@@ -7,15 +7,14 @@ if RUBY_VERSION >= '1.9' && TraceView::Config[:mongo][:enabled]
|
|
7
7
|
if defined?(::Mongo) && (Gem.loaded_specs['mongo'].version.to_s >= '2.0.0')
|
8
8
|
::TraceView.logger.info '[traceview/loading] Instrumenting mongo' if TraceView::Config[:verbose]
|
9
9
|
|
10
|
-
|
11
10
|
# Collection Related Operations
|
12
|
-
COLL_OTHER_OPS = [:create, :drop, :insert_one, :insert_many, :bulk_write, :map_reduce]
|
11
|
+
COLL_OTHER_OPS = [:create, :drop, :insert_one, :insert_many, :bulk_write, :map_reduce].freeze
|
13
12
|
|
14
13
|
# Mongo 2.2 only ops
|
15
14
|
if Mongo::VERSION >= '2.1'
|
16
|
-
COLL_QUERY_OPS = [
|
15
|
+
COLL_QUERY_OPS = [:find, :find_one_and_delete, :find_one_and_update, :find_one_and_replace, :update_one, :update_many, :delete_one, :delete_many, :replace_one].freeze
|
17
16
|
else
|
18
|
-
COLL_QUERY_OPS = [
|
17
|
+
COLL_QUERY_OPS = [:find, :update_many, :delete_one].freeze
|
19
18
|
end
|
20
19
|
|
21
20
|
COLL_OPS = COLL_QUERY_OPS + COLL_OTHER_OPS
|
@@ -92,9 +91,9 @@ if RUBY_VERSION >= '1.9' && TraceView::Config[:mongo][:enabled]
|
|
92
91
|
#
|
93
92
|
|
94
93
|
# Collection View Related Operations
|
95
|
-
VIEW_QUERY_OPS = [
|
96
|
-
|
97
|
-
VIEW_OTHER_OPS = [
|
94
|
+
VIEW_QUERY_OPS = [:delete_one, :delete_many, :count, :distinct, :find_one_and_delete, :find_one_and_update,
|
95
|
+
:replace_one, :update_one, :update_many].freeze
|
96
|
+
VIEW_OTHER_OPS = [:aggregate, :map_reduce ].freeze
|
98
97
|
VIEW_OPS = VIEW_QUERY_OPS + VIEW_OTHER_OPS
|
99
98
|
|
100
99
|
module Mongo
|
@@ -170,7 +169,7 @@ if RUBY_VERSION >= '1.9' && TraceView::Config[:mongo][:enabled]
|
|
170
169
|
#
|
171
170
|
|
172
171
|
# Collection Index View Related Operations
|
173
|
-
INDEX_OPS = [
|
172
|
+
INDEX_OPS = [:create_one, :create_many, :drop_one, :drop_all].freeze
|
174
173
|
|
175
174
|
module Mongo
|
176
175
|
module Index
|
data/lib/traceview/inst/moped.rb
CHANGED
@@ -5,471 +5,462 @@ require 'json'
|
|
5
5
|
|
6
6
|
module TraceView
|
7
7
|
module Inst
|
8
|
+
##
|
9
|
+
# Moped
|
10
|
+
#
|
8
11
|
module Moped
|
9
12
|
FLAVOR = :mongodb
|
10
13
|
|
11
14
|
# Moped::Database
|
12
|
-
DB_OPS = [:command, :drop]
|
15
|
+
DB_OPS = [:command, :drop].freeze
|
13
16
|
|
14
17
|
# Moped::Indexes
|
15
|
-
INDEX_OPS = [:create, :drop]
|
18
|
+
INDEX_OPS = [:create, :drop].freeze
|
16
19
|
|
17
20
|
# Moped::Query
|
18
21
|
QUERY_OPS = [:count, :sort, :limit, :distinct, :update, :update_all, :upsert,
|
19
|
-
:explain, :modify, :remove, :remove_all]
|
22
|
+
:explain, :modify, :remove, :remove_all].freeze
|
20
23
|
|
21
24
|
# Moped::Collection
|
22
|
-
COLLECTION_OPS = [:drop, :find, :indexes, :insert, :aggregate]
|
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
|
23
40
|
end
|
24
|
-
end
|
25
|
-
end
|
26
41
|
|
27
|
-
|
28
|
-
|
42
|
+
##
|
43
|
+
# MopedDatabase
|
44
|
+
#
|
45
|
+
module MopedDatabase
|
46
|
+
include TraceView::Inst::Moped
|
29
47
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
48
|
+
def self.included(klass)
|
49
|
+
TraceView::Inst::Moped::DB_OPS.each do |m|
|
50
|
+
::TraceView::Util.method_alias(klass, m)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def extract_trace_details(op)
|
55
|
+
report_kvs = {}
|
56
|
+
report_kvs[:Flavor] = TraceView::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] = TraceView::API.backtrace if TraceView::Config[:moped][:collect_backtraces]
|
62
|
+
rescue StandardError => e
|
63
|
+
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
64
|
+
ensure
|
65
|
+
return report_kvs
|
66
|
+
end
|
34
67
|
|
35
|
-
|
36
|
-
|
68
|
+
def command_with_traceview(command)
|
69
|
+
if TraceView.tracing? && !TraceView.layer_op && command.key?(:mapreduce)
|
37
70
|
begin
|
38
|
-
report_kvs
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
else
|
44
|
-
report_kvs[:RemoteHost] = "#{first.address.host}:#{first.address.port}"
|
45
|
-
end
|
46
|
-
report_kvs[:Database] = name
|
47
|
-
report_kvs[:QueryOp] = op.to_s
|
48
|
-
report_kvs[:Backtrace] = TraceView::API.backtrace if TraceView::Config[:moped][:collect_backtraces]
|
49
|
-
rescue StandardError => e
|
50
|
-
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" if TraceView::Config[:verbose]
|
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
|
+
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
51
76
|
end
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
def command_with_traceview(command)
|
56
|
-
if TraceView.tracing? && !TraceView.layer_op && command.key?(:mapreduce)
|
57
|
-
begin
|
58
|
-
report_kvs = extract_trace_details(:map_reduce)
|
59
|
-
report_kvs[:Map_Function] = command[:map]
|
60
|
-
report_kvs[:Reduce_Function] = command[:reduce]
|
61
|
-
rescue => e
|
62
|
-
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" if TraceView::Config[:verbose]
|
63
|
-
end
|
64
|
-
|
65
|
-
TraceView::API.trace(:mongo, report_kvs) do
|
66
|
-
command_without_traceview(command)
|
67
|
-
end
|
68
|
-
else
|
77
|
+
|
78
|
+
TraceView::API.trace(:mongo, report_kvs) do
|
69
79
|
command_without_traceview(command)
|
70
80
|
end
|
81
|
+
else
|
82
|
+
command_without_traceview(command)
|
71
83
|
end
|
84
|
+
end
|
72
85
|
|
73
|
-
|
74
|
-
|
86
|
+
def drop_with_traceview
|
87
|
+
return drop_without_traceview unless TraceView.tracing?
|
75
88
|
|
76
|
-
|
89
|
+
report_kvs = extract_trace_details(:drop_database)
|
77
90
|
|
78
|
-
|
79
|
-
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
TraceView::Inst::Moped::DB_OPS.each do |m|
|
84
|
-
if method_defined?(m)
|
85
|
-
class_eval "alias #{m}_without_traceview #{m}"
|
86
|
-
class_eval "alias #{m} #{m}_with_traceview"
|
87
|
-
else TraceView.logger.warn "[traceview/loading] Couldn't properly instrument moped (#{m}). Partial traces may occur."
|
88
|
-
end
|
91
|
+
TraceView::API.trace(:mongo, report_kvs) do
|
92
|
+
drop_without_traceview
|
89
93
|
end
|
90
94
|
end
|
91
95
|
end
|
92
|
-
end
|
93
96
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
97
|
+
##
|
98
|
+
# MopedIndexes
|
99
|
+
#
|
100
|
+
module MopedIndexes
|
101
|
+
include TraceView::Inst::Moped
|
98
102
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
report_kvs[:Flavor] = TraceView::Inst::Moped::FLAVOR
|
103
|
-
|
104
|
-
# FIXME: We're only grabbing the first of potentially multiple servers here
|
105
|
-
first = database.session.cluster.seeds.first
|
106
|
-
if ::Moped::VERSION < '2.0.0'
|
107
|
-
report_kvs[:RemoteHost] = first
|
108
|
-
else
|
109
|
-
report_kvs[:RemoteHost] = "#{first.address.host}:#{first.address.port}"
|
110
|
-
end
|
111
|
-
report_kvs[:Database] = database.name
|
112
|
-
report_kvs[:QueryOp] = op.to_s
|
113
|
-
report_kvs[:Backtrace] = TraceView::API.backtrace if TraceView::Config[:moped][:collect_backtraces]
|
114
|
-
rescue StandardError => e
|
115
|
-
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" if TraceView::Config[:verbose]
|
116
|
-
end
|
117
|
-
report_kvs
|
103
|
+
def self.included(klass)
|
104
|
+
TraceView::Inst::Moped::INDEX_OPS.each do |m|
|
105
|
+
::TraceView::Util.method_alias(klass, m)
|
118
106
|
end
|
107
|
+
end
|
119
108
|
|
120
|
-
|
121
|
-
|
109
|
+
def extract_trace_details(op)
|
110
|
+
report_kvs = {}
|
111
|
+
report_kvs[:Flavor] = TraceView::Inst::Moped::FLAVOR
|
122
112
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
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] = TraceView::API.backtrace if TraceView::Config[:moped][:collect_backtraces]
|
123
|
+
rescue StandardError => e
|
124
|
+
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
125
|
+
ensure
|
126
|
+
return report_kvs
|
127
|
+
end
|
132
128
|
|
133
|
-
|
134
|
-
|
135
|
-
|
129
|
+
def create_with_traceview(key, options = {})
|
130
|
+
return create_without_traceview(key, options) unless TraceView.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
|
+
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
136
140
|
end
|
137
141
|
|
138
|
-
|
139
|
-
|
142
|
+
TraceView::API.trace(:mongo, report_kvs, :create_index) do
|
143
|
+
create_without_traceview(key, options = {})
|
144
|
+
end
|
145
|
+
end
|
140
146
|
|
141
|
-
|
142
|
-
|
143
|
-
# with other mongo implementations
|
144
|
-
report_kvs = extract_trace_details(:drop_indexes)
|
145
|
-
report_kvs[:Key] = key.nil? ? :all : key.to_json
|
146
|
-
rescue StandardError => e
|
147
|
-
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" if TraceView::Config[:verbose]
|
148
|
-
end
|
147
|
+
def drop_with_traceview(key = nil)
|
148
|
+
return drop_without_traceview(key) unless TraceView.tracing?
|
149
149
|
|
150
|
-
|
151
|
-
|
152
|
-
|
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
|
+
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
153
157
|
end
|
154
158
|
|
155
|
-
TraceView::
|
156
|
-
|
157
|
-
class_eval "alias #{m}_without_traceview #{m}"
|
158
|
-
class_eval "alias #{m} #{m}_with_traceview"
|
159
|
-
else TraceView.logger.warn "[traceview/loading] Couldn't properly instrument moped (#{m}). Partial traces may occur."
|
160
|
-
end
|
159
|
+
TraceView::API.trace(:mongo, report_kvs) do
|
160
|
+
drop_without_traceview(key = nil)
|
161
161
|
end
|
162
162
|
end
|
163
163
|
end
|
164
|
-
end
|
165
164
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
165
|
+
##
|
166
|
+
# MopedQuery
|
167
|
+
#
|
168
|
+
module MopedQuery
|
169
|
+
include TraceView::Inst::Moped
|
170
170
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
report_kvs[:Flavor] = TraceView::Inst::Moped::FLAVOR
|
175
|
-
# FIXME: We're only grabbing the first of potentially multiple servers here
|
176
|
-
first = collection.database.session.cluster.seeds.first
|
177
|
-
if ::Moped::VERSION < '2.0.0'
|
178
|
-
report_kvs[:RemoteHost] = first
|
179
|
-
else
|
180
|
-
report_kvs[:RemoteHost] = "#{first.address.host}:#{first.address.port}"
|
181
|
-
end
|
182
|
-
report_kvs[:Database] = collection.database.name
|
183
|
-
report_kvs[:Collection] = collection.name
|
184
|
-
report_kvs[:QueryOp] = op.to_s
|
185
|
-
report_kvs[:Backtrace] = TraceView::API.backtrace if TraceView::Config[:moped][:collect_backtraces]
|
186
|
-
rescue StandardError => e
|
187
|
-
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" if TraceView::Config[:verbose]
|
188
|
-
end
|
189
|
-
report_kvs
|
171
|
+
def self.included(klass)
|
172
|
+
TraceView::Inst::Moped::QUERY_OPS.each do |m|
|
173
|
+
::TraceView::Util.method_alias(klass, m)
|
190
174
|
end
|
175
|
+
end
|
191
176
|
|
192
|
-
|
193
|
-
|
177
|
+
def extract_trace_details(op)
|
178
|
+
report_kvs = {}
|
179
|
+
report_kvs[:Flavor] = TraceView::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] = TraceView::API.backtrace if TraceView::Config[:moped][:collect_backtraces]
|
187
|
+
rescue StandardError => e
|
188
|
+
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
189
|
+
ensure
|
190
|
+
return report_kvs
|
191
|
+
end
|
194
192
|
|
195
|
-
|
196
|
-
|
197
|
-
report_kvs[:Query] = selector.empty? ? :all : selector.to_json
|
198
|
-
rescue StandardError => e
|
199
|
-
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" if TraceView::Config[:verbose]
|
200
|
-
end
|
193
|
+
def count_with_traceview
|
194
|
+
return count_without_traceview unless TraceView.tracing?
|
201
195
|
|
202
|
-
|
203
|
-
|
204
|
-
|
196
|
+
begin
|
197
|
+
report_kvs = extract_trace_details(:count)
|
198
|
+
report_kvs[:Query] = selector.empty? ? :all : selector.to_json
|
199
|
+
rescue StandardError => e
|
200
|
+
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
205
201
|
end
|
206
202
|
|
207
|
-
|
208
|
-
|
203
|
+
TraceView::API.trace(:mongo, report_kvs) do
|
204
|
+
count_without_traceview
|
205
|
+
end
|
206
|
+
end
|
209
207
|
|
210
|
-
|
211
|
-
|
212
|
-
report_kvs[:Query] = selector.empty? ? :all : selector.to_json
|
213
|
-
report_kvs[:Order] = sort.to_s
|
214
|
-
rescue StandardError => e
|
215
|
-
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" if TraceView::Config[:verbose]
|
216
|
-
end
|
208
|
+
def sort_with_traceview(sort)
|
209
|
+
return sort_without_traceview(sort) unless TraceView.tracing?
|
217
210
|
|
218
|
-
|
219
|
-
|
220
|
-
|
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
|
+
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
221
217
|
end
|
222
218
|
|
223
|
-
|
224
|
-
|
225
|
-
begin
|
226
|
-
report_kvs = extract_trace_details(:limit)
|
227
|
-
report_kvs[:Query] = selector.empty? ? :all : selector.to_json
|
228
|
-
report_kvs[:Limit] = limit.to_s
|
229
|
-
rescue StandardError => e
|
230
|
-
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" if TraceView::Config[:verbose]
|
231
|
-
end
|
232
|
-
|
233
|
-
TraceView::API.trace(:mongo, report_kvs) do
|
234
|
-
limit_without_traceview(limit)
|
235
|
-
end
|
236
|
-
else
|
237
|
-
limit_without_traceview(limit)
|
238
|
-
end
|
219
|
+
TraceView::API.trace(:mongo, report_kvs) do
|
220
|
+
sort_without_traceview(sort)
|
239
221
|
end
|
222
|
+
end
|
240
223
|
|
241
|
-
|
242
|
-
|
243
|
-
|
224
|
+
def limit_with_traceview(limit)
|
225
|
+
if TraceView.tracing? && !TraceView.tracing_layer_op?(:explain)
|
244
226
|
begin
|
245
|
-
report_kvs = extract_trace_details(:
|
227
|
+
report_kvs = extract_trace_details(:limit)
|
246
228
|
report_kvs[:Query] = selector.empty? ? :all : selector.to_json
|
247
|
-
report_kvs[:
|
229
|
+
report_kvs[:Limit] = limit.to_s
|
248
230
|
rescue StandardError => e
|
249
|
-
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
231
|
+
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
250
232
|
end
|
251
233
|
|
252
234
|
TraceView::API.trace(:mongo, report_kvs) do
|
253
|
-
|
235
|
+
limit_without_traceview(limit)
|
254
236
|
end
|
237
|
+
else
|
238
|
+
limit_without_traceview(limit)
|
255
239
|
end
|
240
|
+
end
|
256
241
|
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
TraceView::API.trace(:mongo, report_kvs) do
|
268
|
-
update_without_traceview(change, flags)
|
269
|
-
end
|
270
|
-
else
|
271
|
-
update_without_traceview(change, flags)
|
272
|
-
end
|
242
|
+
def distinct_with_traceview(key)
|
243
|
+
return distinct_without_traceview(key) unless TraceView.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
|
+
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
273
251
|
end
|
274
252
|
|
275
|
-
|
276
|
-
|
253
|
+
TraceView::API.trace(:mongo, report_kvs) do
|
254
|
+
distinct_without_traceview(key)
|
255
|
+
end
|
256
|
+
end
|
277
257
|
|
258
|
+
def update_with_traceview(change, flags = nil)
|
259
|
+
if TraceView.tracing? && !TraceView.tracing_layer_op?([:update_all, :upsert])
|
278
260
|
begin
|
279
|
-
report_kvs = extract_trace_details(:
|
261
|
+
report_kvs = extract_trace_details(:update)
|
262
|
+
report_kvs[:Flags] = flags.to_s if flags
|
280
263
|
report_kvs[:Update_Document] = change.to_json
|
281
264
|
rescue StandardError => e
|
282
|
-
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
265
|
+
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
283
266
|
end
|
284
267
|
|
285
|
-
TraceView::API.trace(:mongo, report_kvs
|
286
|
-
|
268
|
+
TraceView::API.trace(:mongo, report_kvs) do
|
269
|
+
update_without_traceview(change, flags)
|
287
270
|
end
|
271
|
+
else
|
272
|
+
update_without_traceview(change, flags)
|
288
273
|
end
|
274
|
+
end
|
289
275
|
|
290
|
-
|
291
|
-
|
276
|
+
def update_all_with_traceview(change)
|
277
|
+
return update_all_without_traceview(change) unless TraceView.tracing?
|
292
278
|
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
end
|
279
|
+
begin
|
280
|
+
report_kvs = extract_trace_details(:update_all)
|
281
|
+
report_kvs[:Update_Document] = change.to_json
|
282
|
+
rescue StandardError => e
|
283
|
+
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
284
|
+
end
|
300
285
|
|
301
|
-
|
302
|
-
|
303
|
-
end
|
286
|
+
TraceView::API.trace(:mongo, report_kvs, :update_all) do
|
287
|
+
update_all_without_traceview(change)
|
304
288
|
end
|
289
|
+
end
|
305
290
|
|
306
|
-
|
307
|
-
|
291
|
+
def upsert_with_traceview(change)
|
292
|
+
return upsert_without_traceview(change) unless TraceView.tracing?
|
308
293
|
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
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
|
+
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
300
|
+
end
|
315
301
|
|
316
|
-
|
317
|
-
|
318
|
-
end
|
302
|
+
TraceView::API.trace(:mongo, report_kvs, :upsert) do
|
303
|
+
upsert_without_traceview(change)
|
319
304
|
end
|
305
|
+
end
|
320
306
|
|
321
|
-
|
322
|
-
|
307
|
+
def explain_with_traceview
|
308
|
+
return explain_without_traceview unless TraceView.tracing?
|
323
309
|
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" if TraceView::Config[:verbose]
|
331
|
-
end
|
310
|
+
begin
|
311
|
+
report_kvs = extract_trace_details(:explain)
|
312
|
+
report_kvs[:Query] = selector.empty? ? :all : selector.to_json
|
313
|
+
rescue StandardError => e
|
314
|
+
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
315
|
+
end
|
332
316
|
|
333
|
-
|
334
|
-
|
335
|
-
end
|
317
|
+
TraceView::API.trace(:mongo, report_kvs, :explain) do
|
318
|
+
explain_without_traceview
|
336
319
|
end
|
320
|
+
end
|
337
321
|
|
338
|
-
|
339
|
-
|
322
|
+
def modify_with_traceview(change, options = {})
|
323
|
+
return modify_without_traceview(change, options) unless TraceView.tracing?
|
340
324
|
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
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
|
+
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
332
|
+
end
|
347
333
|
|
348
|
-
|
349
|
-
|
350
|
-
end
|
334
|
+
TraceView::API.trace(:mongo, report_kvs) do
|
335
|
+
modify_without_traceview(change, options)
|
351
336
|
end
|
337
|
+
end
|
352
338
|
|
353
|
-
|
354
|
-
|
339
|
+
def remove_with_traceview
|
340
|
+
return remove_without_traceview unless TraceView.tracing?
|
355
341
|
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
342
|
+
begin
|
343
|
+
report_kvs = extract_trace_details(:remove)
|
344
|
+
report_kvs[:Query] = selector.to_json
|
345
|
+
rescue StandardError => e
|
346
|
+
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
347
|
+
end
|
362
348
|
|
363
|
-
|
364
|
-
|
365
|
-
|
349
|
+
TraceView::API.trace(:mongo, report_kvs) do
|
350
|
+
remove_without_traceview
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
def remove_all_with_traceview
|
355
|
+
return remove_all_without_traceview unless TraceView.tracing?
|
356
|
+
|
357
|
+
begin
|
358
|
+
report_kvs = extract_trace_details(:remove_all)
|
359
|
+
report_kvs[:Query] = selector.to_json
|
360
|
+
rescue StandardError => e
|
361
|
+
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
366
362
|
end
|
367
363
|
|
368
|
-
TraceView::
|
369
|
-
|
370
|
-
class_eval "alias #{m}_without_traceview #{m}"
|
371
|
-
class_eval "alias #{m} #{m}_with_traceview"
|
372
|
-
else TraceView.logger.warn "[traceview/loading] Couldn't properly instrument moped (#{m}). Partial traces may occur."
|
373
|
-
end
|
364
|
+
TraceView::API.trace(:mongo, report_kvs) do
|
365
|
+
remove_all_without_traceview
|
374
366
|
end
|
375
367
|
end
|
376
368
|
end
|
377
|
-
end # ::Moped::Query
|
378
369
|
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
370
|
+
##
|
371
|
+
# MopedCollection
|
372
|
+
#
|
373
|
+
module MopedCollection
|
374
|
+
include TraceView::Inst::Moped
|
383
375
|
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
report_kvs[:Flavor] = TraceView::Inst::Moped::FLAVOR
|
388
|
-
# FIXME: We're only grabbing the first of potentially multiple servers here
|
389
|
-
first = database.session.cluster.seeds.first
|
390
|
-
if ::Moped::VERSION < '2.0.0'
|
391
|
-
report_kvs[:RemoteHost] = first
|
392
|
-
else
|
393
|
-
report_kvs[:RemoteHost] = "#{first.address.host}:#{first.address.port}"
|
394
|
-
end
|
395
|
-
report_kvs[:Database] = database.name
|
396
|
-
report_kvs[:Collection] = name
|
397
|
-
report_kvs[:QueryOp] = op.to_s
|
398
|
-
report_kvs[:Backtrace] = TraceView::API.backtrace if TraceView::Config[:moped][:collect_backtraces]
|
399
|
-
rescue StandardError => e
|
400
|
-
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" if TraceView::Config[:verbose]
|
401
|
-
end
|
402
|
-
report_kvs
|
376
|
+
def self.included(klass)
|
377
|
+
TraceView::Inst::Moped::COLLECTION_OPS.each do |m|
|
378
|
+
::TraceView::Util.method_alias(klass, m)
|
403
379
|
end
|
380
|
+
end
|
404
381
|
|
405
|
-
|
406
|
-
|
382
|
+
def extract_trace_details(op)
|
383
|
+
report_kvs = {}
|
384
|
+
report_kvs[:Flavor] = TraceView::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] = TraceView::API.backtrace if TraceView::Config[:moped][:collect_backtraces]
|
391
|
+
rescue StandardError => e
|
392
|
+
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
393
|
+
ensure
|
394
|
+
return report_kvs
|
395
|
+
end
|
407
396
|
|
408
|
-
|
409
|
-
|
410
|
-
report_kvs = extract_trace_details(:drop_collection)
|
397
|
+
def drop_with_traceview
|
398
|
+
return drop_without_traceview unless TraceView.tracing?
|
411
399
|
|
412
|
-
|
413
|
-
|
414
|
-
|
400
|
+
# We report :drop_collection here to be consistent
|
401
|
+
# with other mongo implementations
|
402
|
+
report_kvs = extract_trace_details(:drop_collection)
|
403
|
+
|
404
|
+
TraceView::API.trace(:mongo, report_kvs) do
|
405
|
+
drop_without_traceview
|
415
406
|
end
|
407
|
+
end
|
416
408
|
|
417
|
-
|
418
|
-
|
409
|
+
def find_with_traceview(selector = {})
|
410
|
+
return find_without_traceview(selector) unless TraceView.tracing?
|
419
411
|
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
412
|
+
begin
|
413
|
+
report_kvs = extract_trace_details(:find)
|
414
|
+
report_kvs[:Query] = selector.empty? ? 'all' : selector.to_json
|
415
|
+
rescue StandardError => e
|
416
|
+
TraceView.logger.debug "[traceview/debug] #{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}"
|
417
|
+
end
|
426
418
|
|
427
|
-
|
428
|
-
|
429
|
-
end
|
419
|
+
TraceView::API.trace(:mongo, report_kvs) do
|
420
|
+
find_without_traceview(selector)
|
430
421
|
end
|
422
|
+
end
|
431
423
|
|
432
|
-
|
433
|
-
|
424
|
+
def indexes_with_traceview
|
425
|
+
return indexes_without_traceview unless TraceView.tracing?
|
434
426
|
|
435
|
-
|
427
|
+
report_kvs = extract_trace_details(:indexes)
|
436
428
|
|
437
|
-
|
438
|
-
|
439
|
-
end
|
429
|
+
TraceView::API.trace(:mongo, report_kvs) do
|
430
|
+
indexes_without_traceview
|
440
431
|
end
|
432
|
+
end
|
441
433
|
|
442
|
-
|
443
|
-
|
444
|
-
|
434
|
+
def insert_with_traceview(documents, flags = nil)
|
435
|
+
if TraceView.tracing? && !TraceView.tracing_layer_op?(:create_index)
|
436
|
+
report_kvs = extract_trace_details(:insert)
|
445
437
|
|
446
|
-
|
447
|
-
insert_without_traceview(documents, flags)
|
448
|
-
end
|
449
|
-
else
|
438
|
+
TraceView::API.trace(:mongo, report_kvs) do
|
450
439
|
insert_without_traceview(documents, flags)
|
451
440
|
end
|
441
|
+
else
|
442
|
+
insert_without_traceview(documents, flags)
|
452
443
|
end
|
444
|
+
end
|
453
445
|
|
454
|
-
|
455
|
-
|
446
|
+
def aggregate_with_traceview(*pipeline)
|
447
|
+
return aggregate_without_traceview(*pipeline) unless TraceView.tracing?
|
456
448
|
|
457
|
-
|
458
|
-
|
449
|
+
report_kvs = extract_trace_details(:aggregate)
|
450
|
+
report_kvs[:Query] = pipeline
|
459
451
|
|
460
|
-
|
461
|
-
|
462
|
-
end
|
463
|
-
end
|
464
|
-
|
465
|
-
TraceView::Inst::Moped::COLLECTION_OPS.each do |m|
|
466
|
-
if method_defined?(m)
|
467
|
-
class_eval "alias #{m}_without_traceview #{m}"
|
468
|
-
class_eval "alias #{m} #{m}_with_traceview"
|
469
|
-
else TraceView.logger.warn "[traceview/loading] Couldn't properly instrument moped (#{m}). Partial traces may occur."
|
470
|
-
end
|
452
|
+
TraceView::API.trace(:mongo, report_kvs) do
|
453
|
+
aggregate_without_traceview(pipeline)
|
471
454
|
end
|
472
455
|
end
|
473
456
|
end
|
474
|
-
end
|
457
|
+
end
|
458
|
+
end
|
459
|
+
|
460
|
+
if defined?(::Moped) && TraceView::Config[:moped][:enabled]
|
461
|
+
::TraceView.logger.info '[traceview/loading] Instrumenting moped' if TraceView::Config[:verbose]
|
462
|
+
::TraceView::Util.send_include(::Moped::Database, ::TraceView::Inst::MopedDatabase)
|
463
|
+
::TraceView::Util.send_include(::Moped::Collection, ::TraceView::Inst::MopedCollection)
|
464
|
+
::TraceView::Util.send_include(::Moped::Query, ::TraceView::Inst::MopedQuery)
|
465
|
+
::TraceView::Util.send_include(::Moped::Indexes, ::TraceView::Inst::MopedIndexes)
|
475
466
|
end
|