Class: Oboe::Rack
- Inherits:
-
Object
- Object
- Oboe::Rack
- Defined in:
- lib/oboe/inst/rack.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
Instance Method Summary collapse
- #call(env) ⇒ Object
- #collect(req, env) ⇒ Object
-
#initialize(app) ⇒ Rack
constructor
A new instance of Rack.
Constructor Details
#initialize(app) ⇒ Rack
Returns a new instance of Rack.
10 11 12 |
# File 'lib/oboe/inst/rack.rb', line 10 def initialize(app) @app = app end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
8 9 10 |
# File 'lib/oboe/inst/rack.rb', line 8 def app @app end |
Instance Method Details
#call(env) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/oboe/inst/rack.rb', line 53 def call(env) req = ::Rack::Request.new(env) report_kvs = {} report_kvs[:URL] = URI.unescape(req.path) xtrace = env.is_a?(Hash) ? env['HTTP_X_TRACE'] : nil result, xtrace = Oboe::API.start_trace('rack', xtrace, report_kvs) do status, headers, response = @app.call(env) if Oboe.tracing? report_kvs = collect(req, env) Oboe::API.log(nil, 'info', report_kvs.merge!({ :Status => status })) end [status, headers, response] end rescue Exception => e xtrace = e.instance_variable_get(:@xtrace) raise ensure result[1]['X-Trace'] = xtrace if result and Oboe::XTrace.valid?(xtrace) return result end |
#collect(req, env) ⇒ Object
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 |
# File 'lib/oboe/inst/rack.rb', line 14 def collect(req, env) report_kvs = {} begin if Oboe.always? # Only report these KVs under tracing_mode 'always' (never for 'through') report_kvs[:SampleRate] = Oboe.sample_rate report_kvs[:SampleSource] = Oboe.sample_source end report_kvs['HTTP-Host'] = req.host report_kvs['Port'] = req.port report_kvs['Proto'] = req.scheme report_kvs['Query-String'] = URI.unescape(req.query_string) unless req.query_string.empty? report_kvs[:URL] = URI.unescape(req.path) report_kvs[:Method] = req.request_method report_kvs['AJAX'] = true if req.xhr? report_kvs['ClientIP'] = req.ip report_kvs['X-TV-Meta'] = env['HTTP_X_TV_META'] if env.has_key?('HTTP_X_TV_META') # Report any request queue'ing headers. Report as 'Request-Start' or the summed Queue-Time report_kvs['Request-Start'] = env['HTTP_X_REQUEST_START'] if env.has_key?('HTTP_X_REQUEST_START') report_kvs['Request-Start'] = env['HTTP_X_QUEUE_START'] if env.has_key?('HTTP_X_QUEUE_START') report_kvs['Queue-Time'] = env['HTTP_X_QUEUE_TIME'] if env.has_key?('HTTP_X_QUEUE_TIME') report_kvs['Forwarded-For'] = env['HTTP_X_FORWARDED_FOR'] if env.has_key?('HTTP_X_FORWARDED_FOR') report_kvs['Forwarded-Host'] = env['HTTP_X_FORWARDED_HOST'] if env.has_key?('HTTP_X_FORWARDED_HOST') report_kvs['Forwarded-Proto'] = env['HTTP_X_FORWARDED_PROTO'] if env.has_key?('HTTP_X_FORWARDED_PROTO') report_kvs['Forwarded-Port'] = env['HTTP_X_FORWARDED_PORT'] if env.has_key?('HTTP_X_FORWARDED_PORT') report_kvs['Ruby.Oboe.Version'] = ::Oboe::Version::STRING rescue Exception => e # Discard any potential exceptions. Debug log and report whatever we can. Oboe.logger.debug "[oboe/debug] Rack KV collection error: #{e.inspect}" end report_kvs end |