Package list golang-github-go-kit-kit / 2ea9d3e
examples/addsvc2: Appdash and LightStep tracing Peter Bourgon 4 years ago
1 changed file(s) with 26 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
1111 "text/tabwriter"
1212
1313 "github.com/apache/thrift/lib/go/thrift"
14 lightstep "github.com/lightstep/lightstep-tracer-go"
1415 "github.com/oklog/oklog/pkg/group"
1516 stdopentracing "github.com/opentracing/opentracing-go"
1617 zipkin "github.com/openzipkin/zipkin-go-opentracing"
1718 stdprometheus "github.com/prometheus/client_golang/prometheus"
1819 "google.golang.org/grpc"
20 "sourcegraph.com/sourcegraph/appdash"
21 appdashot "sourcegraph.com/sourcegraph/appdash/opentracing"
1922
2023 "github.com/go-kit/kit/log"
2124 "github.com/go-kit/kit/metrics"
3740 debugAddr = fs.String("debug.addr", ":8080", "Debug and metrics listen address")
3841 httpAddr = fs.String("http-addr", ":8081", "HTTP listen address")
3942 grpcAddr = fs.String("grpc-addr", ":8082", "gRPC listen address")
40 thriftAddr = fs.String("thrift-addr", ":8082", "Thrift listen address")
43 thriftAddr = fs.String("thrift-addr", ":8083", "Thrift listen address")
4144 thriftProtocol = fs.String("thrift-protocol", "binary", "binary, compact, json, simplejson")
4245 thriftBuffer = fs.Int("thrift-buffer", 0, "0 for unbuffered")
4346 thriftFramed = fs.Bool("thrift-framed", false, "true to enable framing")
44 zipkinURL = fs.String("zipkin-url", "", "Zipkin collector URL e.g. http://localhost:9411/api/v1/spans")
47 zipkinURL = fs.String("zipkin-url", "", "Enable Zipkin tracing via a collector URL e.g. http://localhost:9411/api/v1/spans")
48 lightstepToken = flag.String("lightstep-token", "", "Enable LightStep tracing via a LightStep access token")
49 appdashAddr = flag.String("appdash-addr", "", "Enable Appdash tracing via an Appdash server host:port")
4550 )
4651 fs.Usage = usageFor(fs, os.Args[0]+" [flags]")
4752 fs.Parse(os.Args[1:])
5964 var tracer stdopentracing.Tracer
6065 {
6166 if *zipkinURL != "" {
62 logger.Log("zipkin", *zipkinURL)
67 logger.Log("tracer", "Zipkin", "URL", *zipkinURL)
6368 collector, err := zipkin.NewHTTPCollector(*zipkinURL)
6469 if err != nil {
6570 logger.Log("err", err)
7176 hostPort = "localhost:80"
7277 serviceName = "addsvc"
7378 )
74 tracer, err = zipkin.NewTracer(zipkin.NewRecorder(
75 collector, debug, hostPort, serviceName,
76 ))
79 recorder := zipkin.NewRecorder(collector, debug, hostPort, serviceName)
80 tracer, err = zipkin.NewTracer(recorder)
7781 if err != nil {
7882 logger.Log("err", err)
7983 os.Exit(1)
8084 }
85 } else if *lightstepToken != "" {
86 logger.Log("tracer", "LightStep") // probably don't want to print out the token :)
87 tracer = lightstep.NewTracer(lightstep.Options{
88 AccessToken: *lightstepToken,
89 })
90 defer lightstep.FlushLightStepTracer(tracer)
91 } else if *appdashAddr != "" {
92 logger.Log("tracer", "Appdash", "addr", *appdashAddr)
93 tracer = appdashot.NewTracer(appdash.NewRemoteCollector(*appdashAddr))
8194 } else {
95 logger.Log("tracer", "none")
8296 tracer = stdopentracing.GlobalTracer() // no-op
8397 }
8498 }
132146 // The method is the same for each component: add a new actor to the group
133147 // struct, which is a combination of 2 anonymous functions: the first
134148 // function actually runs the component, and the second function should
135 // interrupt the first function and cause it to return.
136
149 // interrupt the first function and cause it to return. It's in these
150 // functions that we actually bin the Go kit server/handler structs to the
151 // concrete transports and start them running.
152 //
153 // Putting each component into its own block is mostly for aesthetics: it
154 // clearly demarcates the scope in which each listener/socket may be used.
137155 var g group.Group
138156 {
139157 // The debug listener mounts the http.DefaultServeMux, and serves up