class Tailog::RequestId

Public Class Methods

new(app) click to toggle source
# File lib/tailog/request_id.rb, line 3
def initialize app
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/tailog/request_id.rb, line 7
def call env
  Tailog.request_id = external_request_id(env) || internal_request_id
  @app.call(env).tap do |_status, headers, _body|
    headers["X-Request-Id"] = Tailog.request_id
  end
end

Private Instance Methods

external_request_id(env) click to toggle source
# File lib/tailog/request_id.rb, line 16
def external_request_id env
  env["HTTP_X_REQUEST_ID"].presence
end
internal_request_id() click to toggle source
# File lib/tailog/request_id.rb, line 20
def internal_request_id
  SecureRandom.uuid
end