Class: Mnemosyne::Middleware::Rack

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

Defined Under Namespace

Classes: Proxy

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Rack

Returns a new instance of Rack.



53
54
55
# File 'lib/mnemosyne/middleware/rack.rb', line 53

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object

rubocop:disable AbcSize



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/mnemosyne/middleware/rack.rb', line 57

def call(env) # rubocop:disable AbcSize
  origin      = env.fetch('HTTP_X_MNEMOSYNE_ORIGIN', false)
  transaction = env.fetch('HTTP_X_MNEMOSYNE_TRANSACTION') do
    ::SecureRandom.uuid
  end

  trace = ::Mnemosyne::Instrumenter.trace 'app.web.request.rack',
    transaction: transaction,
    origin: origin

  if trace
    trace.start!

    scan_request(trace, env)

    response = @app.call env

    scan_response(trace, response)

    response[2] = Proxy.new(response[2]) { trace.submit }
    response
  else
    @app.call env
  end
rescue Exception # rubocop:disable RescueException
  trace.submit if trace
  raise
ensure
  trace.release if trace
end