Module: TingYun::Instrumentation::ThriftHelper

Defined in:
lib/ting_yun/instrumentation/support/thrift_helper.rb

Instance Method Summary collapse

Instance Method Details

#metrics(operate) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ting_yun/instrumentation/support/thrift_helper.rb', line 45

def metrics operate
  metrics = if tingyun_host.nil?
              ["External/thrift:%2F%2F#{operate}/thrift"]
            else
              ["External/thrift:%2F%2F#{tingyun_host}:#{tingyun_port}%2F#{operate}/thrift"]
            end
  metrics << "External/NULL/ALL"

  if TingYun::Agent::Transaction.recording_web_transaction?
    metrics << "External/NULL/AllWeb"
  else
    metrics << "External/NULL/AllBackground"
  end
  return metrics
end

#metrics_for_cross_app(operate, my_data) ⇒ Object



61
62
63
64
65
66
# File 'lib/ting_yun/instrumentation/support/thrift_helper.rb', line 61

def metrics_for_cross_app(operate,my_data)
  metrics = ["ExternalTransaction/NULL/#{my_data["id"]}",
             "ExternalTransaction/thrift/#{my_data["id"]}",
             "ExternalTransaction/thrift:%2F%2F#{tingyun_host}:#{tingyun_port}%2F#{operate}/#{my_data["id"]}%2F#{my_data["action"].to_s.gsub(/\/\z/,'')}"]
  return metrics
end

#operationsObject



21
22
23
# File 'lib/ting_yun/instrumentation/support/thrift_helper.rb', line 21

def operations
  @operations ||= {}
end

#operator(result_klass) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ting_yun/instrumentation/support/thrift_helper.rb', line 9

def operator result_klass
  namespaces = result_klass.to_s.split('::')
  operator_name = namespaces[0].downcase
  if namespaces.last =~ /_result/
    operator_name = "#{operator_name}.#{namespaces.last.sub('_result', '').downcase}"
  elsif namespaces.last =~ /_args/
    operator_name = "#{operator_name}.#{namespaces.last.sub('_args', '').downcase}"
  end

  operator_name
end

#started_time_and_node(operate) ⇒ Object



25
26
27
28
29
30
# File 'lib/ting_yun/instrumentation/support/thrift_helper.rb', line 25

def started_time_and_node(operate)
  _op_ = operations.delete(operate)
  time = (_op_ && _op_[:started_time]) || Time.now.to_f
  node = _op_ && _op_[:node]
  [time, node]
end

#tingyun_hostObject



37
38
39
# File 'lib/ting_yun/instrumentation/support/thrift_helper.rb', line 37

def tingyun_host
  @tingyun_host ||= tingyun_socket.instance_variable_get("@host") rescue nil
end

#tingyun_portObject



41
42
43
# File 'lib/ting_yun/instrumentation/support/thrift_helper.rb', line 41

def tingyun_port
  @tingyun_port  ||= tingyun_socket.instance_variable_get("@port") rescue nil
end

#tingyun_socketObject



33
34
35
# File 'lib/ting_yun/instrumentation/support/thrift_helper.rb', line 33

def tingyun_socket
  @iprot.instance_variable_get("@trans").instance_variable_get("@transport")
end