Skip to content

Instantly share code, notes, and snippets.

@NorbertFenk
Created January 30, 2020 16:30
Show Gist options
  • Save NorbertFenk/0d8bf946a651d7509ac2b1caa24b1877 to your computer and use it in GitHub Desktop.
Save NorbertFenk/0d8bf946a651d7509ac2b1caa24b1877 to your computer and use it in GitHub Desktop.
// To run the Zipkin UI use the following docker command
// docker run -p 9411:9411 openzipkin/zipkin
package main
import (
"fmt"
"io"
"log"
"github.com/opentracing/opentracing-go"
zipkinot "github.com/openzipkin-contrib/zipkin-go-opentracing"
"github.com/openzipkin/zipkin-go"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
)
const (
endpointURL = "http://localhost:9411/api/v2/spans"
hostURL = "0.0.0.0:0"
serviceName = "Bruuh"
)
func newTracer() (opentracing.Tracer, io.Closer, error) {
// set up a span reporter
reporter := zipkinhttp.NewReporter(endpointURL)
// create our local service endpoint
endpoint, err := zipkin.NewEndpoint(serviceName, hostURL)
if err != nil {
log.Fatalf("unable to create local endpoint: %+v\n", err)
return nil, nil, err
}
// initialize our tracer
nativeTracer, err := zipkin.NewTracer(reporter, zipkin.WithLocalEndpoint(endpoint))
if err != nil {
log.Fatalf("unable to create tracer: %+v\n", err)
return nil, nil, err
}
// use zipkin-go-opentracing to wrap our tracer
tracer := zipkinot.Wrap(nativeTracer)
// optionally set as Global OpenTracing tracer instance
opentracing.SetGlobalTracer(tracer)
return tracer, reporter, nil
}
func main() {
fmt.Println("started")
tracer, reporter, err := newTracer()
if err != nil {
panic(err)
}
defer reporter.Close()
span := tracer.StartSpan("say-hello")
defer span.Finish()
fmt.Println("finished")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment