Class: Timber::Integrations::Rack::HTTPResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/timber-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.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/timber-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

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



8
9
10
# File 'lib/timber-rack/http_response.rb', line 8

def body
  @body
end

#content_lengthObject (readonly)

Returns the value of attribute content_length.



8
9
10
# File 'lib/timber-rack/http_response.rb', line 8

def content_length
  @content_length
end

#duration_msObject (readonly)

Returns the value of attribute duration_ms.



8
9
10
# File 'lib/timber-rack/http_response.rb', line 8

def duration_ms
  @duration_ms
end

#headersObject (readonly)

Returns the value of attribute headers.



8
9
10
# File 'lib/timber-rack/http_response.rb', line 8

def headers
  @headers
end

#headers_jsonObject (readonly)

Returns the value of attribute headers_json.



8
9
10
# File 'lib/timber-rack/http_response.rb', line 8

def headers_json
  @headers_json
end

#http_contextObject (readonly)

Returns the value of attribute http_context.



8
9
10
# File 'lib/timber-rack/http_response.rb', line 8

def http_context
  @http_context
end

#request_idObject (readonly)

Returns the value of attribute request_id.



8
9
10
# File 'lib/timber-rack/http_response.rb', line 8

def request_id
  @request_id
end

#service_nameObject (readonly)

Returns the value of attribute service_name.



8
9
10
# File 'lib/timber-rack/http_response.rb', line 8

def service_name
  @service_name
end

#statusObject (readonly)

Returns the value of attribute status.



8
9
10
# File 'lib/timber-rack/http_response.rb', line 8

def status
  @status
end

Instance Method Details

#messageObject

Returns the human readable log message for this event.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/timber-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_descriptionObject



48
49
50
# File 'lib/timber-rack/http_response.rb', line 48

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