oboe 1.3.9.1 → 1.4.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,192 @@
1
+ # Copyright (c) 2013 by Tracelytics, Inc.
2
+ # All rights reserved.
3
+
4
+ require 'socket'
5
+
6
+ module Oboe
7
+ module Inst
8
+ module Resque
9
+
10
+ def self.included(base)
11
+ base.send :extend, ::Resque
12
+ end
13
+
14
+ def extract_trace_details(op, klass, args)
15
+ report_kvs = {}
16
+
17
+ begin
18
+ report_kvs[:Op] = op.to_s
19
+ report_kvs[:Class] = klass.to_s if klass
20
+
21
+ if Oboe::Config[:resque][:log_args]
22
+ kv_args = args.to_json
23
+
24
+ # Limit the argument json string to 1024 bytes
25
+ if kv_args.length > 1024
26
+ report_kvs[:Args] = kv_args[0..1023] + '...[snipped]'
27
+ else
28
+ report_kvs[:Args] = kv_args
29
+ end
30
+ end
31
+
32
+ report_kvs[:Backtrace] = Oboe::API.backtrace
33
+ rescue
34
+ end
35
+
36
+ report_kvs
37
+ end
38
+
39
+ def enqueue_with_oboe(klass, *args)
40
+ if Oboe.tracing?
41
+ report_kvs = extract_trace_details(:enqueue, klass, args)
42
+
43
+ Oboe::API.trace('resque', report_kvs, :enqueue) do
44
+ args.push({:parent_trace_id => Oboe::Context.toString}) if Oboe::Config[:resque][:link_workers]
45
+ enqueue_without_oboe(klass, *args)
46
+ end
47
+ else
48
+ enqueue_without_oboe(klass, *args)
49
+ end
50
+ end
51
+
52
+ def enqueue_to_with_oboe(queue, klass, *args)
53
+ if Oboe.tracing? and not Oboe::Context.tracing_layer_op?(:enqueue)
54
+ report_kvs = extract_trace_details(:enqueue_to, klass, args)
55
+ report_kvs[:Queue] = queue.to_s if queue
56
+
57
+ Oboe::API.trace('resque', report_kvs) do
58
+ args.push({:parent_trace_id => Oboe::Context.toString}) if Oboe::Config[:resque][:link_workers]
59
+ enqueue_to_without_oboe(queue, klass, *args)
60
+ end
61
+ else
62
+ enqueue_to_without_oboe(queue, klass, *args)
63
+ end
64
+ end
65
+
66
+ def dequeue_with_oboe(klass, *args)
67
+ if Oboe.tracing?
68
+ report_kvs = extract_trace_details(:dequeue, klass, args)
69
+
70
+ Oboe::API.trace('resque', report_kvs) do
71
+ dequeue_without_oboe(klass, *args)
72
+ end
73
+ else
74
+ dequeue_without_oboe(klass, *args)
75
+ end
76
+ end
77
+ end
78
+
79
+ module ResqueWorker
80
+ def perform_with_oboe(job)
81
+ report_kvs = {}
82
+ last_arg = nil
83
+
84
+ begin
85
+ report_kvs[:Op] = :perform
86
+
87
+ # Set these keys for the ability to separate out
88
+ # background tasks into a separate app on the server-side UI
89
+ report_kvs[:Controller] = :Resque
90
+ report_kvs[:Action] = :perform
91
+
92
+ report_kvs['HTTP-Host'] = Socket.gethostname
93
+ report_kvs[:URL] = '/resque/' + job.queue
94
+ report_kvs[:Method] = 'NONE'
95
+ report_kvs[:Queue] = job.queue
96
+
97
+ report_kvs[:Class] = job.payload['class']
98
+
99
+ if Oboe::Config[:resque][:log_args]
100
+ kv_args = job.payload['args'].to_json
101
+
102
+ # Limit the argument json string to 1024 bytes
103
+ if kv_args.length > 1024
104
+ report_kvs[:Args] = kv_args[0..1023] + '...[snipped]'
105
+ else
106
+ report_kvs[:Args] = kv_args
107
+ end
108
+ end
109
+
110
+ last_arg = job.payload['args'].last
111
+ rescue
112
+ end
113
+
114
+ if last_arg.is_a?(Hash) and last_arg.has_key?('parent_trace_id')
115
+ begin
116
+ # Since the enqueue was traced, we force trace the actual job execution and reference
117
+ # the enqueue trace with ParentTraceID
118
+ report_kvs[:ParentTraceID] = last_arg['parent_trace_id']
119
+ job.payload['args'].pop
120
+
121
+ rescue
122
+ end
123
+
124
+ Oboe::API.force_trace do
125
+ Oboe::API.start_trace('resque', nil, report_kvs) do
126
+ perform_without_oboe(job)
127
+ end
128
+ end
129
+
130
+ else
131
+ Oboe::API.start_trace('resque', nil, report_kvs) do
132
+ perform_without_oboe(job)
133
+ end
134
+ end
135
+ end
136
+ end
137
+
138
+ module ResqueJob
139
+ def fail_with_oboe(exception)
140
+ if Oboe.tracing?
141
+ Oboe::API.log_exception('resque', exception)
142
+ end
143
+ fail_without_oboe(exception)
144
+ end
145
+ end
146
+ end
147
+ end
148
+
149
+ if defined?(::Resque)
150
+ puts "[oboe/loading] Instrumenting resque" if Oboe::Config[:verbose]
151
+
152
+ ::Resque.module_eval do
153
+ include Oboe::Inst::Resque
154
+
155
+ [ :enqueue, :enqueue_to, :dequeue ].each do |m|
156
+ if method_defined?(m)
157
+ module_eval "alias #{m}_without_oboe #{m}"
158
+ module_eval "alias #{m} #{m}_with_oboe"
159
+ elsif Oboe::Config[:verbose]
160
+ puts "[oboe/loading] Couldn't properly instrument Resque (#{m}). Partial traces may occur."
161
+ end
162
+ end
163
+ end
164
+
165
+ if defined?(::Resque::Worker)
166
+ ::Resque::Worker.class_eval do
167
+ include Oboe::Inst::ResqueWorker
168
+
169
+ if method_defined?(:perform)
170
+ alias perform_without_oboe perform
171
+ alias perform perform_with_oboe
172
+ elsif Oboe::Config[:verbose]
173
+ puts "[oboe/loading] Couldn't properly instrument ResqueWorker (perform). Partial traces may occur."
174
+ end
175
+ end
176
+ end
177
+
178
+ if defined?(::Resque::Job)
179
+ ::Resque::Job.class_eval do
180
+ include Oboe::Inst::ResqueJob
181
+
182
+ if method_defined?(:fail)
183
+ alias fail_without_oboe fail
184
+ alias fail fail_with_oboe
185
+ elsif Oboe::Config[:verbose]
186
+ puts "[oboe/loading] Couldn't properly instrument ResqueWorker (fail). Partial traces may occur."
187
+ end
188
+ end
189
+ end
190
+ end
191
+
192
+
@@ -26,7 +26,7 @@ module Oboe
26
26
  module Loading
27
27
 
28
28
  def self.load_access_key
29
- unless Oboe::Config.has_key?(:access_key)
29
+ unless Oboe::Config.access_key
30
30
  config_file = '/etc/tracelytics.conf'
31
31
  return unless File.exists?(config_file)
32
32
 
@@ -1,9 +1,9 @@
1
1
  module Oboe
2
2
  module Version
3
3
  MAJOR = 1
4
- MINOR = 3
5
- PATCH = 9
6
- BUILD = 1
4
+ MINOR = 4
5
+ PATCH = 0
6
+ BUILD = 2
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
9
9
  end
@@ -50,45 +50,6 @@ end
50
50
  module Oboe
51
51
  include Oboe_metal
52
52
 
53
- # TODO: Ensure that the :tracing_mode is set to "always", "through", or "never"
54
- Config = {
55
- :tracing_mode => "through",
56
- :reporter_host => "127.0.0.1",
57
- :sample_rate => 1000000
58
- }
59
-
60
- def self.passthrough?
61
- ["always", "through"].include?(Oboe::Config[:tracing_mode])
62
- end
63
-
64
- def self.always?
65
- Oboe::Config[:tracing_mode] == "always"
66
- end
67
-
68
- def self.through?
69
- Oboe::Config[:tracing_mode] == "through"
70
- end
71
-
72
- def self.never?
73
- Oboe::Config[:tracing_mode] == "never"
74
- end
75
-
76
- def self.now?
77
- Oboe::Context.isValid and not Oboe.never?
78
- end
79
-
80
- def self.start?
81
- not Oboe::Context.isValid and Oboe.always?
82
- end
83
-
84
- def self.continue?
85
- Oboe::Context.isValid and not Oboe.never?
86
- end
87
-
88
- def self.log(layer, label, options = {})
89
- Context.log(layer, label, options = options)
90
- end
91
-
92
53
  def self.reporter
93
54
  if !@reporter
94
55
  @reporter = Oboe::UdpReporter.new(Oboe::Config[:reporter_host])
@@ -13,4 +13,36 @@ if defined?(::Oboe::Config)
13
13
  <% end %>
14
14
  # Verbose output of instrumentation initialization
15
15
  # Oboe::Config[:verbose] = <%= @verbose %>
16
+
17
+ #
18
+ # Resque Options
19
+ #
20
+ # :link_workers - associates Resque enqueue operations with the jobs they queue by piggybacking
21
+ # an additional argument on the Redis queue that is stripped prior to job
22
+ # processing
23
+ # !!! Note: Make sure both the enqueue side and the Resque workers are instrumented
24
+ # before enabling this or jobs will fail !!!
25
+ # (Default: false)
26
+ # Oboe::Config[:resque][:link_workers] = false
27
+ #
28
+ # Set to true to disable Resque argument logging (Default: false)
29
+ # Oboe::Config[:resque][:log_args] = false
30
+
31
+ #
32
+ # Enabling/Disabling Instrumentation
33
+ #
34
+ # If you're having trouble with one of the instrumentation libraries, they
35
+ # can be individually disabled here by setting the :enabled
36
+ # value to false:
37
+ #
38
+ # Oboe::Config[:action_controller][:enabled] = true
39
+ # Oboe::Config[:active_record][:enabled] = true
40
+ # Oboe::Config[:action_view][:enabled] = true
41
+ # Oboe::Config[:cassandra][:enabled] = true
42
+ # Oboe::Config[:dalli][:enabled] = true
43
+ # Oboe::Config[:memcache][:enabled] = true
44
+ # Oboe::Config[:memcached][:enabled] = true
45
+ # Oboe::Config[:mongo][:enabled] = true
46
+ # Oboe::Config[:moped][:enabled] = true
47
+ # Oboe::Config[:resque][:enabled] = true
16
48
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oboe
3
3
  version: !ruby/object:Gem::Version
4
- hash: 97
4
+ hash: 123
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 3
9
- - 9
10
- - 1
11
- version: 1.3.9.1
8
+ - 4
9
+ - 0
10
+ - 2
11
+ version: 1.4.0.2
12
12
  platform: ruby
13
13
  authors:
14
14
  - Tracelytics, Inc.
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2013-01-29 00:00:00 Z
19
+ date: 2013-03-08 00:00:00 Z
20
20
  dependencies: []
21
21
 
22
22
  description: The oboe gem provides AppNeta instrumentation for Ruby and Ruby frameworks.
@@ -40,6 +40,7 @@ files:
40
40
  - lib/oboe/ruby.rb
41
41
  - lib/oboe/inst/cassandra.rb
42
42
  - lib/oboe/inst/dalli.rb
43
+ - lib/oboe/inst/resque.rb
43
44
  - lib/oboe/inst/rack.rb
44
45
  - lib/oboe/inst/mongo.rb
45
46
  - lib/oboe/inst/memcached.rb