diff --git a/pkg/traceql/engine.go b/pkg/traceql/engine.go index 18107711482..4120bf3c607 100644 --- a/pkg/traceql/engine.go +++ b/pkg/traceql/engine.go @@ -177,6 +177,14 @@ func (e *Engine) ExecuteTagValues( span.SetAttributes(attribute.String("pipeline", rootExpr.Pipeline.String())) span.SetAttributes(attribute.String("autocompleteReq", fmt.Sprint(autocompleteReq))) + // If the tag we are fetching is already filtered in the query, then this is a noop. + // I.e. we are autocompleting resource.service.name and the query was {resource.service.name="foo"} + for _, c := range autocompleteReq.Conditions { + if c.Attribute == tag && c.Op == OpEqual { + return nil + } + } + return fetcher.Fetch(ctx, autocompleteReq, cb) } @@ -230,12 +238,6 @@ func (e *Engine) createAutocompleteRequest(tag Attribute, pipeline Pipeline) Fet pipeline.extractConditions(&req) - // TODO: remove other conditions for the wantAttr we're searching for - // for _, cond := range fetchSpansRequest.Conditions { - // if cond.Attribute == wantAttr { - // return fmt.Errorf("cannot search for tag values for tag that is already used in query") - // } - // } req.Conditions = append(req.Conditions, Condition{ Attribute: tag, Op: OpNone, diff --git a/pkg/traceql/engine_test.go b/pkg/traceql/engine_test.go index a578d2451e0..11f0e8d4573 100644 --- a/pkg/traceql/engine_test.go +++ b/pkg/traceql/engine_test.go @@ -666,6 +666,12 @@ func TestExecuteTagValues(t *testing.T) { {Type: "string", Value: "redis call"}, }, }, + { + name: "noop", // autocompleting an attribute already filtered by the query + attribute: "name", + query: `{ name = "foo" }`, + expectedValues: []tempopb.TagValue{}, + }, } { t.Run(tc.name, func(t *testing.T) { distinctValues := collector.NewDistinctValue[tempopb.TagValue](100_000, 0, 0, func(v tempopb.TagValue) int { return len(v.Type) + len(v.Value) })