diff --git a/prometheus/counter.go b/prometheus/counter.go index 40d1b24f3..3668a16b3 100644 --- a/prometheus/counter.go +++ b/prometheus/counter.go @@ -140,7 +140,8 @@ func (c *counter) get() float64 { } func (c *counter) Write(out *dto.Metric) error { - + // Read the Exemplar first and the value second. This is to avoid a race condition + // where users see an exemplar for a not-yet-existing observation. var exemplar *dto.Exemplar if e := c.exemplar.Load(); e != nil { exemplar = e.(*dto.Exemplar)