Skip to content

distributor: add counter for spans in the future - #4936

Merged
carles-grafana merged 2 commits into
grafana:mainfrom
carles-grafana:count_spans_in_future
Jun 11, 2025
Merged

distributor: add counter for spans in the future#4936
carles-grafana merged 2 commits into
grafana:mainfrom
carles-grafana:count_spans_in_future

Conversation

@carles-grafana

@carles-grafana carles-grafana commented Apr 2, 2025

Copy link
Copy Markdown
Contributor

What this PR does:

This will allow us to find customers that send spans in the future,
which can't be found using the Search API.

Which issue(s) this PR fixes:
Fixes #

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

@javiermolinar javiermolinar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea. I think this is quite similar to what we have in the data quality package. What do you think of adding a new reason to the existing metric there?. It would be good to have all the related code in the same place. The name of the metrics and the help could be improved, though..

var metric = promauto.NewCounterVec(prometheus.CounterOpts{
Namespace: "tempo",
Name: "warnings_total",
Help: "The total number of warnings per tenant with reason.",
}, []string{"tenant", "reason"})

@carles-grafana

Copy link
Copy Markdown
Contributor Author

@javiermolinar I've converted it to the warn metric

Comment thread modules/distributor/distributor.go
Comment thread modules/distributor/distributor.go Outdated
@carles-grafana

Copy link
Copy Markdown
Contributor Author

As discussed with Joe, we should use the slack time to determine whether a span is in the past or in the future. However, this configuration field is only available in the Ingesters, and these have RF3, which means we cannot reliably count ingested spans there.

I will try instead to implement it in the block builder for Tempo 3.

@carles-grafana
carles-grafana force-pushed the count_spans_in_future branch 2 times, most recently from 448e0ce to 544ac41 Compare April 14, 2025 12:44
@carles-grafana
carles-grafana force-pushed the count_spans_in_future branch from 91f3f40 to b85ccec Compare May 7, 2025 13:51
Comment thread modules/distributor/distributor.go
@carles-grafana
carles-grafana requested a review from joe-elliott May 8, 2025 08:50
@carles-grafana

carles-grafana commented May 9, 2025

Copy link
Copy Markdown
Contributor Author

In the end we decided to put it in the distributor as the implementation is simpler and we'll have real time data, which wouldn't be possible in the block-builder

Comment thread pkg/dataquality/warnings.go Outdated

var MetricSpanInFuture = promauto.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "tempo",
Name: "span_in_future_total",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the suffix on prometheus metrics should be the unit. something like?

tempo_spans_distance_in_future_seconds

wdyt about putting these in the dataquality package:

https://github.com/grafana/tempo/blob/main/pkg/dataquality/warnings.go

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the names.

Comment thread modules/distributor/distributor.go Outdated
if end > currentTime {
dataquality.MetricSpanInFuture.WithLabelValues(userID).Observe(float64(end - currentTime))
} else {
dataquality.MetricSpanInPast.WithLabelValues(userID).Observe(float64(currentTime - start))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we use span end time to enforce ingestion slack in other spots. should we use the end time here? what are we attempting to do with this metric?

if the goal is to measure lag due to the tracing pipeline i think end makes more sense, but maybe our goals here are different?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's worth having the metric in the past, only for spans in the future, unless you have use case in mind

@carles-grafana carles-grafana May 9, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which makes me thing a histogram isn't really worth it. Maybe we should go for the original idea of counting spans in the future and that's it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A spans in the future counter seems useful as it suggests something wildly wrong like a system clock misconfigured or a script that's generating bad data.

A spans in the past histogram seems useful as it can give information about the impact of delays due to trace pipelining.

@mapno how does rhythm impact ingestion slack in the block builder/generator? does the time in queue impact this behavior or do we propagate the ingestion time forward somehow?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mapno how does rhythm impact ingestion slack in the block builder/generator? does the time in queue impact this behavior or do we propagate the ingestion time forward somehow?

Traces get longer to get to metrics-generators (and block-builders) than with the classic architecture. Delay should go from milliseconds in normal operation to whatever lag it accumulates—minutes, hours.

In the distributors there is no difference.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed it to the end time, I agree it makes more sense.

@carles-grafana
carles-grafana force-pushed the count_spans_in_future branch from b85ccec to 3f02e52 Compare May 20, 2025 13:07
@knylander-grafana

Copy link
Copy Markdown
Contributor

Are there any changes that impact Tempo users? If so, we should consider adding docs.

@carles-grafana

Copy link
Copy Markdown
Contributor Author

@joe-elliott are we still interested in having this?

@joe-elliott joe-elliott left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the changelog. It's trying to add to 2.8 but I'm good on this.

Double check that you can get a decent visualization out of this and then let's talk internally about exposing it to cloud customers as a dataquality metric.

@carles-grafana
carles-grafana force-pushed the count_spans_in_future branch from 3f02e52 to 88e9a40 Compare June 11, 2025 09:18
@carles-grafana
carles-grafana marked this pull request as draft June 11, 2025 10:04
@carles-grafana
carles-grafana marked this pull request as ready for review June 11, 2025 10:04
@carles-grafana
carles-grafana force-pushed the count_spans_in_future branch from 88e9a40 to 9b93d90 Compare June 11, 2025 10:05
@carles-grafana
carles-grafana merged commit 81ce5be into grafana:main Jun 11, 2025
mattdurham pushed a commit to mattdurham/tempo that referenced this pull request Jun 18, 2026
* distributor: add metrics for spans in the past/future

* Update changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants