From 1ce53aeefafc50a77cbd22d2566a766988587d88 Mon Sep 17 00:00:00 2001 From: Zachary_ZH Date: Sat, 28 Nov 2026 01:25:55 +0800 Subject: [PATCH 1/2] lib/traceql: convert duration values in duration filters only `{ span.cache.ttl = "30s" }` was translated to `"span_attr:cache.ttl":=30000000000`, so it never matched a span whose `cache.ttl` attribute is the string `30s`. Values such as `100ms` are converted to nanoseconds only for the `duration` field now. Fixes https://github.com/VictoriaMetrics/VictoriaTraces/issues/321 --- docs/victoriatraces/changelog/CHANGELOG.md | 1 + lib/traceql/filter_general.go | 10 +++++----- lib/traceql/parser_test.go | 3 +++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/victoriatraces/changelog/CHANGELOG.md b/docs/victoriatraces/changelog/CHANGELOG.md index e5e58f9f6..81101e005 100644 --- a/docs/victoriatraces/changelog/CHANGELOG.md +++ b/docs/victoriatraces/changelog/CHANGELOG.md @@ -15,6 +15,7 @@ The following `tip` changes can be tested by building VictoriaTraces components * FEATURE: [vmui](https://docs.victoriametrics.com/victoriatraces/querying/#web-ui): add the `Volume by service` chart to the Trace Explorer page. It shows the number of spans over time for the top 20 services, so ingestion spikes and the traffic split across services are visible. See [this issue #263](https://github.com/VictoriaMetrics/VictoriaTraces/issues/263). * BUGFIX: [Single-node VictoriaTraces](https://docs.victoriametrics.com/victoriatraces/) and vtselect in [VictoriaTraces cluster](https://docs.victoriametrics.com/victoriatraces/cluster/): return correct results for TraceQL filters with `||` in the Tempo API, such as `{ status = error || duration > 5s }`. Previously, such a filter could count extra spans, or the search failed with `cannot parse in()`, depending on the order of the conditions. Thank @ZeXi0308 for [the issue #319](https://github.com/VictoriaMetrics/VictoriaTraces/issues/319) and [the pull request #320](https://github.com/VictoriaMetrics/VictoriaTraces/pull/320). +* BUGFIX: [Single-node VictoriaTraces](https://docs.victoriametrics.com/victoriatraces/) and vtselect in [VictoriaTraces cluster](https://docs.victoriametrics.com/victoriatraces/cluster/): match attribute values that look like durations in TraceQL filters of the Tempo API, such as `{ span.cache.ttl = "30s" }`. Previously, such a value was converted to nanoseconds and the filter matched nothing. The conversion now applies to `duration` and `traceDuration` filters only. Thank @ZeXi0308 for [the issue #321](https://github.com/VictoriaMetrics/VictoriaTraces/issues/321) and [the pull request #322](https://github.com/VictoriaMetrics/VictoriaTraces/pull/322). ## [v0.13.0](https://github.com/VictoriaMetrics/VictoriaTraces/releases/tag/v0.13.0) diff --git a/lib/traceql/filter_general.go b/lib/traceql/filter_general.go index 8cb230072..2afc41ede 100644 --- a/lib/traceql/filter_general.go +++ b/lib/traceql/filter_general.go @@ -133,11 +133,11 @@ func (fc *filterCommon) String() string { } else if fieldName == "kind" { // map span kind (server, client, producer, consumer...) to numeric OpenTelemetry SpanKind values. fieldValue = rewriteSpanKindInRegex(fieldValue) - } - - // translate duration to nanosecond. - if duration, ok := tryParseDuration(fieldValue); ok { - fieldValue = strconv.FormatInt(duration, 10) + } else if fieldName == otelpb.DurationField { + // translate duration to nanosecond. + if duration, ok := tryParseDuration(fieldValue); ok { + fieldValue = strconv.FormatInt(duration, 10) + } } // for stream filter, just use the source op (=, !=, =~, !~), as they're identical in LogsQL. diff --git a/lib/traceql/parser_test.go b/lib/traceql/parser_test.go index 272848669..029bab049 100644 --- a/lib/traceql/parser_test.go +++ b/lib/traceql/parser_test.go @@ -74,6 +74,9 @@ func TestParseQuery(t *testing.T) { f(`{ span.http.request_content_length > 10} | select(span.http.request_content_length) | by(span.http.request_content_length, span.http.request_content_length2) | sum(other_field) > 2m`, `"span_attr:http.request_content_length":>10 | select(span.http.request_content_length) | by(span.http.request_content_length, span.http.request_content_length2) | sum(other_field) > 2m`) f(`{(a=b && c=d && c=d)}`, `a:=b and c:=d and c:=d`) f(`{span.http.status_code = "200"}`, `"span_attr:http.status_code":=200`) + f(`{span.cache.ttl = "30s"}`, `"span_attr:cache.ttl":=30s`) + f(`{span.cache.ttl = 30s}`, `"span_attr:cache.ttl":=30s`) + f(`{duration > 100ms}`, `duration:>100000000`) f(`{status = "error"}`, `status_code:=2`) f(`{status = "unset"}`, `status_code:=0`) f(`{resource.service.name = "my_service"}`, `{"resource_attr:service.name"=my_service}`) From 9913fe21db0050056db03c33aefe184c8d1f4a41 Mon Sep 17 00:00:00 2001 From: Jiekun Date: Mon, 30 Nov 2026 11:57:51 +0800 Subject: [PATCH 2/2] traceql: follow-up after 1ce53aeefafc50a77cbd22d2566a766988587d88 to verify traceDuration, and use simple string instead of const --- lib/traceql/filter_general.go | 2 +- lib/traceql/parser_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/traceql/filter_general.go b/lib/traceql/filter_general.go index 2afc41ede..3de42b35e 100644 --- a/lib/traceql/filter_general.go +++ b/lib/traceql/filter_general.go @@ -133,7 +133,7 @@ func (fc *filterCommon) String() string { } else if fieldName == "kind" { // map span kind (server, client, producer, consumer...) to numeric OpenTelemetry SpanKind values. fieldValue = rewriteSpanKindInRegex(fieldValue) - } else if fieldName == otelpb.DurationField { + } else if fieldName == "duration" { // translate duration to nanosecond. if duration, ok := tryParseDuration(fieldValue); ok { fieldValue = strconv.FormatInt(duration, 10) diff --git a/lib/traceql/parser_test.go b/lib/traceql/parser_test.go index 029bab049..6f040cd89 100644 --- a/lib/traceql/parser_test.go +++ b/lib/traceql/parser_test.go @@ -163,6 +163,7 @@ func TestGetTraceDurationFilters(t *testing.T) { f(`{(a=b && c=d && c=d)}`, `a:=b and c:=d and c:=d`) f(`{(traceDuration=10ms && c=d && c=d)}`, `* and c:=d and c:=d | join by (trace_id) ({trace_id_idx_stream!=""} AND duration := 10000000 | fields trace_id_idx | rename trace_id_idx as trace_id) inner`) + f(`{(traceDuration="10ms" && c=d && c=d)}`, `* and c:=d and c:=d | join by (trace_id) ({trace_id_idx_stream!=""} AND duration := 10000000 | fields trace_id_idx | rename trace_id_idx as trace_id) inner`) f(`{(traceDuration>10ms && c=d && c=d)}`, `* and c:=d and c:=d | join by (trace_id) ({trace_id_idx_stream!=""} AND duration :> 10000000 | fields trace_id_idx | rename trace_id_idx as trace_id) inner`) f(`{(traceDuration>=10ms && traceDuration<1s && c=d)}`, `* and * and c:=d | join by (trace_id) ({trace_id_idx_stream!=""} AND duration :>= 10000000 AND duration :< 1000000000 | fields trace_id_idx | rename trace_id_idx as trace_id) inner`) }