From 92d4e70f5d2ff4d2655b1222a570711a6a7bab78 Mon Sep 17 00:00:00 2001 From: anhnv Date: Thu, 17 Aug 2023 15:33:41 +0700 Subject: [PATCH] refactor: refactor func Flush() of metric pkg --- pkg/metric/meter.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/metric/meter.go b/pkg/metric/meter.go index be66caa..9400bc2 100644 --- a/pkg/metric/meter.go +++ b/pkg/metric/meter.go @@ -2,6 +2,7 @@ package metric import ( "context" + "errors" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/metric" @@ -16,5 +17,9 @@ func Meter() metric.Meter { } func Flush(ctx context.Context) error { - return otel.GetMeterProvider().(*metricsdk.MeterProvider).ForceFlush(ctx) + if m, ok := otel.GetMeterProvider().(*metricsdk.MeterProvider); ok { + return m.ForceFlush(ctx) + } else { + return errors.New("no meter provider was initialized") + } }