-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
53 lines (45 loc) · 1.52 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
package main
import (
"fmt"
"log"
"net/http"
"runtime"
"time"
"github.com/opentracing-contrib/go-stdlib/nethttp"
opentracing "github.com/opentracing/opentracing-go"
jaeger "github.com/uber/jaeger-client-go"
"github.com/uber/jaeger-client-go/zipkin"
)
func indexHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "hello world, I'm running on %s with an %s CPU ", runtime.GOOS, runtime.GOARCH)
}
func getTimeHandler(w http.ResponseWriter, r *http.Request) {
log.Print("Received getTime request")
t := time.Now()
ts := t.Format("Mon Jan _2 15:04:05 2006")
fmt.Fprintf(w, "The time is %s", ts)
}
func main() {
zipkinPropagator := zipkin.NewZipkinB3HTTPHeaderPropagator()
injector := jaeger.TracerOptions.Injector(opentracing.HTTPHeaders, zipkinPropagator)
extractor := jaeger.TracerOptions.Extractor(opentracing.HTTPHeaders, zipkinPropagator)
// Zipkin shares span ID between client and server spans; it must be enabled via the following option.
zipkinSharedRPCSpan := jaeger.TracerOptions.ZipkinSharedRPCSpan(true)
sender, _ := jaeger.NewUDPTransport("jaeger-agent.istio-system:5775", 0)
tracer, closer := jaeger.NewTracer(
"myhelloworld",
jaeger.NewConstSampler(true),
jaeger.NewRemoteReporter(
sender,
jaeger.ReporterOptions.BufferFlushInterval(1*time.Second)),
injector,
extractor,
zipkinSharedRPCSpan,
)
defer closer.Close()
http.HandleFunc("/", indexHandler)
http.HandleFunc("/gettime", getTimeHandler)
http.ListenAndServe(
":8080",
nethttp.Middleware(tracer, http.DefaultServeMux))
}