2018-12-05 20:54:40 +00: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)
|
2019-02-18 20:57:22 +00:00
|
|
|
::Labkit::Correlation::CorrelationId.use_id(correlation_id(env)) do
|
2018-12-05 20:54:40 +00:00
|
|
|
@app.call(env)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def correlation_id(env)
|
2018-12-15 09:06:56 +00:00
|
|
|
request(env).request_id
|
2018-12-05 20:54:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def request(env)
|
|
|
|
ActionDispatch::Request.new(env)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|