module OneApm module Support module HTTPClients module ThriftTracer def self.included clazz clazz.class_eval do def is_cross_app=(is_cross_app) @is_cross_app = is_cross_app end def is_cross_app? @is_cross_app end def write_field_stop_with_oneapm is_write_fielded = false begin state = OneApm::TransactionState.tl_get message = OneApm::Agent::CrossAppTracingMessage.request_data(state) if message write_field_begin('oneapm_message', ::Thrift::Types::STRING, -32768) is_write_fielded = true write_string("####{message}###") end rescue => e OneApm::Manager.logger.error "Thrift write_field_stop error: #{e}" ensure write_field_end if is_write_fielded end write_field_stop_without_oneapm end alias :write_field_stop_without_oneapm :write_field_stop alias :write_field_stop :write_field_stop_with_oneapm def read_field_begin_with_oneapm name, type, id = read_field_begin_without_oneapm begin is_cross_app = true if type == ::Thrift::Types::STRING && id == -32768 rescue => e OneApm::Manager.logger.error "Thrift read_field_begin error: #{e}" end [name, type, id] end alias :read_field_begin_without_oneapm :read_field_begin alias :read_field_begin :read_field_begin_with_oneapm def read_string_with_oneapm string = read_string_without_oneapm if string && is_cross_app? if /###(?.*)###/ =~ string OneApm::Agent::CrossAppTracingMessage.process_request(message) end end string end alias :read_string_without_oneapm :read_string alias :read_string :read_string_with_oneapm end end end end end end