Sha256: 5212b9588f0a34f3dcdc055ad50df3b4b6b2fa0c1115956e513d9c63766c0e73

Contents?: true

Size: 461 Bytes

Versions: 28

Compression:

Stored size: 461 Bytes

Contents

module Tailog
  class RequestId
    def initialize app
      @app = app
    end

    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

    def external_request_id env
      env["HTTP_X_REQUEST_ID"].presence
    end

    def internal_request_id
      SecureRandom.uuid
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
tailog-0.4.8 lib/tailog/request_id.rb
tailog-0.4.7 lib/tailog/request_id.rb
tailog-0.4.6 lib/tailog/request_id.rb
tailog-0.4.5 lib/tailog/request_id.rb
tailog-0.4.3 lib/tailog/request_id.rb
tailog-0.4.2 lib/tailog/request_id.rb
tailog-0.4.1 lib/tailog/request_id.rb
tailog-0.4.0 lib/tailog/request_id.rb