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.16.2 lib/labkit/middleware/rack.rb
gitlab-labkit-0.16.1 lib/labkit/middleware/rack.rb
gitlab-labkit-0.16.0 lib/labkit/middleware/rack.rb
gitlab-labkit-0.15.0 lib/labkit/middleware/rack.rb
gitlab-labkit-0.14.0 lib/labkit/middleware/rack.rb
gitlab-labkit-0.13.5 lib/labkit/middleware/rack.rb
gitlab-labkit-0.13.4 lib/labkit/middleware/rack.rb
gitlab-labkit-0.13.3 lib/labkit/middleware/rack.rb
gitlab-labkit-0.13.2 lib/labkit/middleware/rack.rb
gitlab-labkit-0.13.1 lib/labkit/middleware/rack.rb
gitlab-labkit-0.13.0 lib/labkit/middleware/rack.rb
gitlab-labkit-0.12.2 lib/labkit/middleware/rack.rb
gitlab-labkit-0.12.1 lib/labkit/middleware/rack.rb
gitlab-labkit-0.12.0 lib/labkit/middleware/rack.rb
gitlab-labkit-0.11.0 lib/labkit/middleware/rack.rb
gitlab-labkit-0.10.1 lib/labkit/middleware/rack.rb
gitlab-labkit-0.10.0 lib/labkit/middleware/rack.rb
gitlab-labkit-0.9.1 lib/labkit/middleware/rack.rb
gitlab-labkit-0.9.0 lib/labkit/middleware/rack.rb
gitlab-labkit-0.8.0 lib/labkit/middleware/rack.rb