2019-02-15 15:39:39 +05:30
|
|
|
# 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-07-31 22:56:46 +05:30
|
|
|
::Labkit::Correlation::CorrelationId.use_id(correlation_id(env)) do
|
2019-02-15 15:39:39 +05:30
|
|
|
@app.call(env)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def correlation_id(env)
|
|
|
|
request(env).request_id
|
|
|
|
end
|
|
|
|
|
|
|
|
def request(env)
|
|
|
|
ActionDispatch::Request.new(env)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|