lib/ting_yun/instrumentation/thrift.rb in tingyun_rpm-1.0.7 vs lib/ting_yun/instrumentation/thrift.rb in tingyun_rpm-1.1.0

- old
+ new

@@ -1,8 +1,9 @@ # encoding: utf-8 require 'ting_yun/support/helper' require 'ting_yun/agent' +require 'ting_yun/instrumentation/support/external_error' module TingYun module Instrumentation module ThriftHelper def operator result_klass @@ -236,28 +237,30 @@ ::Thrift::Client.module_eval do include TingYun::Instrumentation::ThriftHelper - def send_message_args_with_tingyun(args_class, args = {}) - state = TingYun::Agent::TransactionState.tl_get - return unless state.execution_traced? - cross_app_id = TingYun::Agent.config[:tingyunIdSecret] or - raise TingYun::Agent::CrossAppTracing::Error, "no tingyunIdSecret configured" - txn_guid = state.request_guid - tingyun_id = "#{cross_app_id};c=1;x=#{txn_guid}" - data = TingYun::Support::Serialize::JSONWrapper.dump("TingyunID" => tingyun_id) - @oprot.write_field_begin("TingyunField", 11, 6) - @oprot.write_string(data) - @oprot.write_field_end - send_message_args_without_tingyun(args_class, args) - end + def send_message_args_with_tingyun(args_class, args = {}) + state = TingYun::Agent::TransactionState.tl_get + return unless state.execution_traced? + cross_app_id = TingYun::Agent.config[:tingyunIdSecret] or + raise TingYun::Agent::CrossAppTracing::Error, "no tingyunIdSecret configured" + txn_guid = state.request_guid + tingyun_id = "#{cross_app_id};c=1;x=#{txn_guid}" - alias :send_message_args_without_tingyun :send_message_args - alias :send_message_args :send_message_args_with_tingyun + data = TingYun::Support::Serialize::JSONWrapper.dump("TingyunID" => tingyun_id) + @oprot.write_field_begin("TingyunField", 11, 6) + @oprot.write_string(data) + @oprot.write_field_end + send_message_args_without_tingyun(args_class, args) + end + alias :send_message_args_without_tingyun :send_message_args + alias :send_message_args :send_message_args_with_tingyun + + def send_message_with_tingyun(name, args_class, args = {}) tag = "#{args_class.to_s.split('::').first.downcase}.#{name}" t0 = Time.now.to_f operations[tag] = {:started_time => t0} @@ -294,14 +297,10 @@ result = receive_message_without_tingyun(result_klass) if result.nil? || result.success.nil? e = ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, "#{operate} failed: unknown result") - e.instance_variable_set(:@tingyun_klass, metrics(operate)[0]) - e.instance_variable_set(:@tingyun_external, true) - e.instance_variable_set(:@tingyun_code, 1000) - e.instance_variable_set(:@tingyun_trace, caller.reject! { |t| t.include?('tingyun_rpm') }) - TingYun::Agent.notice_error(e) + ::TingYun::Instrumentation::Support::ExternalError.handle_error(e,metrics(operate)[0]) end t1 = Time.now.to_f node_name, *other_metrics = metrics(operate) duration = TingYun::Helper.time_to_millis(t1 - t0) \ No newline at end of file