package state import ( "context" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" "gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather" ) func (w *WeatherState) Set(ctx context.Context, u *weather.WeatherUpdate) error { _, span := w.tracer.Start(ctx, "setWeatherState") span.SetAttributes( attribute.Int("countWeatherUpdates", w.Count()), attribute.Int("keepUpdates", w.keep), ) defer span.End() return w.set(span, u) } func (w *WeatherState) set(span trace.Span, u *weather.WeatherUpdate) error { w.Lock() defer w.Unlock() if len(w.updates) > w.keep { w.updates = w.updates[1:] span.AddEvent("trimmed state updates by 1") } w.updates = append(w.updates, u) span.AddEvent("recorded weather state") return nil }