Module: TingYun::Agent::Transaction::InstanceMethod
- Included in:
- TingYun::Agent::Transaction
- Defined in:
- lib/ting_yun/agent/transaction/instance_method.rb
Constant Summary collapse
- WEB_TRANSACTION_CATEGORIES =
[:controller, :uri, :rack, :sinatra, :grape, :middleware, :thrift, :action_cable, :message].freeze
- HEX_DIGITS =
(0..15).map{|i| i.to_s(16)}
- GUID_LENGTH =
16
Instance Method Summary collapse
- #assign_agent_attributes(state) ⇒ Object
- #best_name ⇒ Object
- #create_nested_frame(state, category, options) ⇒ Object
- #freeze_name_and_execute ⇒ Object
- #ignore! ⇒ Object
- #ignore? ⇒ Boolean
- #influences_transaction_name?(category) ⇒ Boolean
-
#instrumentation_state ⇒ Object
This transaction-local hash may be used as temprory storage by instrumentation that needs to pass data from one instrumentation point to another.
- #make_transaction_name(name, category = nil) ⇒ Object
- #name_last_frame(name) ⇒ Object
- #needs_middleware_summary_metrics?(name) ⇒ Boolean (also: #ignore)
- #record_summary_metrics(state, outermost_node_name, end_time) ⇒ Object
- #set_default_transaction_name(name, category) ⇒ Object
- #similar_category?(category) ⇒ Boolean
- #web_category?(category) ⇒ Boolean
- #with_database_metric_name(model, method, product = nil) ⇒ Object
Instance Method Details
#assign_agent_attributes(state) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 85 def assign_agent_attributes(state) @attributes.add_agent_attribute(:threadName, "pid-#{$$}"); if @request_attributes @request_attributes.assign_agent_attributes @attributes @request_attributes.assign_user_info_attributes @attributes end @attributes.add_agent_attribute(:tx_id, @guid); @attributes.add_agent_attribute(:tmd5, state.transaction_name_md5); @attributes.add_agent_attribute(:metric_name, best_name); @attributes.add_agent_attribute(:trace_id, state.trace_id || "0") @attributes.add_agent_attribute(:refid, state.extenel_req_id) @attributes.add_agent_attribute(:cross, state.call_list) end |
#best_name ⇒ Object
49 50 51 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 49 def best_name @frozen_name || @default_name || ::TingYun::Agent::UNKNOWN_METRIC end |
#create_nested_frame(state, category, options) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 16 def create_nested_frame(state, category, ) if [:filtered_params] && ![:filtered_params].empty? attributes.merge_request_parameters([:filtered_params]) end state.add_current_node_params(:method => [:method]) unless [:method].nil? @has_children = true frame_stack.push TingYun::Agent::MethodTracerHelpers.trace_execution_scoped_header(state, Time.now.to_f) name_last_frame([:transaction_name]) set_default_transaction_name("#{state.action_type}/#{[:transaction_name]}", category) end |
#freeze_name_and_execute ⇒ Object
137 138 139 140 141 142 143 144 145 146 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 137 def freeze_name_and_execute unless @frozen_name @frozen_name = best_name end state = TingYun::Agent::TransactionState.tl_get unless @frozen_name.start_with? CONTROLLER_PREFIX, BACKGROUND_PREFIX, COSS_CONTROLLER_PREFIX @frozen_name = state.action_type + @frozen_name end yield if block_given? end |
#ignore! ⇒ Object
8 9 10 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 8 def ignore! @ignore_this_transaction = true end |
#ignore? ⇒ Boolean
12 13 14 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 12 def ignore? @ignore_this_transaction end |
#influences_transaction_name?(category) ⇒ Boolean
54 55 56 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 54 def influences_transaction_name?(category) !category || frame_stack.size == 1 || similar_category?(category) end |
#instrumentation_state ⇒ Object
This transaction-local hash may be used as temprory storage by instrumentation that needs to pass data from one instrumentation point to another.
For example, if both A and B are instrumented, and A calls B but some piece of state needed by the instrumentation at B is only available at A, the instrumentation at A may write into the hash, call through, and then remove the key afterwards, allowing the instrumentation at B to read the value in between.
Keys should be symbols, and care should be taken to not generate key names dynamically, and to ensure that keys are removed upon return from the method that creates them.
117 118 119 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 117 def instrumentation_state @instrumentation_state ||= {} end |
#make_transaction_name(name, category = nil) ⇒ Object
39 40 41 42 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 39 def make_transaction_name(name, category=nil) namer = TingYun::Instrumentation::Support::TransactionNamer "#{namer.prefix_for_category(self, category)}#{name}" end |
#name_last_frame(name) ⇒ Object
44 45 46 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 44 def name_last_frame(name) frame_stack.last.name = name end |
#needs_middleware_summary_metrics?(name) ⇒ Boolean Also known as: ignore
69 70 71 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 69 def needs_middleware_summary_metrics?(name) name.start_with?(MIDDLEWARE_PREFIX) end |
#record_summary_metrics(state, outermost_node_name, end_time) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 75 def record_summary_metrics(state, outermost_node_name,end_time) unless @frozen_name == outermost_node_name time = (end_time - start_time) * 1000 @metrics.record_unscoped(@frozen_name, time) if @frozen_name.start_with?('WebAction') state.current_transaction.base_quantile_hash[@frozen_name] = time end end end |
#set_default_transaction_name(name, category) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 28 def set_default_transaction_name(name, category) if @frozen_name TingYun::Agent.logger.warn("Attempted to rename transaction to '#{name}' after transaction name was already frozen as '#{@frozen_name}'.") return end if influences_transaction_name?(category) @default_name = name @category = category if category end end |
#similar_category?(category) ⇒ Boolean
64 65 66 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 64 def similar_category?(category) web_category?(@category) == web_category?(category) end |
#web_category?(category) ⇒ Boolean
60 61 62 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 60 def web_category?(category) WEB_TRANSACTION_CATEGORIES.include?(category) end |
#with_database_metric_name(model, method, product = nil) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 121 def with_database_metric_name(model, method, product=nil) previous = self.instrumentation_state[:datastore_override] model_name = case model when Class model.name when String model else model.to_s end @instrumentation_state[:datastore_override] = [method, model_name, product] yield ensure @instrumentation_state[:datastore_override] = previous end |