examples/addsvc2: Appdash and LightStep tracing
Peter Bourgon
6 years ago
11 | 11 | "text/tabwriter" |
12 | 12 | |
13 | 13 | "github.com/apache/thrift/lib/go/thrift" |
14 | lightstep "github.com/lightstep/lightstep-tracer-go" | |
14 | 15 | "github.com/oklog/oklog/pkg/group" |
15 | 16 | stdopentracing "github.com/opentracing/opentracing-go" |
16 | 17 | zipkin "github.com/openzipkin/zipkin-go-opentracing" |
17 | 18 | stdprometheus "github.com/prometheus/client_golang/prometheus" |
18 | 19 | "google.golang.org/grpc" |
20 | "sourcegraph.com/sourcegraph/appdash" | |
21 | appdashot "sourcegraph.com/sourcegraph/appdash/opentracing" | |
19 | 22 | |
20 | 23 | "github.com/go-kit/kit/log" |
21 | 24 | "github.com/go-kit/kit/metrics" |
37 | 40 | debugAddr = fs.String("debug.addr", ":8080", "Debug and metrics listen address") |
38 | 41 | httpAddr = fs.String("http-addr", ":8081", "HTTP listen address") |
39 | 42 | 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") | |
41 | 44 | thriftProtocol = fs.String("thrift-protocol", "binary", "binary, compact, json, simplejson") |
42 | 45 | thriftBuffer = fs.Int("thrift-buffer", 0, "0 for unbuffered") |
43 | 46 | 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") | |
45 | 50 | ) |
46 | 51 | fs.Usage = usageFor(fs, os.Args[0]+" [flags]") |
47 | 52 | fs.Parse(os.Args[1:]) |
59 | 64 | var tracer stdopentracing.Tracer |
60 | 65 | { |
61 | 66 | if *zipkinURL != "" { |
62 | logger.Log("zipkin", *zipkinURL) | |
67 | logger.Log("tracer", "Zipkin", "URL", *zipkinURL) | |
63 | 68 | collector, err := zipkin.NewHTTPCollector(*zipkinURL) |
64 | 69 | if err != nil { |
65 | 70 | logger.Log("err", err) |
71 | 76 | hostPort = "localhost:80" |
72 | 77 | serviceName = "addsvc" |
73 | 78 | ) |
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) | |
77 | 81 | if err != nil { |
78 | 82 | logger.Log("err", err) |
79 | 83 | os.Exit(1) |
80 | 84 | } |
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)) | |
81 | 94 | } else { |
95 | logger.Log("tracer", "none") | |
82 | 96 | tracer = stdopentracing.GlobalTracer() // no-op |
83 | 97 | } |
84 | 98 | } |
132 | 146 | // The method is the same for each component: add a new actor to the group |
133 | 147 | // struct, which is a combination of 2 anonymous functions: the first |
134 | 148 | // 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. | |
137 | 155 | var g group.Group |
138 | 156 | { |
139 | 157 | // The debug listener mounts the http.DefaultServeMux, and serves up |