Class: TCellAgent::SensorEvents::AppSensorMetaEvent

Inherits:
AppSensor::MetaData show all
Defined in:
lib/tcell_agent/sensor_events/appsensor_meta_event.rb

Instance Attribute Summary collapse

Attributes inherited from TCellSensorEvent

#ensure, #flush, #send

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AppSensor::MetaData

#flattened_body_dict, #flattened_cookie_dict, #flattened_get_dict, #flattened_path_parameters, #set_body_dict

Methods inherited from TCellSensorEvent

#bucket_key, #calculateOffset

Constructor Details

#initializeAppSensorMetaEvent

Returns a new instance of AppSensorMetaEvent.



84
85
86
87
88
89
90
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 84

def initialize
  super

  @request_content_bytes_len = 0
  @response_content_bytes_len = 0
  @user_agent = nil
end

Instance Attribute Details

#body_dictObject

Returns the value of attribute body_dict.



78
79
80
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 78

def body_dict
  @body_dict
end

Returns the value of attribute cookie_dict.



78
79
80
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 78

def cookie_dict
  @cookie_dict
end

#get_dictObject

Returns the value of attribute get_dict.



78
79
80
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 78

def get_dict
  @get_dict
end

#locationObject

Returns the value of attribute location.



78
79
80
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 78

def location
  @location
end

#methodObject

Returns the value of attribute method.



78
79
80
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 78

def method
  @method
end

#path_parametersObject

Returns the value of attribute path_parameters.



78
79
80
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 78

def path_parameters
  @path_parameters
end

#post_dictObject

Returns the value of attribute post_dict.



78
79
80
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 78

def post_dict
  @post_dict
end

#remote_addressObject

Returns the value of attribute remote_address.



78
79
80
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 78

def remote_address
  @remote_address
end

#request_content_bytes_lenObject

Returns the value of attribute request_content_bytes_len.



78
79
80
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 78

def request_content_bytes_len
  @request_content_bytes_len
end

#request_headersObject

Returns the value of attribute request_headers.



82
83
84
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 82

def request_headers
  @request_headers
end

#response_codeObject

Returns the value of attribute response_code.



78
79
80
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 78

def response_code
  @response_code
end

#response_content_bytes_lenObject

Returns the value of attribute response_content_bytes_len.



78
79
80
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 78

def response_content_bytes_len
  @response_content_bytes_len
end

#response_headersObject

Returns the value of attribute response_headers.



82
83
84
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 82

def response_headers
  @response_headers
end

#route_idObject

Returns the value of attribute route_id.



78
79
80
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 78

def route_id
  @route_id
end

#session_idObject

Returns the value of attribute session_id.



78
79
80
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 78

def session_id
  @session_id
end

#transaction_idObject

Returns the value of attribute transaction_id.



78
79
80
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 78

def transaction_id
  @transaction_id
end

#user_agentObject

Returns the value of attribute user_agent.



78
79
80
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 78

def user_agent
  @user_agent
end

#user_idObject

Returns the value of attribute user_id.



78
79
80
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 78

def user_id
  @user_id
end

Class Method Details

.build(request, response_content_length, response_code, response_headers) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 23

def build(request, response_content_length, response_code, response_headers)
  meta_event = AppSensorMetaEvent.new

  meta_event.remote_address = TCellAgent::Utils::Rails.better_ip(request)
  meta_event.method = request.request_method
  meta_event.location = "#{request.base_url}#{request.fullpath}"
  meta_event.request_headers = request.env
  meta_event.user_agent = request.env['HTTP_USER_AGENT']
  meta_event.request_content_bytes_len = (request.content_length || 0).to_i
  meta_event.response_content_bytes_len = response_content_length

  meta_event.get_dict = request.GET
  meta_event.cookie_dict = request.cookies

  # don't enqueue parameter values of unknown type to avoid any serialization issues
  meta_event.post_dict = TCellAgent::Utils::Params.flatten(request.POST)

  meta_event.response_code = response_code
  meta_event.response_headers = response_headers

  meta_event.path_parameters = request.env[TCellAgent::Instrumentation::TCELL_ID].path_parameters
  meta_event.route_id = request.env[TCellAgent::Instrumentation::TCELL_ID].route_id
  meta_event.transaction_id = request.env[TCellAgent::Instrumentation::TCELL_ID].transaction_id
  meta_event.session_id = request.env[TCellAgent::Instrumentation::TCELL_ID].hmac_session_id
  meta_event.user_id = request.env[TCellAgent::Instrumentation::TCELL_ID].user_id

  # Positions strio to the beginning of input, resetting lineno to zero.
  # rails 4.1 seems to read the stringIO directly and so body.gets is empty
  # this is called
  request.body.rewind

  meta_event.set_body_dict(
    meta_event.request_content_bytes_len,
    request.content_type,
    request.body.gets
  )

  meta_event
end

.build_basic(appsensor_meta) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 63

def build_basic(appsensor_meta)
  meta_event = AppSensorMetaEvent.new
  meta_event.location = appsensor_meta.location
  meta_event.method =appsensor_meta.method
  meta_event.remote_address = appsensor_meta.remote_address
  meta_event.route_id = appsensor_meta.route_id
  meta_event.session_id = appsensor_meta.session_id
  meta_event.user_id = appsensor_meta.user_id
  meta_event.route_id = appsensor_meta.route_id

  meta_event
end

Instance Method Details

#flattened_post_dictObject



99
100
101
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 99

def flattened_post_dict
  @post_dict
end

#post_processObject



92
93
94
95
96
97
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 92

def post_process
  appsensor_policy = TCellAgent.policy(TCellAgent::PolicyTypes::AppSensor)
  return unless appsensor_policy

  appsensor_policy.process_meta_event(self)
end