Sha256: 47c14198009eb595bc024848eb75c26a1aea34aaaf2dc51a0be46555a67305c0

Contents?: true

Size: 1.2 KB

Versions: 17

Compression:

Stored size: 1.2 KB

Contents

module Timber
  module Events
    # The HTTP server response event tracks outgoing HTTP responses that you send
    # to clients.
    #
    # @note This event should be installed automatically through integrations,
    #   such as the {Integrations::ActionController::LogSubscriber} integration.
    class HTTPServerResponse < Timber::Event
      attr_reader :headers, :request_id, :status, :time_ms

      def initialize(attributes)
        @headers = Util::HTTPEvent.normalize_headers(attributes[:headers])
        @request_id = attributes[:request_id]
        @status = attributes[:status] || raise(ArgumentError.new(":status is required"))
        @time_ms = attributes[:time_ms] || raise(ArgumentError.new(":time_ms is required"))
        @time_ms = @time_ms.round(6)
      end

      def to_hash
        {headers: headers, request_id: request_id, status: status, time_ms: time_ms}
      end
      alias to_h to_hash

      def as_json(_options = {})
        {:server_side_app => {:http_server_response => to_hash}}
      end

      def message
        "Completed #{status} #{status_description} in #{time_ms}ms"
      end

      def status_description
        Rack::Utils::HTTP_STATUS_CODES[status]
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
timber-2.0.17 lib/timber/events/http_server_response.rb
timber-2.0.16 lib/timber/events/http_server_response.rb
timber-2.0.15 lib/timber/events/http_server_response.rb
timber-2.0.14 lib/timber/events/http_server_response.rb
timber-2.0.12 lib/timber/events/http_server_response.rb
timber-2.0.11 lib/timber/events/http_server_response.rb
timber-2.0.10 lib/timber/events/http_server_response.rb
timber-2.0.9 lib/timber/events/http_server_response.rb
timber-2.0.8 lib/timber/events/http_server_response.rb
timber-2.0.7 lib/timber/events/http_server_response.rb
timber-2.0.6 lib/timber/events/http_server_response.rb
timber-2.0.5 lib/timber/events/http_server_response.rb
timber-2.0.4 lib/timber/events/http_server_response.rb
timber-2.0.3 lib/timber/events/http_server_response.rb
timber-2.0.2 lib/timber/events/http_server_response.rb
timber-2.0.1 lib/timber/events/http_server_response.rb
timber-2.0.0 lib/timber/events/http_server_response.rb