-
Notifications
You must be signed in to change notification settings - Fork 1
/
traceable.rb
57 lines (45 loc) · 1.12 KB
/
traceable.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require 'drb'
class TracerThing
def run(write_to)
begin
require 'rubygems'
require 'ruby-debug'
STDOUT.reopen(write_to)
Debugger.start(:tracing => true)
return "success"
rescue => e
return e.inspect + e.backtrace.join("\n")
end
end
def stop
begin
Debugger.stop
STDOUT.reopen(STDERR)
return "success"
rescue => e
return e.inspect + e.backtrace.join("\n")
end
end
end
class DrbTracer
def initialize(app)
@app = app
end
def call(env)
start_drb_if_needed
@app.call(env)
end
def start_drb_if_needed
@drb_thread ||= Thread.new do
# start up the DRb service
DRb.start_service nil, TracerThing.new
# We need the uri of the service to connect a client
RAILS_DEFAULT_LOGGER.debug("this proc #{Process.pid} can be hooked into at #{DRb.uri}")
# wait for the DRb service to finish before exiting
DRb.thread.join
end
end
end
if defined?(ENABLE_DEBUG_TRACER_HOOK) && ENABLE_DEBUG_TRACER_HOOK
ActionController::Dispatcher.middleware.use DrbTracer
end