Skip to content

Commit

Permalink
fix(chstorage): filter root span names, when rootName is queried
Browse files Browse the repository at this point in the history
  • Loading branch information
tdakkota committed Jun 14, 2024
1 parent 2415db2 commit 4ad0b3a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion internal/chstorage/querier_traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package chstorage

import (
"context"
"encoding/hex"
"time"

"github.com/ClickHouse/ch-go/proto"
Expand Down Expand Up @@ -224,7 +225,6 @@ func (q *Querier) TagValues(ctx context.Context, tag traceql.Attribute, opts tra
// Too high cardinality to query.
return iterators.Empty[tracestorage.Tag](), nil
case traceql.SpanName, traceql.RootSpanName:
// FIXME(tdakkota): we don't check if span name is actually coming from a root span.
return q.spanNames(ctx, tag, opts)
case traceql.RootServiceName:
// FIXME(tdakkota): we don't check if service.name actually coming from a root span.
Expand All @@ -237,6 +237,8 @@ func (q *Querier) TagValues(ctx context.Context, tag traceql.Attribute, opts tra
}
}

var zeroSpanIDHex = hex.EncodeToString(new(pcommon.SpanID)[:])

func (q *Querier) spanNames(ctx context.Context, tag traceql.Attribute, opts tracestorage.TagValuesOptions) (_ iterators.Iterator[tracestorage.Tag], rerr error) {
table := q.tables.Spans

Expand All @@ -261,7 +263,15 @@ func (q *Querier) spanNames(ctx context.Context, tag traceql.Attribute, opts tra
query = chsql.Select(table, chsql.Column("name", name)).
Distinct(true).
Where(traceInTimeRange(opts.Start, opts.End))
)
if tag.Prop == traceql.RootSpanName {
query.Where(chsql.Eq(
chsql.Ident("parent_span_id"),
chsql.Unhex(chsql.String(zeroSpanIDHex)),
))
}

var (
tagName = tag.String()
r []tracestorage.Tag
)
Expand Down

0 comments on commit 4ad0b3a

Please sign in to comment.