Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 28 lines (22 sloc) 0.632 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
require "uuid"
require "logger"

module E20
  module Ops
    module Middleware
      class TransactionIdMiddleware

        def initialize(app, options = {})
          @app = app
          @uuid_generator = options[:uuid_generator] || UUID.method(:generate)
          @logger = options[:logger] || Logger.new(STDOUT)
        end

        def call(env)
          uuid = @uuid_generator.call.to_s
          @logger.info "[#{self.class.name}] Transaction ID: #{uuid}"

          status, headers, body = @app.call(env)
          headers["X-Transaction"] = uuid
          [status, headers, body]
        end

      end
    end
  end
end
Something went wrong with that request. Please try again.