oboe 1.3.3 → 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/oboe/frameworks/rails/inst/mongo.rb +225 -0
- data/lib/oboe/version.rb +1 -1
- metadata +2 -1
@@ -0,0 +1,225 @@
|
|
1
|
+
# Copyright (c) 2012 by Tracelytics, Inc.
|
2
|
+
# All rights reserved.
|
3
|
+
|
4
|
+
module Oboe
|
5
|
+
module Inst
|
6
|
+
module Mongo
|
7
|
+
FLAVOR = 'mongodb'
|
8
|
+
|
9
|
+
# Operations for Mongo::DB
|
10
|
+
DB_OPS = [ :create_collection, :drop_collection ]
|
11
|
+
|
12
|
+
# Operations for Mongo::Cursor
|
13
|
+
CURSOR_OPS = [ :count ]
|
14
|
+
|
15
|
+
# Operations for Mongo::Collection
|
16
|
+
COLL_WRITE_OPS = [ :find_and_modify, :insert, :map_reduce, :remove, :rename, :update ]
|
17
|
+
COLL_QUERY_OPS = [ :distinct, :find, :group ]
|
18
|
+
COLL_INDEX_OPS = [ :create_index, :drop_index, :drop_indexes, :ensure_index, :index_information ]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
if defined?(::Mongo::DB)
|
24
|
+
module ::Mongo
|
25
|
+
class DB
|
26
|
+
include Oboe::Inst::Mongo
|
27
|
+
|
28
|
+
# Instrument DB operations
|
29
|
+
Oboe::Inst::Mongo::DB_OPS.reject { |m| not method_defined?(m) }.each do |m|
|
30
|
+
define_method("#{m}_with_oboe") do |*args|
|
31
|
+
report_kvs = {}
|
32
|
+
|
33
|
+
begin
|
34
|
+
report_kvs[:Flavor] = Oboe::Inst::Mongo::FLAVOR
|
35
|
+
|
36
|
+
report_kvs[:Database] = @name
|
37
|
+
report_kvs[:RemoteHost] = @connection.host
|
38
|
+
report_kvs[:RemotePort] = @connection.port
|
39
|
+
|
40
|
+
report_kvs[:QueryOp] = m
|
41
|
+
|
42
|
+
report_kvs[:New_Collection_Name] = args[0] if m == :create_collection
|
43
|
+
report_kvs[:Collection_Name] = args[0] if m == :drop_collection
|
44
|
+
rescue
|
45
|
+
logger.warn "[oboe/error] Problem processing mongo args (#{m})" if defined?(logger)
|
46
|
+
end
|
47
|
+
|
48
|
+
Oboe::API.trace('mongo', report_kvs) do
|
49
|
+
send("#{m}_without_oboe", *args)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
class_eval "alias #{m}_without_oboe #{m}"
|
54
|
+
class_eval "alias #{m} #{m}_with_oboe"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
if defined?(::Mongo::Cursor)
|
61
|
+
module ::Mongo
|
62
|
+
class Cursor
|
63
|
+
include Oboe::Inst::Mongo
|
64
|
+
|
65
|
+
# Instrument DB cursor operations
|
66
|
+
Oboe::Inst::Mongo::CURSOR_OPS.reject { |m| not method_defined?(m) }.each do |m|
|
67
|
+
define_method("#{m}_with_oboe") do |*args|
|
68
|
+
report_kvs = {}
|
69
|
+
|
70
|
+
begin
|
71
|
+
report_kvs[:Flavor] = Oboe::Inst::Mongo::FLAVOR
|
72
|
+
|
73
|
+
report_kvs[:Database] = @db.name
|
74
|
+
report_kvs[:RemoteHost] = @connection.host
|
75
|
+
report_kvs[:RemotePort] = @connection.port
|
76
|
+
|
77
|
+
report_kvs[:QueryOp] = m
|
78
|
+
if m == :count
|
79
|
+
unless @selector.empty?
|
80
|
+
report_kvs[:Query] = @selector.try(:to_json)
|
81
|
+
else
|
82
|
+
report_kvs[:Query] = 'all'
|
83
|
+
end
|
84
|
+
report_kvs[:limit] = @limit if @limit != 0
|
85
|
+
end
|
86
|
+
|
87
|
+
rescue
|
88
|
+
logger.warn "[oboe/error] Problem processing mongo args (#{m})" if defined?(logger)
|
89
|
+
end
|
90
|
+
|
91
|
+
Oboe::API.trace('mongo', report_kvs) do
|
92
|
+
send("#{m}_without_oboe", *args)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
class_eval "alias #{m}_without_oboe #{m}"
|
97
|
+
class_eval "alias #{m} #{m}_with_oboe"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
if defined?(::Mongo::Collection)
|
104
|
+
module ::Mongo
|
105
|
+
class Collection
|
106
|
+
include Oboe::Inst::Mongo
|
107
|
+
|
108
|
+
def oboe_collect(m, args)
|
109
|
+
report_kvs = {}
|
110
|
+
report_kvs[:Flavor] = Oboe::Inst::Mongo::FLAVOR
|
111
|
+
|
112
|
+
report_kvs[:Database] = @db.name
|
113
|
+
report_kvs[:RemoteHost] = @db.connection.host
|
114
|
+
report_kvs[:RemotePort] = @db.connection.port
|
115
|
+
report_kvs[:Collection] = @name
|
116
|
+
|
117
|
+
report_kvs[:QueryOp] = m
|
118
|
+
report_kvs[:Query] = args[0].try(:to_json) if args and not args.empty? and args[0].class == Hash
|
119
|
+
report_kvs
|
120
|
+
end
|
121
|
+
|
122
|
+
# Instrument Collection write operations
|
123
|
+
Oboe::Inst::Mongo::COLL_WRITE_OPS.reject { |m| not method_defined?(m) }.each do |m|
|
124
|
+
define_method("#{m}_with_oboe") do |*args|
|
125
|
+
report_kvs = oboe_collect(m, args)
|
126
|
+
args_length = args.length
|
127
|
+
|
128
|
+
begin
|
129
|
+
if m == :find_and_modify and args[0] and args[0].has_key?(:update)
|
130
|
+
report_kvs[:Update_Document] = args[0][:update]
|
131
|
+
end
|
132
|
+
|
133
|
+
if m == :map_reduce
|
134
|
+
report_kvs[:Map_Function] = args[0]
|
135
|
+
report_kvs[:Reduce_Function] = args[1]
|
136
|
+
report_kvs[:limit] = args[2][:limit] if args[2] and args[2].has_key?(:limit)
|
137
|
+
end
|
138
|
+
|
139
|
+
report_kvs[:New_Collection_Name] = args[0] if m == :rename
|
140
|
+
|
141
|
+
if m == :update
|
142
|
+
if args_length >= 3
|
143
|
+
report_kvs[:Update_Document] = args[1].try(:to_json)
|
144
|
+
report_kvs[:Multi] = args[2][:multi] if args[2] and args[2].has_key?(:multi)
|
145
|
+
end
|
146
|
+
end
|
147
|
+
rescue
|
148
|
+
logger.warn "[oboe/error] Problem processing mongo args (#{m})" if defined?(logger)
|
149
|
+
end
|
150
|
+
|
151
|
+
Oboe::API.trace('mongo', report_kvs) do
|
152
|
+
send("#{m}_without_oboe", *args)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
class_eval "alias #{m}_without_oboe #{m}"
|
157
|
+
class_eval "alias #{m} #{m}_with_oboe"
|
158
|
+
end
|
159
|
+
|
160
|
+
# Instrument Collection query operations
|
161
|
+
Oboe::Inst::Mongo::COLL_QUERY_OPS.reject { |m| not method_defined?(m) }.each do |m|
|
162
|
+
define_method("#{m}_with_oboe") do |*args|
|
163
|
+
begin
|
164
|
+
report_kvs = oboe_collect(m, args)
|
165
|
+
args_length = args.length
|
166
|
+
|
167
|
+
if m == :distinct and args_length >= 2
|
168
|
+
report_kvs[:key] = args[0]
|
169
|
+
report_kvs[:Query] = args[1].try(:to_json) if args[1] and args[1].class == Hash
|
170
|
+
end
|
171
|
+
|
172
|
+
if m == :find and args_length > 0
|
173
|
+
report_kvs[:limit] = args[0][:limit] if !args[0].nil? and args[0].has_key?(:limit)
|
174
|
+
end
|
175
|
+
|
176
|
+
if m == :group
|
177
|
+
unless args.empty?
|
178
|
+
if args[0].is_a?(Hash)
|
179
|
+
report_kvs[:Group_Key] = args[0][:key].try(:to_json) if args[0].has_key?(:key)
|
180
|
+
report_kvs[:Group_Condition] = args[0][:cond].try(:to_json) if args[0].has_key?(:cond)
|
181
|
+
report_kvs[:Group_Initial] = args[0][:initial].try(:to_json) if args[0].has_key?(:initial)
|
182
|
+
report_kvs[:Group_Reduce] = args[0][:reduce] if args[0].has_key?(:reduce)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
rescue
|
187
|
+
logger.warn "[oboe/error] Problem processing mongo args (#{m})" if defined?(logger)
|
188
|
+
end
|
189
|
+
|
190
|
+
Oboe::API.trace('mongo', report_kvs) do
|
191
|
+
send("#{m}_without_oboe", *args)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
class_eval "alias #{m}_without_oboe #{m}"
|
196
|
+
class_eval "alias #{m} #{m}_with_oboe"
|
197
|
+
end
|
198
|
+
|
199
|
+
# Instrument Collection index operations
|
200
|
+
Oboe::Inst::Mongo::COLL_INDEX_OPS.reject { |m| not method_defined?(m) }.each do |m|
|
201
|
+
define_method("#{m}_with_oboe") do |*args|
|
202
|
+
report_kvs = oboe_collect(m, args)
|
203
|
+
_args = args || []
|
204
|
+
|
205
|
+
begin
|
206
|
+
if [:create_index, :ensure_index, :drop_index].include? m and not _args.empty?
|
207
|
+
report_kvs[:Index] = _args[0].try(:to_json)
|
208
|
+
end
|
209
|
+
rescue
|
210
|
+
logger.warn "[oboe/error] Problem processing mongo args (#{m})" if defined?(logger)
|
211
|
+
end
|
212
|
+
|
213
|
+
Oboe::API.trace('mongo', report_kvs) do
|
214
|
+
send("#{m}_without_oboe", *args)
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
class_eval "alias #{m}_without_oboe #{m}"
|
219
|
+
class_eval "alias #{m} #{m}_with_oboe"
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
puts "[oboe/loading] Instrumenting mongo" if Oboe::Config[:verbose]
|
224
|
+
end
|
225
|
+
|
data/lib/oboe/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oboe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -31,6 +31,7 @@ files:
|
|
31
31
|
- lib/oboe/version.rb
|
32
32
|
- lib/oboe/config.rb
|
33
33
|
- lib/oboe/frameworks/rails/inst/memcache.rb
|
34
|
+
- lib/oboe/frameworks/rails/inst/mongo.rb
|
34
35
|
- lib/oboe/frameworks/rails/inst/http.rb
|
35
36
|
- lib/oboe/frameworks/rails/inst/rack.rb
|
36
37
|
- lib/oboe/frameworks/rails/inst/action_controller.rb
|