Skip to content

Commit

Permalink
fix: flush everything when quitting
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <bob@vibioh.fr>
  • Loading branch information
ViBiOh committed Jan 28, 2024
1 parent 7fdddd5 commit 8f93404
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,20 @@ func (s Service) Middleware(name string) func(next http.Handler) http.Handler {

func (s Service) Close(ctx context.Context) {
if s.tracerProvider != nil {
if err := s.tracerProvider.ForceFlush(ctx); err != nil {
slog.LogAttrs(ctx, slog.LevelError, "flush trace provider", slog.Any("error", err))
}

if err := s.tracerProvider.Shutdown(ctx); err != nil {
slog.LogAttrs(ctx, slog.LevelError, "shutdown trace provider", slog.Any("error", err))
}
}

if s.meterProvider != nil {
if err := s.meterProvider.ForceFlush(ctx); err != nil {
slog.LogAttrs(ctx, slog.LevelError, "flush meter provider", slog.Any("error", err))
}

if err := s.meterProvider.Shutdown(ctx); err != nil {
slog.LogAttrs(ctx, slog.LevelError, "shutdown meter provider", slog.Any("error", err))
}
Expand Down

0 comments on commit 8f93404

Please sign in to comment.