mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix(server): prevent otel tracer provider from immediately being closed (#7369)
This commit is contained in:
@@ -21,6 +21,7 @@ import (
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"cdr.dev/slog"
|
||||
"github.com/coder/coder/cli"
|
||||
"github.com/coder/coder/cli/clibase"
|
||||
"github.com/coder/coder/cli/cliui"
|
||||
@@ -136,7 +137,12 @@ func (*RootCmd) proxyServer() *clibase.Cmd {
|
||||
defer http.DefaultClient.CloseIdleConnections()
|
||||
closers.Add(http.DefaultClient.CloseIdleConnections)
|
||||
|
||||
tracer, _ := cli.ConfigureTraceProvider(ctx, logger, inv, cfg)
|
||||
tracer, _, closeTracing := cli.ConfigureTraceProvider(ctx, logger, inv, cfg)
|
||||
defer func() {
|
||||
logger.Debug(ctx, "closing tracing")
|
||||
traceCloseErr := shutdownWithTimeout(closeTracing, 5*time.Second)
|
||||
logger.Debug(ctx, "tracing closed", slog.Error(traceCloseErr))
|
||||
}()
|
||||
|
||||
httpServers, err := cli.ConfigureHTTPServers(inv, cfg)
|
||||
if err != nil {
|
||||
@@ -345,3 +351,9 @@ func (*RootCmd) proxyServer() *clibase.Cmd {
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func shutdownWithTimeout(shutdown func(context.Context) error, timeout time.Duration) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
return shutdown(ctx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user