TraceQL Metrics: right exemplars for histogram and quantiles - #5145
Merged
ruslan-mikhailov merged 10 commits intoJun 2, 2025
Conversation
ruslan-mikhailov
force-pushed
the
bugfix/histogram-exemplars
branch
2 times, most recently
from
May 20, 2025 11:00
e707cd9 to
30d22d1
Compare
ruslan-mikhailov
marked this pull request as ready for review
May 20, 2025 11:33
ruslan-mikhailov
requested review from
carles-grafana,
electron0zero,
ie-pham,
javiermolinar,
joe-elliott,
mapno,
mdisibio,
stoewer,
yvrhdn and
zalegrala
as code owners
May 20, 2025 11:33
mdisibio
reviewed
May 22, 2025
ruslan-mikhailov
force-pushed
the
bugfix/histogram-exemplars
branch
from
May 23, 2025 14:41
04755c4 to
ed202d0
Compare
Contributor
Author
|
+ review fixes |
ruslan-mikhailov
force-pushed
the
bugfix/histogram-exemplars
branch
from
May 23, 2025 14:41
ed202d0 to
68316ef
Compare
Contributor
Author
|
+ rebase from latest master |
mdisibio
reviewed
May 23, 2025
This was referenced May 26, 2025
Contributor
Author
|
+ benchmarks |
Contributor
Author
|
+ review fix |
ruslan-mikhailov
force-pushed
the
bugfix/histogram-exemplars
branch
from
May 27, 2025 12:18
d00396c to
fad8276
Compare
Contributor
Author
|
+ gosec overflow linter mute for testing function |
ruslan-mikhailov
force-pushed
the
bugfix/histogram-exemplars
branch
from
May 27, 2025 12:43
fad8276 to
2bf9905
Compare
mdisibio
approved these changes
May 29, 2025
ruslan-mikhailov
enabled auto-merge (squash)
June 2, 2025 07:58
ruslan-mikhailov
disabled auto-merge
June 2, 2025 08:01
ruslan-mikhailov
force-pushed
the
bugfix/histogram-exemplars
branch
from
June 2, 2025 08:03
2bf9905 to
e4faa25
Compare
Contributor
Author
|
+ rebase from latest main |
ruslan-mikhailov
added a commit
to ruslan-mikhailov/tempo
that referenced
this pull request
Jun 2, 2025
…#5145) * Minor: remove forgotten comment * [Bugfix] TraceQL Metrics: right exemplars for histogram and quantiles * Test fixes: correct unmarshaller * Tests: send traces with different attributes * Tests: by operation * Test attribute values in exemplars * Changelog * Test attribute values in exemplars: additional cases * Benchmarks: HistogramAggregator.Combine * Minor review improvement
3 tasks
ruslan-mikhailov
added a commit
to ruslan-mikhailov/tempo
that referenced
this pull request
Jun 2, 2025
…#5145) * Minor: remove forgotten comment * [Bugfix] TraceQL Metrics: right exemplars for histogram and quantiles * Test fixes: correct unmarshaller * Tests: send traces with different attributes * Tests: by operation * Test attribute values in exemplars * Changelog * Test attribute values in exemplars: additional cases * Benchmarks: HistogramAggregator.Combine * Minor review improvement
ruslan-mikhailov
added a commit
that referenced
this pull request
Jun 2, 2025
…5197) * Minor: remove forgotten comment * [Bugfix] TraceQL Metrics: right exemplars for histogram and quantiles * Test fixes: correct unmarshaller * Tests: send traces with different attributes * Tests: by operation * Test attribute values in exemplars * Changelog * Test attribute values in exemplars: additional cases * Benchmarks: HistogramAggregator.Combine * Minor review improvement
mattdurham
pushed a commit
to mattdurham/tempo
that referenced
this pull request
Jun 18, 2026
…#5145) * Minor: remove forgotten comment * [Bugfix] TraceQL Metrics: right exemplars for histogram and quantiles * Test fixes: correct unmarshaller * Tests: send traces with different attributes * Tests: by operation * Test attribute values in exemplars * Changelog * Test attribute values in exemplars: additional cases * Benchmarks: HistogramAggregator.Combine * Minor review improvement
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does
Root cause
In this loop: https://github.com/ruslan-mikhailov/tempo/blob/17e20a43af0881ef0841d2e33eaeb190c422e549/pkg/traceql/engine_metrics.go#L1477
it iterates over the series set while putting all the exemplars into each resulting series without any filtration: https://github.com/ruslan-mikhailov/tempo/blob/17e20a43af0881ef0841d2e33eaeb190c422e549/pkg/traceql/engine_metrics.go#L1488
For example, if in total, we have the following exemplars:
E1 - span_attr=val_A
E2 - span_attr=val_A
E3 - span_attr=val_B
E4 - span_attr=val_C
For the following query:
we have:
val_A time series exemplars: E1,E2,E3,E4
val_B time series exemplars: E1,E2,E3,E4
val_C time series exemplars: E1,E2,E3,E4
Expected results:
val_A time series exemplars: E1,E2
val_B time series exemplars: E3
val_C time series exemplars: E4
Impact
In Grafana UI, after filtering by series, it provides wrong exemplars from another series, misleading users and providing a bad UX.
How it has been tested
Unit tests (in the PR)
Check that all exemplars have an attribute label that matches the corresponding time series label.
Manual testing
example/docker-compose/localPython script
span.db.systemlabel in exemplars matches"promLabels"of the seriesMain branch results:
After the fix, only exemplars like this:
Which issue(s) this PR fixes
Fixes #
Checklist
CHANGELOG.mdupdated - the order of entries should be[CHANGE],[FEATURE],[ENHANCEMENT],[BUGFIX]