Module: TingYun::Agent::Transaction::ClassMethod
- Included in:
- TingYun::Agent::Transaction
- Defined in:
- lib/ting_yun/agent/transaction/class_method.rb
Overview
web transaction
Instance Method Summary collapse
- #metrics ⇒ Object
- #nested_transaction_name(name) ⇒ Object
-
#notice_error(e, options = {}) ⇒ Object
See TingYun::Agent.notice_error for options and commentary.
-
#recording_web_transaction? ⇒ Boolean
THREAD_LOCAL_ACCESS.
-
#set_default_transaction_name(name, category = nil, node_name = nil) ⇒ Object
THREAD_LOCAL_ACCESS.
-
#set_frozen_transaction_name!(name) ⇒ Object
THREAD_LOCAL_ACCESS.
- #start(state, category, options) ⇒ Object
- #start_new_transaction(state, category, options) ⇒ Object
- #stop(state, end_time = Time.now.to_f, summary_metric_names = []) ⇒ Object
- #tl_current ⇒ Object
- #wrap(state, name, category, options = {}, summary_metrics = []) ⇒ Object
Instance Method Details
#metrics ⇒ Object
13 14 15 16 |
# File 'lib/ting_yun/agent/transaction/class_method.rb', line 13 def metrics txn = tl_current txn && txn.metrics end |
#nested_transaction_name(name) ⇒ Object
117 118 119 120 121 122 123 |
# File 'lib/ting_yun/agent/transaction/class_method.rb', line 117 def nested_transaction_name(name) if name.start_with?(CONTROLLER_PREFIX) || name.start_with?(BACKGROUND_PREFIX) "#{SUBTRANSACTION_PREFIX}#{name}" else name end end |
#notice_error(e, options = {}) ⇒ Object
See TingYun::Agent.notice_error for options and commentary
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ting_yun/agent/transaction/class_method.rb', line 25 def notice_error(e, ={}) state = TingYun::Agent::TransactionState.tl_get txn = state.current_transaction if txn txn.exceptions.notice_error(e, ) state.transaction_sample_builder.trace.add_errors_to_current_node(state,e) rescue nil elsif TingYun::Agent.instance TingYun::Agent.instance.error_collector.notice_error(e, ) end end |
#recording_web_transaction? ⇒ Boolean
THREAD_LOCAL_ACCESS
19 20 21 22 |
# File 'lib/ting_yun/agent/transaction/class_method.rb', line 19 def recording_web_transaction? #THREAD_LOCAL_ACCESS txn = tl_current txn && txn.web_category?(txn.category) end |
#set_default_transaction_name(name, category = nil, node_name = nil) ⇒ Object
THREAD_LOCAL_ACCESS
125 126 127 128 129 130 |
# File 'lib/ting_yun/agent/transaction/class_method.rb', line 125 def set_default_transaction_name(name, category = nil, node_name = nil) #THREAD_LOCAL_ACCESS txn = tl_current name = txn.make_transaction_name(name, category) txn.name_last_frame(node_name || name) txn.set_default_transaction_name(name, category) end |
#set_frozen_transaction_name!(name) ⇒ Object
THREAD_LOCAL_ACCESS
132 133 134 135 |
# File 'lib/ting_yun/agent/transaction/class_method.rb', line 132 def set_frozen_transaction_name!(name) #THREAD_LOCAL_ACCESS txn = tl_current txn.frozen_name = name end |
#start(state, category, options) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/ting_yun/agent/transaction/class_method.rb', line 97 def start(state, category, ) category ||= :controller txn = state.current_transaction if txn txn.create_nested_frame(state, category, ) else txn = start_new_transaction(state, category, ) end txn rescue => e TingYun::Agent.logger.error("Exception during Transaction.start", e) end |
#start_new_transaction(state, category, options) ⇒ Object
110 111 112 113 114 115 |
# File 'lib/ting_yun/agent/transaction/class_method.rb', line 110 def start_new_transaction(state, category, ) txn = Transaction.new(category, state.client_transaction_id, ) state.reset(txn) txn.start(state) txn end |
#stop(state, end_time = Time.now.to_f, summary_metric_names = []) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ting_yun/agent/transaction/class_method.rb', line 37 def stop(state, end_time = Time.now.to_f, summary_metric_names=[]) txn = state.current_transaction unless txn TingYun::Agent.logger.error("Failed during Transaction.stop because there is no current transaction") return end nested_frame = txn.frame_stack.pop if txn.frame_stack.empty? txn.stop(state, end_time, nested_frame, summary_metric_names) state.reset TingYun::Agent.upload else nested_name = Transaction.nested_transaction_name nested_frame.name # if nested_name.start_with?(MIDDLEWARE_PREFIX) # summary_metrics = MIDDLEWARE_SUMMARY_METRICS # else # summary_metrics = EMPTY_SUMMARY_METRICS # end # summary_metrics = summary_metric_names unless summary_metric_names.empty? TingYun::Agent::MethodTracerHelpers.( state, nested_frame.start_time, nested_name, EMPTY_SUMMARY_METRICS, nested_frame, NESTED_TRACE_STOP_OPTIONS, end_time) end :transaction_stopped rescue => e state.reset TingYun::Agent.logger.error("Exception during Transaction.stop", e) nil end |
#tl_current ⇒ Object
9 10 11 |
# File 'lib/ting_yun/agent/transaction/class_method.rb', line 9 def tl_current TingYun::Agent::TransactionState.tl_get.current_transaction end |
#wrap(state, name, category, options = {}, summary_metrics = []) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/ting_yun/agent/transaction/class_method.rb', line 80 def wrap(state, name, category, = {}, summary_metrics=[]) Transaction.start(state, category, .merge(:transaction_name => name)) begin # We shouldn't raise from Transaction.start, but only wrap the yield # to be absolutely sure we don't report agent problems as app errors yield rescue => e ::TingYun::Agent.notice_error(e,:type=> :exception) raise e ensure # when kafka consumer in task, drop original web_action Transaction.stop(state, Time.now.to_f, summary_metrics) if state.current_transaction end end |