Class: TCellAgent::AppSensor::MetaData

Inherits:
SensorEvents::TCellSensorEvent show all
Defined in:
lib/tcell_agent/appsensor/meta_data.rb

Instance Attribute Summary collapse

Attributes inherited from SensorEvents::TCellSensorEvent

#ensure, #flush, #send

Instance Method Summary collapse

Methods inherited from SensorEvents::TCellSensorEvent

#bucket_key, #calculateOffset, #post_process

Constructor Details

#initialize(method, remote_address, route_id, session_id, user_id, transaction_id) ⇒ MetaData

Returns a new instance of MetaData.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/tcell_agent/appsensor/meta_data.rb', line 15

def initialize(method, remote_address, route_id, session_id, user_id, transaction_id)
  @send = false

  @method = method
  @remote_address = remote_address
  @route_id = route_id
  @session_id = session_id
  @user_id = user_id
  @transaction_id = transaction_id

  @body_dict = {}
  @get_dict = {}
  @post_dict = {}
  @cookie_dict = {}
  @path_parameters = {}
  @headers_dict = {}
end

Instance Attribute Details

#body_dictObject

Returns the value of attribute body_dict.



10
11
12
# File 'lib/tcell_agent/appsensor/meta_data.rb', line 10

def body_dict
  @body_dict
end

Returns the value of attribute cookie_dict.



10
11
12
# File 'lib/tcell_agent/appsensor/meta_data.rb', line 10

def cookie_dict
  @cookie_dict
end

#get_dictObject

Returns the value of attribute get_dict.



10
11
12
# File 'lib/tcell_agent/appsensor/meta_data.rb', line 10

def get_dict
  @get_dict
end

#headers_dictObject (readonly)

Returns the value of attribute headers_dict.



13
14
15
# File 'lib/tcell_agent/appsensor/meta_data.rb', line 13

def headers_dict
  @headers_dict
end

#methodObject

Returns the value of attribute method.



10
11
12
# File 'lib/tcell_agent/appsensor/meta_data.rb', line 10

def method
  @method
end

#path_parametersObject

Returns the value of attribute path_parameters.



10
11
12
# File 'lib/tcell_agent/appsensor/meta_data.rb', line 10

def path_parameters
  @path_parameters
end

#post_dictObject

Returns the value of attribute post_dict.



10
11
12
# File 'lib/tcell_agent/appsensor/meta_data.rb', line 10

def post_dict
  @post_dict
end

#remote_addressObject

Returns the value of attribute remote_address.



10
11
12
# File 'lib/tcell_agent/appsensor/meta_data.rb', line 10

def remote_address
  @remote_address
end

#route_idObject

Returns the value of attribute route_id.



10
11
12
# File 'lib/tcell_agent/appsensor/meta_data.rb', line 10

def route_id
  @route_id
end

#session_idObject

Returns the value of attribute session_id.



10
11
12
# File 'lib/tcell_agent/appsensor/meta_data.rb', line 10

def session_id
  @session_id
end

#transaction_idObject

Returns the value of attribute transaction_id.



10
11
12
# File 'lib/tcell_agent/appsensor/meta_data.rb', line 10

def transaction_id
  @transaction_id
end

#user_idObject

Returns the value of attribute user_id.



10
11
12
# File 'lib/tcell_agent/appsensor/meta_data.rb', line 10

def user_id
  @user_id
end

Instance Method Details

#flattened_body_dictObject



76
77
78
# File 'lib/tcell_agent/appsensor/meta_data.rb', line 76

def flattened_body_dict
  @body_dict
end


80
81
82
83
84
# File 'lib/tcell_agent/appsensor/meta_data.rb', line 80

def flattened_cookie_dict
  @flattened_cookie_dict ||= TCellAgent::Utils::Params.flatten(@cookie_dict)

  @flattened_cookie_dict
end

#flattened_get_dictObject



64
65
66
67
68
# File 'lib/tcell_agent/appsensor/meta_data.rb', line 64

def flattened_get_dict
  @flattened_get_dict ||= TCellAgent::Utils::Params.flatten(@get_dict)

  @flattened_get_dict
end

#flattened_headers_dictObject



86
87
88
89
90
# File 'lib/tcell_agent/appsensor/meta_data.rb', line 86

def flattened_headers_dict
  @flattened_headers_dict ||= TCellAgent::Utils::Params.flatten(@headers_dict)

  @flattened_headers_dict
end

#flattened_path_parametersObject



58
59
60
61
62
# File 'lib/tcell_agent/appsensor/meta_data.rb', line 58

def flattened_path_parameters
  @flattened_path_parameters ||= TCellAgent::Utils::Params.flatten(@path_parameters)

  @flattened_path_parameters
end

#flattened_post_dictObject



70
71
72
73
74
# File 'lib/tcell_agent/appsensor/meta_data.rb', line 70

def flattened_post_dict
  @flattened_post_dict ||= TCellAgent::Utils::Params.flatten(@post_dict)

  @flattened_post_dict
end

#set_body_dict(request_content_bytes_len, request_content_type, request_body) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/tcell_agent/appsensor/meta_data.rb', line 104

def set_body_dict(request_content_bytes_len, request_content_type, request_body)
  if request_content_bytes_len > 2000000
    @body_dict = {}

  else
    if request_content_type =~ %r{application/json}i && request_body
      begin
        # don't enqueue parameter values of unknown type to avoid any serialization issues
        @body_dict = TCellAgent::Utils::Params.flatten(JSON.parse(request_body))
      rescue
        TCellAgent.logger.debug("JSON body parameter parsing failed")
        @body_dict = {}
      end
    else
      @body_dict = {}
    end
  end
end

#set_headers_dict(env) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/tcell_agent/appsensor/meta_data.rb', line 92

def set_headers_dict(env)
  @flattened_headers_dict = nil
  @headers_dict = env.select { |k,v|
    header_downcased = k.downcase
    (header_downcased != "http_cookie" && header_downcased.start_with?('http_')) ||
      ["content_type", "content_length"].include?(header_downcased)
  }.inject({}) { |memo, (k,v)|
    memo[k.downcase.sub(/^http_/, '').gsub('_', '-')] = v
    memo
  }
end