Skip to content

Commit a3f2527

Browse files
authored
fix: always use context.Background() when updating metrics (#131)
1 parent 366f931 commit a3f2527

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

aggregators/aggregator.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,12 @@ func (a *Aggregator) AggregateBatch(
159159

160160
var err error
161161
if len(errs) > 0 {
162-
a.metrics.BytesProcessed.Add(ctx, failBytes, metric.WithAttributeSet(
162+
a.metrics.BytesProcessed.Add(context.Background(), failBytes, metric.WithAttributeSet(
163163
attribute.NewSet(append(cmIDAttrs, telemetry.WithFailure())...),
164164
))
165165
err = fmt.Errorf("failed batch aggregation:\n%w", errors.Join(errs...))
166166
}
167-
a.metrics.BytesProcessed.Add(ctx, successBytes, metric.WithAttributeSet(
167+
a.metrics.BytesProcessed.Add(context.Background(), successBytes, metric.WithAttributeSet(
168168
attribute.NewSet(append(cmIDAttrs, telemetry.WithSuccess())...),
169169
))
170170
return err
@@ -199,7 +199,7 @@ func (a *Aggregator) AggregateCombinedMetrics(
199199

200200
if cmk.ProcessingTime.Before(a.processingTime.Add(-a.cfg.Lookback)) {
201201
a.metrics.EventsProcessed.Add(
202-
ctx, cm.EventsTotal,
202+
context.Background(), cm.EventsTotal,
203203
metric.WithAttributes(append(
204204
a.cfg.CombinedMetricsIDToKVs(cmk.ID),
205205
attribute.String(aggregationIvlKey, formatDuration(cmk.Interval)),
@@ -228,7 +228,7 @@ func (a *Aggregator) AggregateCombinedMetrics(
228228

229229
span.SetAttributes(attribute.Int("bytes_ingested", bytesIn))
230230
a.cachedEvents.add(cmk.Interval, cmk.ID, cm.EventsTotal)
231-
a.metrics.BytesProcessed.Add(ctx, int64(bytesIn), attrSetOpt)
231+
a.metrics.BytesProcessed.Add(context.Background(), int64(bytesIn), attrSetOpt)
232232
return err
233233
}
234234

@@ -526,7 +526,7 @@ func (a *Aggregator) harvestForInterval(
526526
if n == 0 {
527527
return
528528
}
529-
a.metrics.MetricsOverflowed.Add(ctx, int64(n), commonAttrsOpt, metric.WithAttributes(
529+
a.metrics.MetricsOverflowed.Add(context.Background(), int64(n), commonAttrsOpt, metric.WithAttributes(
530530
attribute.String(aggregationTypeKey, aggregationType),
531531
))
532532
}
@@ -550,11 +550,11 @@ func (a *Aggregator) harvestForInterval(
550550
// Negative values are possible at edges due to delays in running the
551551
// harvest loop or time sync issues between agents and server.
552552
queuedDelay := time.Since(harvestStats.youngestEventTimestamp).Seconds()
553-
a.metrics.MinQueuedDelay.Record(ctx, queuedDelay, commonAttrsOpt, outcomeAttrOpt)
554-
a.metrics.ProcessingLatency.Record(ctx, processingDelay, commonAttrsOpt, outcomeAttrOpt)
553+
a.metrics.MinQueuedDelay.Record(context.Background(), queuedDelay, commonAttrsOpt, outcomeAttrOpt)
554+
a.metrics.ProcessingLatency.Record(context.Background(), processingDelay, commonAttrsOpt, outcomeAttrOpt)
555555
// Events harvested have been successfully processed, publish these
556556
// as success. Update the map to keep track of events failed.
557-
a.metrics.EventsProcessed.Add(ctx, harvestStats.eventsTotal, commonAttrsOpt, outcomeAttrOpt)
557+
a.metrics.EventsProcessed.Add(context.Background(), harvestStats.eventsTotal, commonAttrsOpt, outcomeAttrOpt)
558558
cachedEventsStats[cmk.ID] -= harvestStats.eventsTotal
559559
}
560560
err := a.db.DeleteRange(lb, ub, a.writeOptions)
@@ -589,7 +589,7 @@ func (a *Aggregator) harvestForInterval(
589589
telemetry.WithFailure(),
590590
)...),
591591
)
592-
a.metrics.EventsProcessed.Add(ctx, eventsTotal, attrSetOpt)
592+
a.metrics.EventsProcessed.Add(context.Background(), eventsTotal, attrSetOpt)
593593
}
594594
return cmCount, err
595595
}

0 commit comments

Comments
 (0)