Codebase list golang-github-go-kit-kit / 5c6432c
Zipkin span fix: use the first available IPv4 address from net.LookupIP Bas van Beek 8 years ago
1 changed file(s) with 15 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
4747 if err != nil {
4848 return nil
4949 }
50 portInt, err := strconv.ParseInt(port, 10, 16)
51 if err != nil {
52 return nil
53 }
5054 addrs, err := net.LookupIP(host)
5155 if err != nil {
5256 return nil
5357 }
54 if len(addrs) <= 0 {
55 return nil
56 }
57 portInt, err := strconv.ParseInt(port, 10, 16)
58 if err != nil {
58 // we need the first IPv4 address.
59 var addr net.IP
60 for i := range addrs {
61 addr = addrs[i].To4()
62 if addr != nil {
63 break
64 }
65 }
66 if addr == nil {
67 // none of the returned addresses is IPv4.
5968 return nil
6069 }
6170 endpoint := zipkincore.NewEndpoint()
62 endpoint.Ipv4 = (int32)(binary.BigEndian.Uint32(addrs[0].To4()))
71 endpoint.Ipv4 = (int32)(binary.BigEndian.Uint32(addr))
6372 endpoint.Port = int16(portInt)
6473 endpoint.ServiceName = serviceName
6574 return endpoint