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 ⇒ 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 ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 82 def assign_agent_attributes @attributes.add_agent_attribute(:threadName, "pid-#{$$}"); if @request_attributes @request_attributes.assign_agent_attributes @attributes end @attributes.add_agent_attribute(:tx_id, @guid); @attributes.add_agent_attribute(:metric_name, best_name); end |
#best_name ⇒ Object
46 47 48 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 46 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 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 16 def create_nested_frame(state, category, ) @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([:transaction_name], category) end |
#freeze_name_and_execute ⇒ Object
130 131 132 133 134 135 136 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 130 def freeze_name_and_execute unless @frozen_name @frozen_name = best_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
51 52 53 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 51 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.
110 111 112 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 110 def instrumentation_state @instrumentation_state ||= {} end |
#make_transaction_name(name, category = nil) ⇒ Object
36 37 38 39 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 36 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
41 42 43 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 41 def name_last_frame(name) frame_stack.last.name = name end |
#needs_middleware_summary_metrics?(name) ⇒ Boolean Also known as: ignore
66 67 68 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 66 def needs_middleware_summary_metrics?(name) name.start_with?(MIDDLEWARE_PREFIX) end |
#record_summary_metrics(state, outermost_node_name, end_time) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 72 def record_summary_metrics(state, outermost_node_name,end_time) unless @frozen_name == outermost_node_name time = (end_time.to_f - start_time.to_f) * 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
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 25 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
61 62 63 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 61 def similar_category?(category) web_category?(@category) == web_category?(category) end |
#web_category?(category) ⇒ Boolean
57 58 59 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 57 def web_category?(category) WEB_TRANSACTION_CATEGORIES.include?(category) end |
#with_database_metric_name(model, method, product = nil) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 114 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 |