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 AppSensor::MetaData

#body_dict, #cookie_dict, #get_dict, #headers_dict, #method, #path_parameters, #post_dict, #remote_address, #route_id, #session_id, #transaction_id, #user_id

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_headers_dict, #flattened_path_parameters, #set_body_dict, #set_headers_dict

Methods inherited from TCellSensorEvent

#bucket_key, #calculateOffset

Constructor Details

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

Returns a new instance of AppSensorMetaEvent.



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

def initialize(method, remote_address, route_id, session_id, user_id, transaction_id)
  super(method, remote_address, route_id, session_id, user_id, transaction_id)

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

Instance Attribute Details

#csrf_exception_nameObject

Returns the value of attribute csrf_exception_name.



87
88
89
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 87

def csrf_exception_name
  @csrf_exception_name
end

#database_result_sizesObject

Returns the value of attribute database_result_sizes.



87
88
89
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 87

def database_result_sizes
  @database_result_sizes
end

#locationObject

Returns the value of attribute location.



87
88
89
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 87

def location
  @location
end

#pathObject

Returns the value of attribute path.



87
88
89
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 87

def path
  @path
end

#request_content_bytes_lenObject

Returns the value of attribute request_content_bytes_len.



87
88
89
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 87

def request_content_bytes_len
  @request_content_bytes_len
end

#response_codeObject

Returns the value of attribute response_code.



87
88
89
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 87

def response_code
  @response_code
end

#response_content_bytes_lenObject

Returns the value of attribute response_content_bytes_len.



87
88
89
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 87

def response_content_bytes_len
  @response_content_bytes_len
end

#response_headersObject

Returns the value of attribute response_headers.



87
88
89
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 87

def response_headers
  @response_headers
end

#sql_exceptionsObject

Returns the value of attribute sql_exceptions.



87
88
89
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 87

def sql_exceptions
  @sql_exceptions
end

#user_agentObject

Returns the value of attribute user_agent.



87
88
89
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 87

def user_agent
  @user_agent
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
62
63
64
65
66
67
68
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 23

def build(request, response_content_length, response_code, response_headers)
  tcell_context = request.env[TCellAgent::Instrumentation::TCELL_ID]
  meta_event = AppSensorMetaEvent.new(
    request.request_method,
    TCellAgent::Utils::Rails.better_ip(request),
    tcell_context.route_id,
    tcell_context.hmac_session_id,
    tcell_context.user_id,
    tcell_context.transaction_id
  )

  meta_event.csrf_exception_name = tcell_context.csrf_exception_name
  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.location = "#{request.base_url}#{request.fullpath}"
  meta_event.path = request.path

  meta_event.get_dict = request.GET
  meta_event.cookie_dict = request.cookies
  meta_event.set_headers_dict(request.env)

  # 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.path_parameters = request.env[TCellAgent::Instrumentation::TCELL_ID].path_parameters
  meta_event.response_code = response_code
  meta_event.response_headers = response_headers

  meta_event.sql_exceptions = tcell_context.sql_exceptions
  meta_event.database_result_sizes = tcell_context.database_result_sizes

  # 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



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 70

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

  meta_event.location = appsensor_meta.location

  meta_event
end

Instance Method Details

#flattened_post_dictObject



106
107
108
# File 'lib/tcell_agent/sensor_events/appsensor_meta_event.rb', line 106

def flattened_post_dict
  @post_dict
end

#post_processObject



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

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

  appsensor_policy.process_meta_event(self)
end