Created
February 5, 2018 00:56
-
-
Save stevenc81/c3b5dd383c33c7d9c908cb24e0b97989 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment