From a440cf6106596226bd776d476f643925739349b1 Mon Sep 17 00:00:00 2001 From: embs Date: Fri, 22 Sep 2017 13:33:06 -0300 Subject: [PATCH] Add local IP address to Zipkin tracing Related to https://github.com/microservices-demo/orders/issues/48 --- cmd/paymentsvc/main.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/cmd/paymentsvc/main.go b/cmd/paymentsvc/main.go index c9556b9..fa8270f 100644 --- a/cmd/paymentsvc/main.go +++ b/cmd/paymentsvc/main.go @@ -3,9 +3,11 @@ package main import ( "flag" "fmt" + "net" "net/http" "os" "os/signal" + "strings" "syscall" "github.com/go-kit/kit/log" @@ -35,6 +37,15 @@ func main() { logger = log.NewContext(logger).With("ts", log.DefaultTimestampUTC) logger = log.NewContext(logger).With("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() if *zip == "" { tracer = stdopentracing.NoopTracer{} } else { @@ -49,7 +60,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)