Class: Logtail::Integrations::Rack::HTTPResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/logtail-rack/http_response.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ HTTPResponse

Returns a new instance of HTTPResponse.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/logtail-rack/http_response.rb', line 13

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 = Util::Encoding.force_utf8_encoding(@headers).to_json
  end
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



10
11
12
# File 'lib/logtail-rack/http_response.rb', line 10

def body
  @body
end

#content_lengthObject (readonly)

Returns the value of attribute content_length.



10
11
12
# File 'lib/logtail-rack/http_response.rb', line 10

def content_length
  @content_length
end

#duration_msObject (readonly)

Returns the value of attribute duration_ms.



10
11
12
# File 'lib/logtail-rack/http_response.rb', line 10

def duration_ms
  @duration_ms
end

#headersObject (readonly)

Returns the value of attribute headers.



10
11
12
# File 'lib/logtail-rack/http_response.rb', line 10

def headers
  @headers
end

#headers_jsonObject (readonly)

Returns the value of attribute headers_json.



10
11
12
# File 'lib/logtail-rack/http_response.rb', line 10

def headers_json
  @headers_json
end

#http_contextObject (readonly)

Returns the value of attribute http_context.



10
11
12
# File 'lib/logtail-rack/http_response.rb', line 10

def http_context
  @http_context
end

#request_idObject (readonly)

Returns the value of attribute request_id.



10
11
12
# File 'lib/logtail-rack/http_response.rb', line 10

def request_id
  @request_id
end

#service_nameObject (readonly)

Returns the value of attribute service_name.



10
11
12
# File 'lib/logtail-rack/http_response.rb', line 10

def service_name
  @service_name
end

#statusObject (readonly)

Returns the value of attribute status.



10
11
12
# File 'lib/logtail-rack/http_response.rb', line 10

def status
  @status
end

Instance Method Details

#messageObject

Returns the human readable log message for this event.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/logtail-rack/http_response.rb', line 29

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_descriptionObject



50
51
52
# File 'lib/logtail-rack/http_response.rb', line 50

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