Class: Currentsh::RailsTracker
- Inherits:
-
Object
- Object
- Currentsh::RailsTracker
- Defined in:
- lib/currentsh/rails.rb
Instance Method Summary collapse
- #action(event) ⇒ Object
-
#initialize(output) ⇒ RailsTracker
constructor
A new instance of RailsTracker.
- #register ⇒ Object
- #request(event) ⇒ Object
- #sql(event) ⇒ Object
Constructor Details
#initialize(output) ⇒ RailsTracker
Returns a new instance of RailsTracker.
3 4 5 |
# File 'lib/currentsh/rails.rb', line 3 def initialize(output) @output = output end |
Instance Method Details
#action(event) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/currentsh/rails.rb', line 24 def action(event) data = { :type => "action", :transaction => event.transaction_id, }.merge(event.payload) @output << data end |
#register ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/currentsh/rails.rb', line 7 def register ActiveSupport::Notifications.subscribe "sql.active_record" do |*args| event = ActiveSupport::Notifications::Event.new *args sql(event) end ActiveSupport::Notifications.subscribe "process_action.action_controller" do |*args| event = ActiveSupport::Notifications::Event.new *args action(event) end ActiveSupport::Notifications.subscribe "request.action_dispatch" do |*args| event = ActiveSupport::Notifications::Event.new *args request(event) end end |
#request(event) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/currentsh/rails.rb', line 33 def request(event) request = event.payload[:request] data = { :type => "request", :transaction => event.transaction_id, :method => request.method, :path => request.path, :elapse => event.end - event.time } @output << data end |
#sql(event) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/currentsh/rails.rb', line 47 def sql(event) binds = {} if raw = event.payload[:binds] raw.each do |(attribute,value)| binds[attribute.name] = {:type => attribute.type, :value => value } end end data = { :type => "sql", :name => event.payload[:name], :transaction => event.transaction_id, :query => event.payload[:sql].strip, :binds => binds, } @output << data end |