oboe 1.3.4 → 1.3.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,7 @@
2
2
  # All rights reserved.
3
3
 
4
4
  require 'mkmf'
5
+ dir_config('oboe')
5
6
 
6
7
  if have_library('oboe')
7
8
  $libs = append_library($libs, "oboe")
@@ -82,11 +82,13 @@ module Oboe
82
82
  xtrace
83
83
  end
84
84
 
85
- def log_entry(layer, opts={})
85
+ def log_entry(layer, opts={}, protect_op=false)
86
+ Oboe::Context.layer_op = opts[:Op] if protect_op and opts.has_key?(:Op)
86
87
  log_event(layer, 'entry', Oboe::Context.createEvent, opts)
87
88
  end
88
89
 
89
- def log_exit(layer, opts={})
90
+ def log_exit(layer, opts={}, protect_op=false)
91
+ Oboe::Context.layer_op = nil if protect_op
90
92
  log_event(layer, 'exit', Oboe::Context.createEvent, opts)
91
93
  end
92
94
 
@@ -10,7 +10,7 @@ module Oboe
10
10
  #
11
11
  # layer - The layer the block of code belongs to.
12
12
  # opts - A hash containing key/value pairs that will be reported along
13
- # with the first event of this layer (optional).
13
+ # with the first event of this layer (optional).
14
14
  #
15
15
  # Example
16
16
  #
@@ -28,18 +28,18 @@ module Oboe
28
28
  # result = computation_with_oboe(1000)
29
29
  #
30
30
  # Returns the result of the block.
31
- def trace(layer, opts={})
32
- log_entry(layer, opts)
31
+ def trace(layer, opts={}, protect_op=false)
32
+ log_entry(layer, opts, protect_op)
33
33
  begin
34
34
  yield
35
35
  rescue Exception => e
36
36
  log_exception(layer, e)
37
37
  raise
38
38
  ensure
39
- log_exit(layer)
39
+ log_exit(layer, {}, protect_op)
40
40
  end
41
41
  end
42
-
42
+
43
43
  # Public: Trace a given block of code which can start a trace depending
44
44
  # on configuration and probability. Detect any exceptions thrown by the
45
45
  # block and report errors.
@@ -49,7 +49,7 @@ module Oboe
49
49
  #
50
50
  # layer - The layer the block of code belongs to.
51
51
  # opts - A hash containing key/value pairs that will be reported along
52
- # with the first event of this layer (optional).
52
+ # with the first event of this layer (optional).
53
53
  #
54
54
  # Example
55
55
  #
@@ -89,7 +89,7 @@ module Oboe
89
89
  # on configuration and probability. Detect any exceptions thrown by the
90
90
  # block and report errors. Insert the oboe metadata into the provided for
91
91
  # later user.
92
- #
92
+ #
93
93
  # The motivating use case for this is HTTP streaming in rails3. We need
94
94
  # access to the exit event's trace id so we can set the header before any
95
95
  # work is done, and before any headers are sent back to the client.
@@ -97,7 +97,7 @@ module Oboe
97
97
  # layer - The layer the block of code belongs to.
98
98
  # target - The target object in which to place the oboe metadata.
99
99
  # opts - A hash containing key/value pairs that will be reported along
100
- # with the first event of this layer (optional).
100
+ # with the first event of this layer (optional).
101
101
  #
102
102
  # Example:
103
103
  #
@@ -9,7 +9,8 @@ module Oboe
9
9
  opts = {}
10
10
 
11
11
  opts[:Query] = sql.to_s
12
- opts[:Name] = name.to_s if name
12
+ opts[:Name] = name.to_s if name
13
+ opts[:Backtrace] = Oboe::API.backtrace
13
14
 
14
15
  if defined?(ActiveRecord::Base.connection.cfg)
15
16
  opts[:Database] = ActiveRecord::Base.connection.cfg[:database]
@@ -0,0 +1,301 @@
1
+ # Copyright (c) 2012 by Tracelytics, Inc.
2
+ # All rights reserved.
3
+
4
+ module Oboe
5
+ module Inst
6
+ module Cassandra
7
+ def extract_trace_details(op, column_family, keys, args, options = {})
8
+ report_kvs = {}
9
+
10
+ begin
11
+ report_kvs[:Op] = op.to_s
12
+ report_kvs[:Cf] = column_family.to_s
13
+ report_kvs[:Key] = keys.to_s if keys
14
+
15
+ # Open issue - how to handle multiple Cassandra servers
16
+ report_kvs[:RemoteHost], report_kvs[:RemotePort] = @servers.first.split(":")
17
+
18
+ if options.empty? and args.is_a?(Array)
19
+ options = args.last if args.last.is_a?(Hash)
20
+ end
21
+
22
+ unless options.empty?
23
+ [:start_key, :finish_key, :key_count, :batch_size, :columns, :count, :start,
24
+ :stop, :finish, :finished, :reversed, :consistency, :ttl].each do |k|
25
+ report_kvs[k.capitalize] = options[k] if options.has_key?(k)
26
+ end
27
+
28
+ if op == :get_indexed_slices
29
+ index_clause = columns_and_options[:index_clause] || {}
30
+ unless index_clause.empty?
31
+ [:column_name, :value, :comparison].each do |k|
32
+ report_kvs[k.capitalize] = index_clause[k] if index_clause.has_key?(k)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ rescue
38
+ end
39
+
40
+ report_kvs
41
+ end
42
+
43
+ def insert_with_oboe(column_family, key, hash, options = {})
44
+ if Oboe::Config.tracing?
45
+ report_kvs = extract_trace_details(:insert, column_family, key, hash, options)
46
+
47
+ Oboe::API.trace('cassandra', report_kvs) do
48
+ insert_without_oboe(column_family, key, hash, options = {})
49
+ end
50
+ else
51
+ insert_without_oboe(column_family, key, hash, options = {})
52
+ end
53
+ end
54
+
55
+ def remove_with_oboe(column_family, key, *columns_and_options)
56
+ args = [column_family, key] + columns_and_options
57
+
58
+ if Oboe::Config.tracing?
59
+ report_kvs = extract_trace_details(:remove, column_family, key, columns_and_options)
60
+
61
+ Oboe::API.trace('cassandra', report_kvs) do
62
+ send :remove_without_oboe, *args
63
+ end
64
+ else
65
+ send :remove_without_oboe, *args
66
+ end
67
+ end
68
+
69
+ def count_columns_with_oboe(column_family, key, *columns_and_options)
70
+ args = [column_family, key] + columns_and_options
71
+
72
+ if Oboe::Config.tracing?
73
+ report_kvs = extract_trace_details(:count_columns, column_family, key, columns_and_options)
74
+
75
+ Oboe::API.trace('cassandra', report_kvs) do
76
+ send :count_columns_without_oboe, *args
77
+ end
78
+ else
79
+ send :count_columns_without_oboe, *args
80
+ end
81
+ end
82
+
83
+ def get_columns_with_oboe(column_family, key, *columns_and_options)
84
+ args = [column_family, key] + columns_and_options
85
+
86
+ if Oboe::Config.tracing? and not Oboe::Context.layer_op?(:multi_get_columns)
87
+ report_kvs = extract_trace_details(:get_columns, column_family, key, columns_and_options)
88
+
89
+ Oboe::API.trace('cassandra', report_kvs) do
90
+ send :get_columns_without_oboe, *args
91
+ end
92
+ else
93
+ send :get_columns_without_oboe, *args
94
+ end
95
+ end
96
+
97
+ def multi_get_columns_with_oboe(column_family, key, *columns_and_options)
98
+ args = [column_family, key] + columns_and_options
99
+
100
+ if Oboe::Config.tracing?
101
+ report_kvs = extract_trace_details(:multi_get_columns, column_family, key, columns_and_options)
102
+
103
+ Oboe::API.trace('cassandra', report_kvs, true) do
104
+ send :multi_get_columns_without_oboe, *args
105
+ end
106
+ else
107
+ send :multi_get_columns_without_oboe, *args
108
+ end
109
+ end
110
+
111
+ def get_with_oboe(column_family, key, *columns_and_options)
112
+ args = [column_family, key] + columns_and_options
113
+
114
+ if Oboe::Config.tracing?
115
+ report_kvs = extract_trace_details(:get, column_family, key, columns_and_options)
116
+
117
+ Oboe::API.trace('cassandra', report_kvs, true) do
118
+ send :get_without_oboe, *args
119
+ end
120
+ else
121
+ send :get_without_oboe, *args
122
+ end
123
+ end
124
+
125
+ def multi_get_with_oboe(column_family, key, *columns_and_options)
126
+ args = [column_family, key] + columns_and_options
127
+
128
+ if Oboe::Config.tracing? and not Oboe::Context.layer_op?(:get)
129
+ report_kvs = extract_trace_details(:multi_get, column_family, key, columns_and_options)
130
+
131
+ Oboe::API.trace('cassandra', report_kvs) do
132
+ send :multi_get_without_oboe, *args
133
+ end
134
+ else
135
+ send :multi_get_without_oboe, *args
136
+ end
137
+ end
138
+
139
+ def exists_with_oboe?(column_family, key, *columns_and_options)
140
+ args = [column_family, key] + columns_and_options
141
+
142
+ if Oboe::Config.tracing?
143
+ report_kvs = extract_trace_details(:exists?, column_family, key, columns_and_options)
144
+
145
+ Oboe::API.trace('cassandra', report_kvs) do
146
+ send :exists_without_oboe?, *args
147
+ end
148
+ else
149
+ send :exists_without_oboe?, *args
150
+ end
151
+ end
152
+
153
+ def get_range_single_with_oboe(column_family, options = {})
154
+ if Oboe::Config.tracing? and not Oboe::Context.layer_op?(:get_range_batch)
155
+ report_kvs = extract_trace_details(:get_range_single, column_family, nil, nil)
156
+ args = [column_family, options]
157
+
158
+ Oboe::API.trace('cassandra', report_kvs) do
159
+ get_range_single_without_oboe(column_family, options)
160
+ end
161
+ else
162
+ get_range_single_without_oboe(column_family, options)
163
+ end
164
+ end
165
+
166
+ def get_range_batch_with_oboe(column_family, options = {})
167
+ if Oboe::Config.tracing?
168
+ report_kvs = extract_trace_details(:get_range_batch, column_family, nil, nil)
169
+ args = [column_family, options]
170
+
171
+ Oboe::API.trace('cassandra', report_kvs, true) do
172
+ get_range_batch_without_oboe(column_family, options)
173
+ end
174
+ else
175
+ get_range_batch_without_oboe(column_family, options)
176
+ end
177
+ end
178
+
179
+ def get_indexed_slices_with_oboe(column_family, index_clause, *columns_and_options)
180
+ args = [column_family, index_clause] + columns_and_options
181
+
182
+ if Oboe::Config.tracing?
183
+ report_kvs = extract_trace_details(:get_indexed_slices, column_family, nil, columns_and_options)
184
+
185
+ Oboe::API.trace('cassandra', report_kvs) do
186
+ send :get_indexed_slices_without_oboe, *args
187
+ end
188
+ else
189
+ send :get_indexed_slices_without_oboe, *args
190
+ end
191
+ end
192
+
193
+ def create_index_with_oboe(keyspace, column_family, column_name, validation_class)
194
+ if Oboe::Config.tracing?
195
+ report_kvs = extract_trace_details(:create_index, column_family, nil, nil)
196
+ report_kvs[:Keyspace] = keyspace.to_s
197
+ report_kvs[:Column_name] = column_name.to_s
198
+ report_kvs[:Validation_class] = validation_class.to_s
199
+
200
+ Oboe::API.trace('cassandra', report_kvs) do
201
+ create_index_without_oboe(keyspace, column_family, column_name, validation_class)
202
+ end
203
+ else
204
+ create_index_without_oboe(keyspace, column_family, column_name, validation_class)
205
+ end
206
+ end
207
+
208
+ def drop_index_with_oboe(keyspace, column_family, column_name)
209
+ if Oboe::Config.tracing?
210
+ report_kvs = extract_trace_details(:drop_index, column_family, nil, nil)
211
+ report_kvs[:Keyspace] = keyspace.to_s
212
+ report_kvs[:Column_name] = column_name.to_s
213
+
214
+ Oboe::API.trace('cassandra', report_kvs) do
215
+ drop_index_without_oboe(keyspace, column_family, column_name)
216
+ end
217
+ else
218
+ drop_index_without_oboe(keyspace, column_family, column_name)
219
+ end
220
+ end
221
+
222
+ def add_column_family_with_oboe(cf_def)
223
+ if Oboe::Config.tracing?
224
+ report_kvs = extract_trace_details(:add_column_family, nil, nil, nil)
225
+ report_kvs[:Name] = cf_def[:name] if cf_def.is_a?(Hash) and cf_def.has_key?(:name)
226
+
227
+ Oboe::API.trace('cassandra', report_kvs) do
228
+ add_column_family_without_oboe(cf_def)
229
+ end
230
+ else
231
+ add_column_family_without_oboe(cf_def)
232
+ end
233
+ end
234
+
235
+ def drop_column_family_with_oboe(column_family)
236
+ if Oboe::Config.tracing?
237
+ report_kvs = extract_trace_details(:drop_column_family, column_family, nil, nil)
238
+
239
+ Oboe::API.trace('cassandra', report_kvs) do
240
+ drop_column_family_without_oboe(column_family)
241
+ end
242
+ else
243
+ drop_column_family_without_oboe(column_family)
244
+ end
245
+ end
246
+
247
+ def add_keyspace_with_oboe(ks_def)
248
+ if Oboe::Config.tracing?
249
+ report_kvs = extract_trace_details(:add_keyspace, nil, nil, nil)
250
+ report_kvs[:Name] = ks_def[:name] if ks_def.is_a?(Hash) and ks_def.has_key?(:name)
251
+
252
+ Oboe::API.trace('cassandra', report_kvs) do
253
+ add_keyspace_without_oboe(ks_def)
254
+ end
255
+ else
256
+ add_keyspace_without_oboe(ks_def)
257
+ end
258
+ end
259
+
260
+ def drop_keyspace_with_oboe(keyspace)
261
+ if Oboe::Config.tracing?
262
+ report_kvs = extract_trace_details(:drop_keyspace, nil, nil, nil)
263
+ report_kvs[:Name] = keyspace.to_s
264
+
265
+ Oboe::API.trace('cassandra', report_kvs) do
266
+ drop_keyspace_without_oboe(keyspace)
267
+ end
268
+ else
269
+ drop_keyspace_without_oboe(keyspace)
270
+ end
271
+ end
272
+ end
273
+ end
274
+ end
275
+
276
+ if defined?(::Cassandra)
277
+ puts "[oboe/loading] Instrumenting Cassandra"
278
+ class ::Cassandra
279
+ include Oboe::Inst::Cassandra
280
+
281
+ [ :insert, :remove, :count_columns, :get_columns, :multi_get_columns, :get,
282
+ :multi_get, :get_range_single, :get_range_batch, :get_indexed_slices,
283
+ :create_index, :drop_index, :add_column_family, :drop_column_family,
284
+ :add_keyspace, :drop_keyspace].each do |m|
285
+ if method_defined?(m)
286
+ class_eval "alias #{m}_without_oboe #{m}"
287
+ class_eval "alias #{m} #{m}_with_oboe"
288
+ else puts "[oboe/loading] Couldn't properly instrument Cassandra (#{m}). Partial traces may occur."
289
+ end
290
+ end
291
+
292
+ # Special case handler for question mark methods
293
+ if method_defined?(:exists?)
294
+ alias exists_without_oboe? exists?
295
+ alias exists? exists_with_oboe?
296
+ else puts "[oboe/loading] Couldn't properly instrument Cassandra (exists?). Partial traces may occur."
297
+ end
298
+ end # class Cassandra
299
+ end
300
+
301
+
@@ -2,7 +2,7 @@ module Oboe
2
2
  module Version
3
3
  MAJOR = 1
4
4
  MINOR = 3
5
- PATCH = 4
5
+ PATCH = 5
6
6
  BUILD = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
@@ -16,6 +16,18 @@ module Oboe_metal
16
16
 
17
17
  Oboe.reporter.sendReport(evt)
18
18
  end
19
+
20
+ def self.layer_op=(op)
21
+ @layer_op = op.to_s
22
+ end
23
+
24
+ def self.layer_op
25
+ @layer_op
26
+ end
27
+
28
+ def self.layer_op?(operation)
29
+ @layer_op == operation.to_s
30
+ end
19
31
  end
20
32
  end
21
33
 
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
4
+ version: 1.3.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -37,6 +37,7 @@ files:
37
37
  - lib/oboe/frameworks/rails/inst/action_controller.rb
38
38
  - lib/oboe/frameworks/rails/inst/dalli.rb
39
39
  - lib/oboe/frameworks/rails/inst/active_record.rb
40
+ - lib/oboe/frameworks/rails/inst/cassandra.rb
40
41
  - lib/oboe/frameworks/rails/inst/memcached.rb
41
42
  - lib/oboe/frameworks/rails/rails.rb
42
43
  - lib/oboe_fu.rb