Skip to content

Commit

Permalink
Add query.Invoke span tags (#3737)
Browse files Browse the repository at this point in the history
This improves the detail of query information that can be seen in distributed tracing.
  • Loading branch information
simonswine authored Dec 3, 2024
1 parent fba0faa commit d02c948
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/experiment/query_backend/block_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func (b *BlockReader) Invoke(
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "request validation failed: %v", err)
}
r.setTraceTags(span)

g, ctx := errgroup.WithContext(ctx)
agg := newAggregator(req)
Expand Down Expand Up @@ -113,6 +114,23 @@ type request struct {
endTime int64 // Unix nano.
}

func (r *request) setTraceTags(span opentracing.Span) {
if r.src == nil {
return
}
span.SetTag("start_time", model.Time(r.src.StartTime).Time().String())
span.SetTag("end_time", model.Time(r.src.EndTime).Time().String())
span.SetTag("matchers", r.src.LabelSelector)

if len(r.src.Query) > 0 {
queryTypes := make([]string, 0, len(r.src.Query))
for _, q := range r.src.Query {
queryTypes = append(queryTypes, q.QueryType.String())
}
span.SetTag("query_types", queryTypes)
}
}

func validateRequest(req *queryv1.InvokeRequest) (*request, error) {
if len(req.Query) == 0 {
return nil, fmt.Errorf("no queries provided")
Expand Down

0 comments on commit d02c948

Please sign in to comment.