Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Add local IP address to Zipkin tracing
Browse files Browse the repository at this point in the history
Also reuse client span to be consistent with how interactions between
Java services are traced.

Related to microservices-demo/orders#48
  • Loading branch information
embs committed Sep 21, 2017
1 parent b5ec77e commit 20be7a4
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package main
import (
"flag"
"fmt"
"net"
"net/http"
"os"
"os/signal"
"strings"
"syscall"

corelog "log"
Expand Down Expand Up @@ -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 == "" {
Expand All @@ -75,7 +87,8 @@ 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),
zipkin.ClientServerSameSpan(true),
)
if err != nil {
logger.Log("err", err)
Expand Down

0 comments on commit 20be7a4

Please sign in to comment.