package recorder import ( "context" "sync" "github.com/rs/zerolog" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/trace" "gitea.libretechconsulting.com/rmcguire/go-app/pkg/otel" "gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/ambient/config" "gitea.libretechconsulting.com/rmcguire/ambient-local-exporter/pkg/weather/recorder/recorders" ) type WeatherRecorder struct { recorder recorders.Recorder ctx context.Context tracer trace.Tracer meter metric.Meter *sync.RWMutex } type Opts struct { AppConfig *config.AmbientLocalExporterConfig Ctx context.Context Recorder recorders.Recorder // If nil, will use memory recorder KeepLast int } func (r *WeatherRecorder) Ping(ctx context.Context) error { return r.recorder.Ping(ctx) } func MustNewWeatherRecorder(opts *Opts) *WeatherRecorder { if opts.KeepLast < 1 { opts.KeepLast = 1 } if opts.Recorder == nil { panic("no recorder provided") } opts.Recorder.Init(opts.Ctx, &recorders.RecorderOpts{ AppConfig: opts.AppConfig, RetainLast: opts.KeepLast, BaseCtx: opts.Ctx, }) zerolog.Ctx(opts.Ctx).Info().Str("recorderType", opts.Recorder.Name()). Msg("weather update recorder ready") return &WeatherRecorder{ ctx: opts.Ctx, recorder: opts.Recorder, tracer: otel.GetTracer(opts.Ctx, "weatherRecorder"), meter: otel.GetMeter(opts.Ctx, "weatherRecorder"), RWMutex: &sync.RWMutex{}, } }