From 52923f977ea84c5f1253b8903372e4965cf894c6 Mon Sep 17 00:00:00 2001 From: embs Date: Thu, 21 Sep 2017 09:24:11 -0300 Subject: [PATCH] Add local IP address to Zipkin tracing Related to https://github.com/microservices-demo/orders/issues/48 --- main.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index c38a94e1..dfee8f5e 100644 --- a/main.go +++ b/main.go @@ -3,9 +3,11 @@ package main import ( "flag" "fmt" + "net" "net/http" "os" "os/signal" + "strings" "syscall" corelog "log" @@ -59,6 +61,16 @@ func main() { logger = log.With(logger, "caller", log.DefaultCaller) } + // Find service local IP. + conn, err := net.Dial("udp", "8.8.8.8:80") + if err != nil { + logger.Log("err", err) + os.Exit(1) + } + localAddr := conn.LocalAddr().(*net.UDPAddr) + host := strings.Split(localAddr.String(), ":")[0] + defer conn.Close() + var tracer stdopentracing.Tracer { if zip == "" { @@ -75,7 +87,7 @@ func main() { os.Exit(1) } tracer, err = zipkin.NewTracer( - zipkin.NewRecorder(collector, false, fmt.Sprintf("localhost:%v", port), ServiceName), + zipkin.NewRecorder(collector, false, fmt.Sprintf("%v:%v", host, port), ServiceName), ) if err != nil { logger.Log("err", err)