Sha256: 7ed183e84c1df8cd8f2d5ab6c929d95d8269791ec46d96d3b042566b84fac711

Contents?: true

Size: 806 Bytes

Versions: 40

Compression:

Stored size: 806 Bytes

Contents

# frozen_string_literal: true

require "action_dispatch"

module Labkit
  module Middleware
    # This is a rack middleware to be inserted in GitLab-rails
    # It makes sure that there's always a root context containing the correlation
    # id.
    # Since this context always get's cleaned up by this middleware, we can be
    # sure that any nested contexts will also be cleaned up.
    class Rack
      def initialize(app)
        @app = app
      end

      def call(env)
        Labkit::Context.with_context(Labkit::Context::CORRELATION_ID_KEY => correlation_id(env)) do
          @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

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
gitlab-labkit-0.31.1 lib/labkit/middleware/rack.rb
gitlab-labkit-0.31.0 lib/labkit/middleware/rack.rb
gitlab-labkit-0.30.1 lib/labkit/middleware/rack.rb
gitlab-labkit-0.30.0 lib/labkit/middleware/rack.rb
gitlab-labkit-0.29.0 lib/labkit/middleware/rack.rb
gitlab-labkit-0.28.0 lib/labkit/middleware/rack.rb
gitlab-labkit-0.27.0 lib/labkit/middleware/rack.rb
gitlab-labkit-0.26.0 lib/labkit/middleware/rack.rb
gitlab-labkit-0.25.0 lib/labkit/middleware/rack.rb
gitlab-labkit-0.24.0 lib/labkit/middleware/rack.rb
gitlab-labkit-0.23.0 lib/labkit/middleware/rack.rb
gitlab-labkit-0.22.0 lib/labkit/middleware/rack.rb
gitlab-labkit-0.21.3 lib/labkit/middleware/rack.rb
gitlab-labkit-0.21.2 lib/labkit/middleware/rack.rb
gitlab-labkit-0.21.1 lib/labkit/middleware/rack.rb
gitlab-labkit-0.21.0 lib/labkit/middleware/rack.rb
gitlab-labkit-0.20.0 lib/labkit/middleware/rack.rb
gitlab-labkit-0.19.0 lib/labkit/middleware/rack.rb
gitlab-labkit-0.18.0 lib/labkit/middleware/rack.rb
gitlab-labkit-0.17.1 lib/labkit/middleware/rack.rb