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
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/ting_yun/instrumentation/support/thrift_helper.rb', line 45

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

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


  my_data = state.thrift_return_data


  if my_data && TingYun::Agent.config[:'nbs.transaction_tracer.thrift'] && TingYun::Agent.config[:'nbs.transaction_tracer.enabled']
    uri = "thrift:%2F%2F#{tingyun_host}:#{tingyun_port}%2F#{operate}/#{operate}"
    metrics << "cross_app;#{my_data["id"]};#{my_data["action"]};#{uri}"
  end
  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