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

Instance Method Details

#assign_agent_attributes(state) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 86

def assign_agent_attributes(state)

  @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);
  @attributes.add_agent_attribute(:trace_id, state.trace_id || "0")
end

#best_nameObject



50
51
52
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 50

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
26
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 16

def create_nested_frame(state, category, options)

  if options[:filtered_params] && !options[:filtered_params].empty?
    attributes.merge_request_parameters(options[:filtered_params])
  end
  @has_children = true
  frame_stack.push TingYun::Agent::MethodTracerHelpers.trace_execution_scoped_header(state, Time.now.to_f)
  name_last_frame(options[:transaction_name])

  set_default_transaction_name(options[:transaction_name], category)
end

#freeze_name_and_executeObject



134
135
136
137
138
139
140
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 134

def freeze_name_and_execute
  unless @frozen_name
    @frozen_name = best_name
  end
  @frozen_name = CONTROLLER_PREFIX + @frozen_name unless @frozen_name.start_with? CONTROLLER_PREFIX,BACKGROUND_PREFIX
  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

Returns:

  • (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

Returns:

  • (Boolean)


55
56
57
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 55

def influences_transaction_name?(category)
  !category || frame_stack.size == 1 || similar_category?(category)
end

#instrumentation_stateObject

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.



114
115
116
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 114

def instrumentation_state
  @instrumentation_state ||= {}
end

#make_transaction_name(name, category = nil) ⇒ Object



40
41
42
43
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 40

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



45
46
47
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 45

def name_last_frame(name)
  frame_stack.last.name = name
end

#needs_middleware_summary_metrics?(name) ⇒ Boolean Also known as: ignore

Returns:

  • (Boolean)


70
71
72
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 70

def needs_middleware_summary_metrics?(name)
  name.start_with?(MIDDLEWARE_PREFIX)
end

#record_summary_metrics(state, outermost_node_name, end_time) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 76

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



29
30
31
32
33
34
35
36
37
38
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 29

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

Returns:

  • (Boolean)


65
66
67
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 65

def similar_category?(category)
  web_category?(@category) == web_category?(category)
end

#web_category?(category) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 61

def web_category?(category)
  WEB_TRANSACTION_CATEGORIES.include?(category)
end

#with_database_metric_name(model, method, product = nil) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/ting_yun/agent/transaction/instance_method.rb', line 118

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