diff --git a/pkg/ambient/ambient.go b/pkg/ambient/ambient.go index 195459a..99cd7bc 100644 --- a/pkg/ambient/ambient.go +++ b/pkg/ambient/ambient.go @@ -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{}, } } diff --git a/pkg/weather/recorder/recorder_get.go b/pkg/weather/recorder/recorder_get.go index 9839f04..534ec58 100644 --- a/pkg/weather/recorder/recorder_get.go +++ b/pkg/weather/recorder/recorder_get.go @@ -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() diff --git a/pkg/weather/recorder/recorder_set.go b/pkg/weather/recorder/recorder_set.go index d5a634a..489f4ab 100644 --- a/pkg/weather/recorder/recorder_set.go +++ b/pkg/weather/recorder/recorder_set.go @@ -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()