Sha256: 9c6b8e85d1cfd0378a06b65d951ea459473947203a33c6c72b7e233233f37420

Contents?: true

Size: 1.21 KB

Versions: 20

Compression:

Stored size: 1.21 KB

Contents

module Timber
  module Integrations
    module Rack
      # Reponsible for capturing and logging HTTP server requests and response events.
      class HTTPEvents
        def initialize(app)
          @app = app
        end

        def call(env)
          start = Time.now
          request = Util::Request.new(env)

          Config.instance.logger.info do
            Events::HTTPServerRequest.new(
              headers: request.headers,
              host: request.host,
              method: request.request_method,
              path: request.path,
              port: request.port,
              query_string: request.query_string,
              request_id: request.request_id, # we insert this middleware after ActionDispatch::RequestId
              scheme: request.scheme
            )
          end

          status, headers, body = @app.call(env)

          Config.instance.logger.info do
            time_ms = (Time.now - start) * 1000.0
            Events::HTTPServerResponse.new(
              headers: headers,
              request_id: request.request_id,
              status: status,
              time_ms: time_ms
            )
          end

          [status, headers, body]
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
timber-2.0.24 lib/timber/integrations/rack/http_events.rb
timber-2.0.23 lib/timber/integrations/rack/http_events.rb
timber-2.0.22 lib/timber/integrations/rack/http_events.rb
timber-2.0.21 lib/timber/integrations/rack/http_events.rb
timber-2.0.20 lib/timber/integrations/rack/http_events.rb
timber-2.0.19 lib/timber/integrations/rack/http_events.rb
timber-2.0.17 lib/timber/integrations/rack/http_events.rb
timber-2.0.16 lib/timber/integrations/rack/http_events.rb
timber-2.0.15 lib/timber/integrations/rack/http_events.rb
timber-2.0.14 lib/timber/integrations/rack/http_events.rb
timber-2.0.12 lib/timber/integrations/rack/http_events.rb
timber-2.0.11 lib/timber/integrations/rack/http_events.rb
timber-2.0.10 lib/timber/integrations/rack/http_events.rb
timber-2.0.9 lib/timber/integrations/rack/http_events.rb
timber-2.0.8 lib/timber/integrations/rack/http_events.rb
timber-2.0.7 lib/timber/integrations/rack/http_events.rb
timber-2.0.6 lib/timber/integrations/rack/http_events.rb
timber-2.0.5 lib/timber/integrations/rack/http_events.rb
timber-2.0.4 lib/timber/integrations/rack/http_events.rb
timber-2.0.3 lib/timber/integrations/rack/http_events.rb