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

Configure Feed

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

1package web 2 3import ( 4 "context" 5 6 "github.com/opentracing/opentracing-go" 7 "github.com/sourcegraph/zoekt" 8 "github.com/sourcegraph/zoekt/internal/trace" 9 "github.com/sourcegraph/zoekt/query" 10) 11 12func NewTraceAwareSearcher(s zoekt.Streamer) zoekt.Streamer { 13 return traceAwareSearcher{Searcher: s} 14} 15 16// traceAwareSearcher wraps a zoekt.Searcher instance so that the tracing context item is set in the 17// context. This context item toggles on trace collection via the 18// github.com/sourcegraph/zoekt/internal/trace/ot package. 19type traceAwareSearcher struct { 20 Searcher zoekt.Streamer 21} 22 23func (s traceAwareSearcher) Search( 24 ctx context.Context, 25 q query.Q, 26 opts *zoekt.SearchOptions, 27) (*zoekt.SearchResult, error) { 28 ctx = trace.WithOpenTracingEnabled(ctx, opts.Trace) 29 spanContext := trace.SpanContextFromContext(ctx) 30 if opts.Trace && spanContext != nil { 31 var span opentracing.Span 32 span, ctx = opentracing.StartSpanFromContext(ctx, "zoekt.traceAwareSearcher.Search", opentracing.ChildOf(spanContext)) 33 defer span.Finish() 34 } 35 return s.Searcher.Search(ctx, q, opts) 36} 37 38func (s traceAwareSearcher) StreamSearch( 39 ctx context.Context, 40 q query.Q, 41 opts *zoekt.SearchOptions, 42 sender zoekt.Sender, 43) error { 44 ctx = trace.WithOpenTracingEnabled(ctx, opts.Trace) 45 spanContext := trace.SpanContextFromContext(ctx) 46 if opts.Trace && spanContext != nil { 47 var span opentracing.Span 48 span, ctx = opentracing.StartSpanFromContext(ctx, "zoekt.traceAwareSearcher.StreamSearch", opentracing.ChildOf(spanContext)) 49 defer span.Finish() 50 } 51 return s.Searcher.StreamSearch(ctx, q, opts, sender) 52} 53 54func (s traceAwareSearcher) List(ctx context.Context, q query.Q, opts *zoekt.ListOptions) (*zoekt.RepoList, error) { 55 return s.Searcher.List(ctx, q, opts) 56} 57func (s traceAwareSearcher) Close() { s.Searcher.Close() } 58func (s traceAwareSearcher) String() string { return s.Searcher.String() }