Class: Labkit::Middleware::Rack

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

Overview

This is a rack middleware to be inserted in GitLab-rails It makes sure that there’s always a root context containing the correlation id. Since this context always get’s cleaned up by this middleware, we can be sure that any nested contexts will also be cleaned up.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Rack

Returns a new instance of Rack.



16
17
18
# File 'lib/labkit/middleware/rack.rb', line 16

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/labkit/middleware/rack.rb', line 20

def call(env)
  Labkit::Context.with_context(Labkit::Context::CORRELATION_ID_KEY => correlation_id(env)) do |context|
    status, headers, response = @app.call(env)

    headers[HEADER] = context_to_json(context)

    [status, headers, response]
  end
end