Clean up addsvc main
Peter Bourgon
8 years ago
16 | 16 | "time" |
17 | 17 | |
18 | 18 | "github.com/apache/thrift/lib/go/thrift" |
19 | "github.com/go-kit/kit/tracing/zipkin/_thrift/gen-go/zipkincore" | |
20 | 19 | stdprometheus "github.com/prometheus/client_golang/prometheus" |
21 | 20 | "github.com/streadway/handy/cors" |
22 | 21 | "github.com/streadway/handy/encoding" |
91 | 90 | zipkinMethodName := "add" |
92 | 91 | zipkinSpanFunc := zipkin.MakeNewSpanFunc(zipkinHostPort, *zipkinServiceName, zipkinMethodName) |
93 | 92 | |
94 | // Mechanical stuff | |
95 | rand.Seed(time.Now().UnixNano()) | |
96 | root := context.Background() | |
97 | errc := make(chan error) | |
98 | ||
99 | 93 | // Our business and operational domain |
100 | 94 | var a Add = pureAdd |
101 | 95 | if *proxyHTTPAddr != "" { |
114 | 108 | var e server.Endpoint |
115 | 109 | e = makeEndpoint(a) |
116 | 110 | e = zipkin.AnnotateServer(zipkinSpanFunc, zipkinCollector)(e) |
111 | ||
112 | // Mechanical stuff | |
113 | rand.Seed(time.Now().UnixNano()) | |
114 | root := context.Background() | |
115 | errc := make(chan error) | |
117 | 116 | |
118 | 117 | go func() { |
119 | 118 | errc <- interrupt() |
230 | 229 | type loggingCollector struct{} |
231 | 230 | |
232 | 231 | func (loggingCollector) Collect(s *zipkin.Span) error { |
232 | annotations := s.Encode().GetAnnotations() | |
233 | values := make([]string, len(annotations)) | |
234 | for i, a := range annotations { | |
235 | values[i] = a.Value | |
236 | } | |
233 | 237 | kitlog.DefaultLogger.Log( |
234 | 238 | "trace_id", strconv.FormatInt(s.TraceID(), 16), |
235 | 239 | "span_id", strconv.FormatInt(s.SpanID(), 16), |
236 | 240 | "parent_span_id", strconv.FormatInt(s.ParentSpanID(), 16), |
237 | "annotations", pretty(s.Encode().GetAnnotations()), | |
241 | "annotations", strings.Join(values, " "), | |
238 | 242 | ) |
239 | 243 | return nil |
240 | 244 | } |
241 | ||
242 | func pretty(annotations []*zipkincore.Annotation) string { | |
243 | values := make([]string, len(annotations)) | |
244 | for i, annotation := range annotations { | |
245 | values[i] = annotation.Value | |
246 | } | |
247 | return strings.Join(values, " ") | |
248 | } |