fix recorder

This commit is contained in:
Ryan McGuire 2025-03-21 12:52:39 -04:00
parent 42eea2346b
commit 1f097b1fd7
3 changed files with 9 additions and 8 deletions

View File

@ -42,8 +42,9 @@ type AmbientWeather struct {
func New(appCtx context.Context, awConfig *config.AmbientLocalExporterConfig) *AmbientWeather {
return &AmbientWeather{
Config: awConfig,
appCtx: appCtx,
Config: awConfig,
appCtx: appCtx,
RWMutex: &sync.RWMutex{},
}
}

View File

@ -26,7 +26,7 @@ func (w *WeatherRecorder) Get(ctx context.Context, last int) (
span.SetAttributes(
attribute.Int("last", last),
attribute.Int("keep", w.keep),
attribute.Int("currentSize", w.Count()),
attribute.Int("currentSize", w.Count(ctx)),
)
defer span.End()
@ -47,7 +47,7 @@ func (w *WeatherRecorder) get(ctx context.Context, last int) (
span := trace.SpanFromContext(ctx)
w.RLock()
defer w.Unlock()
defer w.RUnlock()
span.AddEvent("acquired lock on recorder cache")
@ -70,8 +70,8 @@ func (w *WeatherRecorder) get(ctx context.Context, last int) (
}
// Returns count of retained weather updates
func (w *WeatherRecorder) Count() int {
_, span := w.tracer.Start(w.ctx, "countWeatherRecorder")
func (w *WeatherRecorder) Count(ctx context.Context) int {
_, span := w.tracer.Start(ctx, "countWeatherRecorder")
defer span.End()
count := w.count()

View File

@ -10,9 +10,9 @@ import (
)
func (w *WeatherRecorder) Set(ctx context.Context, u *weather.WeatherUpdate) error {
_, span := w.tracer.Start(ctx, "recordWeatherUpdate")
ctx, span := w.tracer.Start(ctx, "recordWeatherUpdate")
span.SetAttributes(
attribute.Int("countWeatherUpdates", w.Count()),
attribute.Int("countWeatherUpdates", w.Count(ctx)),
attribute.Int("keepUpdates", w.keep),
)
defer span.End()