29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
71
72
73
|
# File 'lib/zipkin-query.rb', line 29
def self.with_transport(opts = {})
begin
if opts[:use_local_server]
host = "localhost"
port = 9149
socket = Thrift::Socket.new(host, port)
transport = Thrift::BufferedTransport.new(socket)
else
zk_host = opts[:zk_host] || "localhost"
zk_port = opts[:zk_port] || 2181
host, port = Client::get_query_service(zk_host, zk_port, opts)
socket = Thrift::Socket.new(host, port)
buffered_tp = Thrift::BufferedTransport.new(socket)
transport = Thrift::FramedTransport.new(buffered_tp)
end
protocol = Thrift::BinaryProtocol.new(transport)
client = ThriftClient.new(Zipkin::ZipkinQuery::Client, host + ':' + port.to_s, :retries => 0, :timeout => 60)
client_id = FinagleThrift::ClientId.new(:name => "zipkin.prod")
FinagleThrift.enable_tracing!(client, client_id, "zipkin")
begin
transport.open
yield(client)
ensure
transport.close
end
rescue ZookeeperExceptions::ZookeeperException::ConnectionClosed => ze
"Could not connect to zookeeper at #{opts[:zk_host]}:#{opts[:zk_port]}"
end
end
|