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(key, duration) ⇒ Object
duration=> sec.
-
#notice_nosql_statement(statement, duration) ⇒ Object
duration=> sec.
-
#notice_pop_frame(state, frame, time = Time.now, klass_name = nil) ⇒ Object
Informs the transaction sample builder about the end of a traced frame.
- #notice_push_frame(state, time = Time.now) ⇒ 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 |
# 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[:sql] = end else node[key] = () end append_backtrace(node, duration) end end |
#add_node_info(params) ⇒ Object
115 116 117 118 119 |
# File 'lib/ting_yun/agent/collector/transaction_sampler/class_method.rb', line 115 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
107 108 109 110 111 112 113 |
# File 'lib/ting_yun/agent/collector/transaction_sampler/class_method.rb', line 107 def append_backtrace(node, duration) if duration*1000 >= Agent.config[:'nbs.action_tracer.stack_trace_threshold'] trace = caller.reject! { |t| t.include?('tingyun_rpm') } trace = trace.first(20) node[:stacktrace] = trace end end |
#notice_nosql(key, duration) ⇒ Object
duration=> sec
51 52 53 54 |
# File 'lib/ting_yun/agent/collector/transaction_sampler/class_method.rb', line 51 def notice_nosql(key, duration) #THREAD_LOCAL_ACCESS builder = tl_builder action_tracer_segment(builder, key, duration, :key) end |
#notice_nosql_statement(statement, duration) ⇒ 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) #THREAD_LOCAL_ACCESS builder = tl_builder action_tracer_segment(builder, statement, duration, :statement) end |
#notice_pop_frame(state, frame, time = Time.now, klass_name = 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, klass_name=nil) builder = state.transaction_sample_builder return unless builder builder.trace_exit(frame, time.to_f, klass_name) end |
#notice_push_frame(state, time = Time.now) ⇒ 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) builder = state.transaction_sample_builder return unless builder builder.trace_entry(time.to_f) 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[:'nbs.action_tracer.enabled'] state.transaction_sample_builder ||= TingYun::Agent::TransactionSampleBuilder.new(time) else state.transaction_sample_builder = nil end end |
#tl_builder ⇒ Object
121 122 123 |
# File 'lib/ting_yun/agent/collector/transaction_sampler/class_method.rb', line 121 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
94 95 96 97 98 99 100 101 102 |
# File 'lib/ting_yun/agent/collector/transaction_sampler/class_method.rb', line 94 def () size = MAX_DATA_LENGTH - 4 if .length > size .slice!(size...length) << '...' else end end |