Codebase list golang-github-go-kit-kit / a544240
Clean up addsvc main Peter Bourgon 8 years ago
1 changed file(s) with 11 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
1616 "time"
1717
1818 "github.com/apache/thrift/lib/go/thrift"
19 "github.com/go-kit/kit/tracing/zipkin/_thrift/gen-go/zipkincore"
2019 stdprometheus "github.com/prometheus/client_golang/prometheus"
2120 "github.com/streadway/handy/cors"
2221 "github.com/streadway/handy/encoding"
9190 zipkinMethodName := "add"
9291 zipkinSpanFunc := zipkin.MakeNewSpanFunc(zipkinHostPort, *zipkinServiceName, zipkinMethodName)
9392
94 // Mechanical stuff
95 rand.Seed(time.Now().UnixNano())
96 root := context.Background()
97 errc := make(chan error)
98
9993 // Our business and operational domain
10094 var a Add = pureAdd
10195 if *proxyHTTPAddr != "" {
114108 var e server.Endpoint
115109 e = makeEndpoint(a)
116110 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)
117116
118117 go func() {
119118 errc <- interrupt()
230229 type loggingCollector struct{}
231230
232231 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 }
233237 kitlog.DefaultLogger.Log(
234238 "trace_id", strconv.FormatInt(s.TraceID(), 16),
235239 "span_id", strconv.FormatInt(s.SpanID(), 16),
236240 "parent_span_id", strconv.FormatInt(s.ParentSpanID(), 16),
237 "annotations", pretty(s.Encode().GetAnnotations()),
241 "annotations", strings.Join(values, " "),
238242 )
239243 return nil
240244 }
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 }