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, location) ⇒ MetaData

Returns a new instance of MetaData.



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

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

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

  @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

#locationObject

Returns the value of attribute location.



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

def location
  @location
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



83
84
85
# File 'lib/tcell_agent/appsensor/meta_data.rb', line 83

def flattened_body_dict
  @body_dict
end


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

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

  @flattened_cookie_dict
end

#flattened_get_dictObject



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

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

  @flattened_get_dict
end

#flattened_headers_dictObject



93
94
95
96
97
# File 'lib/tcell_agent/appsensor/meta_data.rb', line 93

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

  @flattened_headers_dict
end

#flattened_path_parametersObject



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

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

  @flattened_path_parameters
end

#flattened_post_dictObject



77
78
79
80
81
# File 'lib/tcell_agent/appsensor/meta_data.rb', line 77

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



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/tcell_agent/appsensor/meta_data.rb', line 111

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 JSON::ParserError
        TCellAgent.logger.debug("JSON body parameter parsing failed")
        @body_dict = {}
      end
    else
      @body_dict = {}
    end
  end
end

#set_headers_dict(env) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/tcell_agent/appsensor/meta_data.rb', line 99

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_/, '').tr('_', '-')] = v
    memo
  }
end