Sha256: b159bccabebd6c8ef49569a3012b3d1fa396eacba898e951c6e54dfd2204fb12

Contents?: true

Size: 1.06 KB

Versions: 15

Compression:

Stored size: 1.06 KB

Contents

module Timber
  module Events
    # The HTTP response event tracks outgoing HTTP request responses.
    #
    # @note This event should be installed automatically through probes,
    #   such as the {Probes::ActionControllerLogSubscriber} probe.
    class HTTPResponse < Timber::Event
      attr_reader :status, :time_ms, :additions

      def initialize(attributes)
        @status = attributes[:status] || raise(ArgumentError.new(":status is required"))
        @time_ms = attributes[:time_ms] || raise(ArgumentError.new(":time_ms is required"))
        @additions = attributes[:additions]
      end

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

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

      def message
        message = "Completed #{status} #{status_description} in #{time_ms}ms"
        message << " (#{additions.join(" | ".freeze)})" unless additions.empty?
        message
      end

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

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
timber-1.0.13 lib/timber/events/http_response.rb
timber-1.0.12 lib/timber/events/http_response.rb
timber-1.0.11 lib/timber/events/http_response.rb
timber-1.0.10 lib/timber/events/http_response.rb
timber-1.0.9 lib/timber/events/http_response.rb
timber-1.0.8 lib/timber/events/http_response.rb
timber-1.0.7 lib/timber/events/http_response.rb
timber-1.0.6 lib/timber/events/http_response.rb
timber-1.0.5 lib/timber/events/http_response.rb
timber-1.0.4 lib/timber/events/http_response.rb
timber-1.0.3 lib/timber/events/http_response.rb
timberio-1.0.3 lib/timber/events/http_response.rb
timberio-1.0.2 lib/timber/events/http_response.rb
timberio-1.0.1 lib/timber/events/http_response.rb
timberio-1.0.0 lib/timber/events/http_response.rb