Skip to content

Commit

Permalink
refactor: refactor func Flush() of metric pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
anhvietnguyennva committed Aug 17, 2023
1 parent a8a6e18 commit 92d4e70
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/metric/meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package metric

import (
"context"
"errors"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/metric"
Expand All @@ -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")
}
}

0 comments on commit 92d4e70

Please sign in to comment.