Class: Rack::Probe
- Inherits:
-
Object
- Object
- Rack::Probe
- Defined in:
- lib/rack/probe.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, opts = {}) ⇒ Probe
constructor
A new instance of Probe.
Constructor Details
#initialize(app, opts = {}) ⇒ Probe
Returns a new instance of Probe.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rack/probe.rb', line 15 def initialize( app, opts = {} ) # Unless our probes are already defined... unless Dtrace::Probe::Rack.instance_of? Dtrace::Provider::Klass Dtrace::Provider.create :rack do |p| p.probe :get # GET request p.probe :post # POST request p.probe :put # PUT request p.probe :delete # DELETE request p.probe :ip, :string # IP of the requester p.probe :path, :string # Path visited p.probe :referer, :string # Referer p.probe :xhr # AJAX request p.probe :request_start # Start of a request p.probe :request_finish # End of a request end end # Provider shortcut @R = Dtrace::Probe::Rack @app = app end |
Instance Method Details
#call(env) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/rack/probe.rb', line 38 def call( env ) @R.request_start(&:fire) request = Rack::Request.new env @R.get(&:fire) if request.get? @R.post(&:fire) if request.post? @R.put(&:fire) if request.put? @R.delete(&:fire) if request.delete? @R.xhr(&:fire) if request.xhr? @R.path { |p| p.fire(request.path) } @R.ip { |p| p.fire(request.ip) } @R.referer { |p| p.fire(request.referer) } response = @app.call(env) @R.request_finish(&:fire) response end |