module OneApm::Support::HTTPClients::ThriftTracer

Public Class Methods

included(clazz) click to toggle source
# File lib/one_apm/support/http_clients/thrift_tracer.rb, line 5
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 /###(?<message>.*)###/ =~ 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

Public Instance Methods

is_cross_app=(is_cross_app) click to toggle source
# File lib/one_apm/support/http_clients/thrift_tracer.rb, line 8
def is_cross_app=(is_cross_app)
  @is_cross_app = is_cross_app
end
is_cross_app?() click to toggle source
# File lib/one_apm/support/http_clients/thrift_tracer.rb, line 12
def is_cross_app?
  @is_cross_app
end
read_field_begin_with_oneapm() click to toggle source
# File lib/one_apm/support/http_clients/thrift_tracer.rb, line 36
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
read_string_with_oneapm() click to toggle source
# File lib/one_apm/support/http_clients/thrift_tracer.rb, line 48
def read_string_with_oneapm
  string = read_string_without_oneapm
  if string && is_cross_app?
    if /###(?<message>.*)###/ =~ string
      OneApm::Agent::CrossAppTracingMessage.process_request(message)
    end
  end
  string
end
write_field_stop_with_oneapm() click to toggle source
# File lib/one_apm/support/http_clients/thrift_tracer.rb, line 16
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