Class: RackStatsD::RequestHostname

Inherits:
Object
  • Object
show all
Defined in:
lib/rack-statsd.rb

Overview

Simple middleware that adds the current host name and current git SHA to the response headers. This can help diagnose problems by letting you know what code is running from what machine.

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ RequestHostname

Initializes the middlware.

app - The next Rack app in the pipeline. options - Hash of options.

:host      - String hostname.
:revision  - String SHA that describes the version of code
             this process is running.

Returns nothing.



68
69
70
71
72
# File 'lib/rack-statsd.rb', line 68

def initialize(app, options = {})
  @app = app
  @host = options.key?(:host) ? options[:host] : `hostname -s`.chomp
  @sha = options[:revision] || '<none>'
end

Instance Method Details

#call(env) ⇒ Object



74
75
76
77
78
79
# File 'lib/rack-statsd.rb', line 74

def call(env)
  status, headers, body = @app.call(env)
  headers['X-Node'] = @host if @host
  headers['X-Revision'] = @sha
  [status, headers, body]
end