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 Metrics/MethodLength



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
# File 'lib/mnemosyne/middleware/rack.rb', line 58

def call(env)
  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!

    response = @app.call env
    response[2] = Proxy.new(response[2]) { trace.submit }
    response
  else
    @app.call env
  end

# rubocop:disable Lint/RescueException
rescue Exception
  trace.submit if trace
  raise
ensure
  trace.release if trace
end