fork of https://github.com/sourcegraph/zoekt
0

Configure Feed

Select the types of activity you want to include in your feed.

trace: flatten opentracing spans (#187)

It is quite frustrating to read traces involving zoekt since they are
always 4 levels deep with all spans but the leaf containing not much
useful information. This just ends up taking up a lot of vertical
space. Instead we can just collapse spans in Zoekt.

+19 -7
+19 -7
trace/trace.go
··· 31 31 32 32 // New returns a new Trace with the specified family and title. 33 33 func (t Tracer) New(ctx context.Context, family, title string) (*Trace, context.Context) { 34 - span, ctx := StartSpanFromContextWithTracer( 35 - ctx, 36 - t.Tracer, 37 - family, 38 - opentracing.Tag{Key: "title", Value: title}, 39 - ) 34 + // In Zoekt child OpenTracing Spans don't really make much sense since all 35 + // our spans are either middleware which just wrap an actual search, or the 36 + // actual search. So we only create a new span if there is no parent. 37 + parent := TraceFromContext(ctx) 38 + var span opentracing.Span 39 + if parent != nil { 40 + span = parent.span 41 + span.LogFields(log.String("child.family", family), log.String("child.title", title)) 42 + } else { 43 + span, ctx = StartSpanFromContextWithTracer( 44 + ctx, 45 + t.Tracer, 46 + family, 47 + opentracing.Tag{Key: "title", Value: title}, 48 + ) 49 + } 50 + 40 51 tr := nettrace.New(family, title) 41 52 trace := &Trace{span: span, trace: tr, family: family} 42 - if parent := TraceFromContext(ctx); parent != nil { 53 + if parent != nil { 43 54 tr.LazyPrintf("parent: %s", parent.family) 44 55 trace.family = parent.family + " > " + family 45 56 } 57 + 46 58 return trace, ContextWithTrace(ctx, trace) 47 59 } 48 60