Module: TingYun::Agent::Collector::TransactionSampler::ClassMethod
- Included in:
- TingYun::Agent::Collector::TransactionSampler
- Defined in:
- lib/ting_yun/agent/collector/transaction_sampler/class_method.rb
Constant Summary collapse
- MAX_DATA_LENGTH =
16384
Instance Method Summary collapse
-
#action_tracer_segment(builder, message, duration, key) ⇒ Object
This method is used to record metadata into the currently active node like a sql query, memcache key, or Net::HTTP uri.
- #add_node_info(params) ⇒ Object
-
#append_backtrace(node, duration) ⇒ Object
Appends a backtrace to a node if that node took longer than the specified duration.
-
#notice_nosql(config, duration, key) ⇒ Object
duration=> sec.
-
#notice_nosql_statement(statement, duration, key = :statement) ⇒ Object
duration=> sec.
-
#notice_pop_frame(state, frame, time = Time.now.to_f, klass_name = nil, error = nil) ⇒ Object
Informs the transaction sample builder about the end of a traced frame.
- #notice_push_frame(state, time = Time.now.to_f) ⇒ Object
-
#notice_sql(sql, config, duration, state = nil, explainer = nil, binds = [], name = "SQL") ⇒ Object
Attaches an SQL query on the current transaction trace node.
- #on_start_transaction(state, time) ⇒ Object
- #tl_builder ⇒ Object
-
#truncate_message(message) ⇒ Object
Truncates the message to ‘MAX_DATA_LENGTH` if needed, and appends an ellipsis because it makes the trucation clearer in the UI.
Instance Method Details
#action_tracer_segment(builder, message, duration, key) ⇒ Object
This method is used to record metadata into the currently active node like a sql query, memcache key, or Net::HTTP uri
duration is milliseconds, float value. duration=> sec
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/ting_yun/agent/collector/transaction_sampler/class_method.rb', line 72 def action_tracer_segment(builder, , duration, key) return unless builder node = builder.current_node if node if key == :sql statement = node[:sql] if statement && !statement.sql.empty? statement.sql = (statement.sql + "\n#{.sql}") if statement.sql.length <= MAX_DATA_LENGTH else # message is expected to have been pre-truncated by notice_sql node.klass = .config[:product] node.method = .config[:operation] node.type = .config[:type] node.params_data.merge!(:vendor => .config[:product], :instance=>"#{.config[:host]}:#{.config[:port]}/#{.config[:database]}", :operation => .sql) node[:sql] = end elsif key == :nosql # message is expected to have been pre-truncated by notice_sql node.klass = [:product] node[:method] = [:operation] node.type = [:type] node.params_data.merge!(:vendor => [:product], :instance=>"#{[:host]}:#{[:port]}/#{[:database]}", :operation => [:nosql]) else node[key] = () end append_backtrace(node, duration) end end |
#add_node_info(params) ⇒ Object
130 131 132 133 134 |
# File 'lib/ting_yun/agent/collector/transaction_sampler/class_method.rb', line 130 def add_node_info(params) builder = tl_builder return unless builder params.each { |k,v| builder.current_node.instance_variable_set(('@'<<k.to_s).to_sym, v) } end |
#append_backtrace(node, duration) ⇒ Object
Appends a backtrace to a node if that node took longer than the specified duration
122 123 124 125 126 127 128 |
# File 'lib/ting_yun/agent/collector/transaction_sampler/class_method.rb', line 122 def append_backtrace(node, duration) if duration*1000 >= Agent.config[:'action_tracer.stack_trace_threshold'] trace = caller.reject! { |t| t.include?('tingyun_rpm') } trace = trace.first(20) node.backtrace = trace end end |
#notice_nosql(config, duration, key) ⇒ Object
duration=> sec
51 52 53 54 |
# File 'lib/ting_yun/agent/collector/transaction_sampler/class_method.rb', line 51 def notice_nosql(config, duration,key) #THREAD_LOCAL_ACCESS builder = tl_builder action_tracer_segment(builder, config, duration, key) end |
#notice_nosql_statement(statement, duration, key = :statement) ⇒ Object
duration=> sec
57 58 59 60 |
# File 'lib/ting_yun/agent/collector/transaction_sampler/class_method.rb', line 57 def notice_nosql_statement(statement, duration,key =:statement) #THREAD_LOCAL_ACCESS builder = tl_builder action_tracer_segment(builder, statement, duration,key ) end |
#notice_pop_frame(state, frame, time = Time.now.to_f, klass_name = nil, error = nil) ⇒ Object
Informs the transaction sample builder about the end of a traced frame
17 18 19 20 21 |
# File 'lib/ting_yun/agent/collector/transaction_sampler/class_method.rb', line 17 def notice_pop_frame(state, frame, time = Time.now.to_f, klass_name=nil, error = nil) builder = state.transaction_sample_builder return unless builder builder.trace_exit(frame, time, klass_name, error) end |
#notice_push_frame(state, time = Time.now.to_f) ⇒ Object
10 11 12 13 14 |
# File 'lib/ting_yun/agent/collector/transaction_sampler/class_method.rb', line 10 def notice_push_frame(state, time=Time.now.to_f) builder = state.transaction_sample_builder return unless builder builder.trace_entry(time) end |
#notice_sql(sql, config, duration, state = nil, explainer = nil, binds = [], name = "SQL") ⇒ Object
Attaches an SQL query on the current transaction trace node. duration=> sec
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/ting_yun/agent/collector/transaction_sampler/class_method.rb', line 39 def notice_sql(sql, config, duration, state=nil, explainer=nil, binds=[], name="SQL") # some statements (particularly INSERTS with large BLOBS # may be very large; we should trim them to a maximum usable length state ||= TingYun::Agent::TransactionState.tl_get builder = state.transaction_sample_builder if state.sql_recorded? statement = TingYun::Agent::Database::Statement.new(sql, config, explainer, binds, name) action_tracer_segment(builder, statement, duration, :sql) end end |
#on_start_transaction(state, time) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/ting_yun/agent/collector/transaction_sampler/class_method.rb', line 24 def on_start_transaction(state, time) if TingYun::Agent.config[:'action_tracer.enabled'] state.transaction_sample_builder ||= TingYun::Agent::TransactionSampleBuilder.new(time) else state.transaction_sample_builder = nil end end |
#tl_builder ⇒ Object
136 137 138 |
# File 'lib/ting_yun/agent/collector/transaction_sampler/class_method.rb', line 136 def tl_builder TingYun::Agent::TransactionState.tl_get.transaction_sample_builder end |
#truncate_message(message) ⇒ Object
Truncates the message to ‘MAX_DATA_LENGTH` if needed, and appends an ellipsis because it makes the trucation clearer in the UI
109 110 111 112 113 114 115 116 117 |
# File 'lib/ting_yun/agent/collector/transaction_sampler/class_method.rb', line 109 def () size = MAX_DATA_LENGTH - 4 if .length > size .slice!(size...length) << '...' else end end |