From 923f691d77ce047cc01a7600e280b6aa0f979de7 Mon Sep 17 00:00:00 2001 From: Elio Bischof Date: Tue, 25 Apr 2023 20:15:32 +0200 Subject: [PATCH] fix: use singleton meter provider (#5725) --- internal/telemetry/metrics/otel/open_telemetry.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/internal/telemetry/metrics/otel/open_telemetry.go b/internal/telemetry/metrics/otel/open_telemetry.go index 4a18c6171c..e249f00d88 100644 --- a/internal/telemetry/metrics/otel/open_telemetry.go +++ b/internal/telemetry/metrics/otel/open_telemetry.go @@ -18,7 +18,7 @@ import ( ) type Metrics struct { - Exporter *prometheus.Exporter + Provider metric.MeterProvider Meter metric.Meter Counters sync.Map UpDownSumObserver sync.Map @@ -34,12 +34,13 @@ func NewMetrics(meterName string) (metrics.Metrics, error) { if err != nil { return &Metrics{}, err } + meterProvider := sdk_metric.NewMeterProvider( + sdk_metric.WithReader(exporter), + sdk_metric.WithResource(resource), + ) return &Metrics{ - Exporter: exporter, - Meter: sdk_metric.NewMeterProvider( - sdk_metric.WithReader(exporter), - sdk_metric.WithResource(resource), - ).Meter(meterName), + Provider: meterProvider, + Meter: meterProvider.Meter(meterName), }, nil } @@ -48,7 +49,7 @@ func (m *Metrics) GetExporter() http.Handler { } 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 {