Skip to content

Commit

Permalink
runtime: Fix opentelemetry gracefull shutdown
Browse files Browse the repository at this point in the history
When running OPA with the distributed tracing option enabled,
the OpenTelemetry trace exporter is not gracefully shut down
when the server is stopped.

This PR fixes that issues by moving the trace exporter shutdown
in the gracefulShutdonw function.

Fixes: open-policy-agent#6651
Signed-off-by: Nicolas Chotard <nicolas.chotard@backmarket.com>
  • Loading branch information
nicolaschotard committed Apr 3, 2024
1 parent 9a13941 commit d18798a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions runtime/runtime.go
Expand Up @@ -534,13 +534,6 @@ func (rt *Runtime) Serve(ctx context.Context) error {
rt.logger.WithFields(map[string]interface{}{"err": err}).Error("Failed to start OpenTelemetry trace exporter.")
return err
}

defer func() {
err := rt.traceExporter.Shutdown(ctx)
if err != nil {
rt.logger.WithFields(map[string]interface{}{"err": err}).Error("Failed to shutdown OpenTelemetry trace exporter gracefully.")
}
}()
}

rt.server = server.New().
Expand Down Expand Up @@ -857,6 +850,13 @@ func (rt *Runtime) gracefulServerShutdown(s *server.Server) error {
return err
}
rt.logger.Info("Server shutdown.")

if rt.traceExporter != nil {
err = rt.traceExporter.Shutdown(ctx)
if err != nil {
rt.logger.WithFields(map[string]interface{}{"err": err}).Error("Failed to shutdown OpenTelemetry trace exporter gracefully.")
}
}
return nil
}

Expand Down

0 comments on commit d18798a

Please sign in to comment.