fix: use singleton meter provider (#5725)

This commit is contained in:
Elio Bischof 2023-04-25 20:15:32 +02:00 committed by GitHub
parent c12c2f09a4
commit 923f691d77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,7 +18,7 @@ import (
) )
type Metrics struct { type Metrics struct {
Exporter *prometheus.Exporter Provider metric.MeterProvider
Meter metric.Meter Meter metric.Meter
Counters sync.Map Counters sync.Map
UpDownSumObserver sync.Map UpDownSumObserver sync.Map
@ -34,12 +34,13 @@ func NewMetrics(meterName string) (metrics.Metrics, error) {
if err != nil { if err != nil {
return &Metrics{}, err return &Metrics{}, err
} }
return &Metrics{ meterProvider := sdk_metric.NewMeterProvider(
Exporter: exporter,
Meter: sdk_metric.NewMeterProvider(
sdk_metric.WithReader(exporter), sdk_metric.WithReader(exporter),
sdk_metric.WithResource(resource), sdk_metric.WithResource(resource),
).Meter(meterName), )
return &Metrics{
Provider: meterProvider,
Meter: meterProvider.Meter(meterName),
}, nil }, nil
} }
@ -48,7 +49,7 @@ func (m *Metrics) GetExporter() http.Handler {
} }
func (m *Metrics) GetMetricsProvider() metric.MeterProvider { func (m *Metrics) GetMetricsProvider() metric.MeterProvider {
return sdk_metric.NewMeterProvider(sdk_metric.WithReader(m.Exporter)) return m.Provider
} }
func (m *Metrics) RegisterCounter(name, description string) error { func (m *Metrics) RegisterCounter(name, description string) error {