Class: TCellAgent::SensorEvents::AppSensorMetaEvent

Inherits:
TCellSensorEvent 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 TCellSensorEvent

#bucket_key, #calculateOffset

Constructor Details

#initializeAppSensorMetaEvent

Returns a new instance of AppSensorMetaEvent.



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 60

def initialize
  @request_content_len = 0
  @response_content_len = 0
  @send = false
  @body_dict = {}
  @get_dict = {}
  @post_dict = {}
  @cookie_dict = {}
  @user_agent = nil
  @path_parameters = {}
end

Instance Attribute Details

#body_dictObject

Returns the value of attribute body_dict.



54
55
56
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 54

def body_dict
  @body_dict
end

Returns the value of attribute cookie_dict.



54
55
56
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 54

def cookie_dict
  @cookie_dict
end

#get_dictObject

Returns the value of attribute get_dict.



54
55
56
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 54

def get_dict
  @get_dict
end

#locationObject

Returns the value of attribute location.



54
55
56
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 54

def location
  @location
end

#methodObject

Returns the value of attribute method.



54
55
56
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 54

def method
  @method
end

#path_parametersObject

Returns the value of attribute path_parameters.



54
55
56
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 54

def path_parameters
  @path_parameters
end

#post_dictObject

Returns the value of attribute post_dict.



54
55
56
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 54

def post_dict
  @post_dict
end

#remote_addressObject

Returns the value of attribute remote_address.



54
55
56
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 54

def remote_address
  @remote_address
end

#request_content_lenObject

Returns the value of attribute request_content_len.



54
55
56
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 54

def request_content_len
  @request_content_len
end

#request_headersObject

Returns the value of attribute request_headers.



58
59
60
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 58

def request_headers
  @request_headers
end

#response_codeObject

Returns the value of attribute response_code.



54
55
56
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 54

def response_code
  @response_code
end

#response_content_lenObject

Returns the value of attribute response_content_len.



54
55
56
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 54

def response_content_len
  @response_content_len
end

#response_headersObject

Returns the value of attribute response_headers.



58
59
60
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 58

def response_headers
  @response_headers
end

#route_idObject

Returns the value of attribute route_id.



54
55
56
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 54

def route_id
  @route_id
end

#session_idObject

Returns the value of attribute session_id.



54
55
56
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 54

def session_id
  @session_id
end

#transaction_idObject

Returns the value of attribute transaction_id.



54
55
56
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 54

def transaction_id
  @transaction_id
end

#user_agentObject

Returns the value of attribute user_agent.



54
55
56
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 54

def user_agent
  @user_agent
end

#user_idObject

Returns the value of attribute user_id.



54
55
56
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 54

def user_id
  @user_id
end

Class Method Details

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



20
21
22
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
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 20

def build(request, rack_response, 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_len = (request.content_length || "0").to_i
  meta_event.response_content_len = (rack_response.length || "0").to_i
  meta_event.get_dict = request.GET
  meta_event.post_dict = request.POST
  meta_event.cookie_dict = request.cookies

  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

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

  meta_event
end

Instance Method Details

#post_processObject



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

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

  appsensor_policy.process_meta_event(self)
end

#set_body_dict(request_content_len, request_content_type, request_body) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 72

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

  else
    if request_content_type =~ %r{application/json}i && request_body
      begin
        @body_dict = JSON.parse(request_body)
      rescue
        TCellAgent.logger.debug("JSON body parameter parsing failed")
        @body_dict = {}
      end
    else
      @body_dict = {}
    end
  end
end