2018-12-05 15:54:40 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# A dumb middleware that steals correlation id
|
|
|
|
# and sets it as a global context for the request
|
|
|
|
module Gitlab
|
|
|
|
module Middleware
|
|
|
|
class CorrelationId
|
|
|
|
include ActionView::Helpers::TagHelper
|
|
|
|
|
|
|
|
def initialize(app)
|
|
|
|
@app = app
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
2018-12-07 07:18:03 -05:00
|
|
|
::Gitlab::CorrelationId.use_id(correlation_id(env)) do
|
2018-12-05 15:54:40 -05:00
|
|
|
@app.call(env)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def correlation_id(env)
|
2018-12-15 04:06:56 -05:00
|
|
|
request(env).request_id
|
2018-12-05 15:54:40 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def request(env)
|
|
|
|
ActionDispatch::Request.new(env)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|