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

@ -44,6 +44,7 @@ func New(appCtx context.Context, awConfig *config.AmbientLocalExporterConfig) *A
return &AmbientWeather{ return &AmbientWeather{
Config: awConfig, Config: awConfig,
appCtx: appCtx, appCtx: appCtx,
RWMutex: &sync.RWMutex{},
} }
} }

View File

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

View File

@ -10,9 +10,9 @@ import (
) )
func (w *WeatherRecorder) Set(ctx context.Context, u *weather.WeatherUpdate) error { 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( span.SetAttributes(
attribute.Int("countWeatherUpdates", w.Count()), attribute.Int("countWeatherUpdates", w.Count(ctx)),
attribute.Int("keepUpdates", w.keep), attribute.Int("keepUpdates", w.keep),
) )
defer span.End() defer span.End()