-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
58 lines (51 loc) · 1.33 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
package main
import (
"flag"
"fmt"
"github.com/opentracing-contrib/go-stdlib/nethttp"
zipkin "github.com/openzipkin/zipkin-go-opentracing"
"net/http"
"os"
"time"
)
const (
serviceName = "date-server"
hostPort = "0.0.0.0:0"
debug = false
sameSpan = false
traceID128Bit = true
)
func timeHandler(w http.ResponseWriter, r *http.Request) {
tm := time.Now().Format(time.RFC1123)
w.Write([]byte("The time is " + tm))
}
func main() {
collectorHost := os.Getenv("ZIPKIN_COLLECTOR_HOST")
if collectorHost == "" {
collectorHost = "localhost"
}
collectorPort := os.Getenv("ZIPKIN_COLLECTOR_PORT")
if collectorPort == "" {
collectorPort = "9411"
}
flag.Parse()
zipkinHTTPEndpoint := "http://" + collectorHost + ":" + collectorPort + "/api/v1/spans"
collector, err := zipkin.NewHTTPCollector(zipkinHTTPEndpoint)
if err != nil {
fmt.Printf("unable to create Zipkin HTTP collector: %+v\n", err)
os.Exit(-1)
}
recorder := zipkin.NewRecorder(collector, debug, hostPort, serviceName)
tracer, err := zipkin.NewTracer(
recorder,
zipkin.ClientServerSameSpan(sameSpan),
zipkin.TraceID128Bit(traceID128Bit))
if err != nil {
fmt.Printf("unable to create Zipkin tracer: %+v\n", err)
os.Exit(-1)
}
handler := nethttp.Middleware(
tracer,
http.HandlerFunc(timeHandler))
http.ListenAndServe(":8080", handler)
}