class Logtail::Integrations::Rack::HTTPResponse

The HTTP server response event tracks outgoing HTTP responses that you send to clients.

Attributes

body[R]
content_length[R]
duration_ms[R]
headers[R]
headers_json[R]
http_context[R]
request_id[R]
service_name[R]
status[R]

Public Class Methods

new(attributes) click to toggle source
# File lib/logtail-rack/http_response.rb, line 11
def initialize(attributes)
  @body = attributes[:body]
  @content_length  = attributes[:content_length]
  @headers = attributes[:headers]
  @http_context = attributes[:http_context]
  @request_id = attributes[:request_id]
  @service_name = attributes[:service_name]
  @status = attributes[:status]
  @duration_ms = attributes[:duration_ms]

  if @headers
    @headers_json = @headers.to_json
  end
end

Public Instance Methods

message() click to toggle source

Returns the human readable log message for this event.

# File lib/logtail-rack/http_response.rb, line 27
def message
  if http_context
    message = "#{http_context[:method]} #{http_context[:path]} completed with " \
      "#{status} #{status_description} "

    if content_length
      message << ", #{content_length} bytes, "
    end

    message << "in #{duration_ms}ms"
  else
    message = "Completed #{status} #{status_description} "

    if content_length
      message << ", #{content_length} bytes, "
    end

    message << "in #{duration_ms}ms"
  end
end
status_description() click to toggle source
# File lib/logtail-rack/http_response.rb, line 48
def status_description
  ::Rack::Utils::HTTP_STATUS_CODES[status]
end