Class: TCellAgent::MetaData
- Inherits:
-
Object
- Object
- TCellAgent::MetaData
- Defined in:
- lib/tcell_agent/tcell_context.rb
Instance Attribute Summary collapse
-
#csrf_exception_name ⇒ Object
Returns the value of attribute csrf_exception_name.
-
#database_result_sizes ⇒ Object
Returns the value of attribute database_result_sizes.
-
#flattened_body_dict ⇒ Object
readonly
Returns the value of attribute flattened_body_dict.
-
#flattened_cookie_dict ⇒ Object
readonly
Returns the value of attribute flattened_cookie_dict.
-
#flattened_get_dict ⇒ Object
readonly
Returns the value of attribute flattened_get_dict.
-
#flattened_headers_dict ⇒ Object
readonly
Returns the value of attribute flattened_headers_dict.
-
#flattened_path_parameters ⇒ Object
readonly
Returns the value of attribute flattened_path_parameters.
-
#flattened_post_dict ⇒ Object
readonly
Returns the value of attribute flattened_post_dict.
-
#location ⇒ Object
Returns the value of attribute location.
-
#method ⇒ Object
Returns the value of attribute method.
-
#path ⇒ Object
Returns the value of attribute path.
-
#remote_address ⇒ Object
Returns the value of attribute remote_address.
-
#request_content_bytes_len ⇒ Object
Returns the value of attribute request_content_bytes_len.
-
#response_code ⇒ Object
Returns the value of attribute response_code.
-
#response_content_bytes_len ⇒ Object
Returns the value of attribute response_content_bytes_len.
-
#response_headers ⇒ Object
Returns the value of attribute response_headers.
-
#route_id ⇒ Object
Returns the value of attribute route_id.
-
#session_id ⇒ Object
Returns the value of attribute session_id.
-
#sql_exceptions ⇒ Object
Returns the value of attribute sql_exceptions.
-
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
-
#user_agent ⇒ Object
Returns the value of attribute user_agent.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
Class Method Summary collapse
Instance Method Summary collapse
- #cookie_dict=(value) ⇒ Object
- #get_dict=(value) ⇒ Object
- #headers_dict=(value) ⇒ Object
-
#initialize(method, remote_address, route_id, session_id, user_id, transaction_id, location) ⇒ MetaData
constructor
A new instance of MetaData.
- #path_parameters=(value) ⇒ Object
- #post_dict=(value) ⇒ Object
- #set_body_dict(request_content_bytes_len, request_content_type, request_body) ⇒ Object
- #set_parameter_dicts(request) ⇒ Object
Constructor Details
#initialize(method, remote_address, route_id, session_id, user_id, transaction_id, location) ⇒ MetaData
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/tcell_agent/tcell_context.rb', line 57 def initialize(method, remote_address, route_id, session_id, user_id, transaction_id, location) @method = method @remote_address = remote_address @route_id = route_id @session_id = session_id @user_id = user_id @transaction_id = transaction_id @location = location @path = path @flattened_get_dict = {} = {} @flattened_path_parameters = {} # POST/body dict can contain files, so always flatten it # to get rid of those and to make this model serializable @flattened_post_dict = {} @flattened_body_dict = {} @request_content_bytes_len = 0 @response_content_bytes_len = 0 @user_agent = nil end |
Instance Attribute Details
#csrf_exception_name ⇒ Object
Returns the value of attribute csrf_exception_name.
33 34 35 |
# File 'lib/tcell_agent/tcell_context.rb', line 33 def csrf_exception_name @csrf_exception_name end |
#database_result_sizes ⇒ Object
Returns the value of attribute database_result_sizes.
33 34 35 |
# File 'lib/tcell_agent/tcell_context.rb', line 33 def database_result_sizes @database_result_sizes end |
#flattened_body_dict ⇒ Object (readonly)
Returns the value of attribute flattened_body_dict.
50 51 52 |
# File 'lib/tcell_agent/tcell_context.rb', line 50 def flattened_body_dict @flattened_body_dict end |
#flattened_cookie_dict ⇒ Object (readonly)
Returns the value of attribute flattened_cookie_dict.
50 51 52 |
# File 'lib/tcell_agent/tcell_context.rb', line 50 def end |
#flattened_get_dict ⇒ Object (readonly)
Returns the value of attribute flattened_get_dict.
50 51 52 |
# File 'lib/tcell_agent/tcell_context.rb', line 50 def flattened_get_dict @flattened_get_dict end |
#flattened_headers_dict ⇒ Object (readonly)
Returns the value of attribute flattened_headers_dict.
50 51 52 |
# File 'lib/tcell_agent/tcell_context.rb', line 50 def flattened_headers_dict @flattened_headers_dict end |
#flattened_path_parameters ⇒ Object (readonly)
Returns the value of attribute flattened_path_parameters.
50 51 52 |
# File 'lib/tcell_agent/tcell_context.rb', line 50 def flattened_path_parameters @flattened_path_parameters end |
#flattened_post_dict ⇒ Object (readonly)
Returns the value of attribute flattened_post_dict.
50 51 52 |
# File 'lib/tcell_agent/tcell_context.rb', line 50 def flattened_post_dict @flattened_post_dict end |
#location ⇒ Object
Returns the value of attribute location.
33 34 35 |
# File 'lib/tcell_agent/tcell_context.rb', line 33 def location @location end |
#method ⇒ Object
Returns the value of attribute method.
33 34 35 |
# File 'lib/tcell_agent/tcell_context.rb', line 33 def method @method end |
#path ⇒ Object
Returns the value of attribute path.
33 34 35 |
# File 'lib/tcell_agent/tcell_context.rb', line 33 def path @path end |
#remote_address ⇒ Object
Returns the value of attribute remote_address.
33 34 35 |
# File 'lib/tcell_agent/tcell_context.rb', line 33 def remote_address @remote_address end |
#request_content_bytes_len ⇒ Object
Returns the value of attribute request_content_bytes_len.
33 34 35 |
# File 'lib/tcell_agent/tcell_context.rb', line 33 def request_content_bytes_len @request_content_bytes_len end |
#response_code ⇒ Object
Returns the value of attribute response_code.
33 34 35 |
# File 'lib/tcell_agent/tcell_context.rb', line 33 def response_code @response_code end |
#response_content_bytes_len ⇒ Object
Returns the value of attribute response_content_bytes_len.
33 34 35 |
# File 'lib/tcell_agent/tcell_context.rb', line 33 def response_content_bytes_len @response_content_bytes_len end |
#response_headers ⇒ Object
Returns the value of attribute response_headers.
33 34 35 |
# File 'lib/tcell_agent/tcell_context.rb', line 33 def response_headers @response_headers end |
#route_id ⇒ Object
Returns the value of attribute route_id.
33 34 35 |
# File 'lib/tcell_agent/tcell_context.rb', line 33 def route_id @route_id end |
#session_id ⇒ Object
Returns the value of attribute session_id.
33 34 35 |
# File 'lib/tcell_agent/tcell_context.rb', line 33 def session_id @session_id end |
#sql_exceptions ⇒ Object
Returns the value of attribute sql_exceptions.
33 34 35 |
# File 'lib/tcell_agent/tcell_context.rb', line 33 def sql_exceptions @sql_exceptions end |
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
33 34 35 |
# File 'lib/tcell_agent/tcell_context.rb', line 33 def transaction_id @transaction_id end |
#user_agent ⇒ Object
Returns the value of attribute user_agent.
33 34 35 |
# File 'lib/tcell_agent/tcell_context.rb', line 33 def user_agent @user_agent end |
#user_id ⇒ Object
Returns the value of attribute user_id.
33 34 35 |
# File 'lib/tcell_agent/tcell_context.rb', line 33 def user_id @user_id end |
Class Method Details
.from_request(request) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/tcell_agent/tcell_context.rb', line 10 def from_request(request) tcell_context = request.env[TCellAgent::Instrumentation::TCELL_ID] # use uri stored in tcell_context because # rails modifies original request.url # to always return /404 (or whatever error code # it encountered) = MetaData.new( tcell_context.request_method, tcell_context.ip_address, tcell_context.route_id, tcell_context.hmac_session_id, tcell_context.user_id, tcell_context.transaction_id, tcell_context.uri ) .path = tcell_context.path .set_parameter_dicts(request) end |
Instance Method Details
#cookie_dict=(value) ⇒ Object
91 92 93 |
# File 'lib/tcell_agent/tcell_context.rb', line 91 def (value) = TCellAgent::Utils::Params.flatten(value) end |
#get_dict=(value) ⇒ Object
87 88 89 |
# File 'lib/tcell_agent/tcell_context.rb', line 87 def get_dict=(value) @flattened_get_dict = TCellAgent::Utils::Params.flatten(value) end |
#headers_dict=(value) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/tcell_agent/tcell_context.rb', line 95 def headers_dict=(value) headers_dict = value.select do |k, _v| header_downcased = k.downcase (header_downcased != 'http_cookie' && header_downcased.start_with?('http_')) || %w[content_type content_length].include?(header_downcased) end headers_dict = headers_dict.each_with_object({}) do |(k, v), memo| memo[k.downcase.sub(/^http_/, '').tr('_', '-')] = v end @flattened_headers_dict = TCellAgent::Utils::Params.flatten(headers_dict) end |
#path_parameters=(value) ⇒ Object
112 113 114 |
# File 'lib/tcell_agent/tcell_context.rb', line 112 def path_parameters=(value) @flattened_path_parameters = TCellAgent::Utils::Params.flatten(value) end |
#post_dict=(value) ⇒ Object
108 109 110 |
# File 'lib/tcell_agent/tcell_context.rb', line 108 def post_dict=(value) @flattened_post_dict = TCellAgent::Utils::Params.flatten(value) end |
#set_body_dict(request_content_bytes_len, request_content_type, request_body) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/tcell_agent/tcell_context.rb', line 135 def set_body_dict(request_content_bytes_len, request_content_type, request_body) @flattened_body_dict = {} return if request_content_bytes_len > 2_000_000 return unless request_body && (request_content_type =~ %r{application/json}i) begin # don't enqueue parameter values of unknown type to avoid any serialization issues @flattened_body_dict = TCellAgent::Utils::Params.flatten(JSON.parse(request_body)) rescue JSON::ParserError TCellAgent.logger.debug('JSON body parameter parsing failed') end end |
#set_parameter_dicts(request) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/tcell_agent/tcell_context.rb', line 116 def set_parameter_dicts(request) self.get_dict = request.GET self. = request. self.post_dict = request.POST self.headers_dict = request.env # 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 @request_content_bytes_len = (request.content_length || 0).to_i set_body_dict( @request_content_bytes_len, request.content_type, request.body.gets ) end |