Class: Sleuth::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/sleuth/middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, name) ⇒ Middleware

Returns a new instance of Middleware.


3
4
5
# File 'lib/sleuth/middleware.rb', line 3

def initialize(app, name)
  @app, @name = app, name
end

Instance Method Details

#call(env) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/sleuth/middleware.rb', line 7

def call(env)
  parent = env["HTTP_#{TRANSACTION_HEADER}"]

  Sleuth.transaction(@name, parent) do
    request = Rack::Request.new(env)
    code, headers, body = Sleuth.instrument("Received #{request.request_method} #{request.url}") do
      @app.call(env)
    end
    headers[TRANSACTION_HEADER] = Sleuth.current_transaction.full_name
    [code, headers, body]
  end
end