diff --git a/server/api/server.go b/server/api/server.go index 5bc406acfa38..ef280951e6f7 100644 --- a/server/api/server.go +++ b/server/api/server.go @@ -90,6 +90,16 @@ func New(clientCtx client.Context, logger log.Logger) *Server { // non-blocking, so an external signal handler must be used. func (s *Server) Start(cfg config.Config) error { s.mtx.Lock() + if cfg.Telemetry.Enabled { + m, err := telemetry.New(cfg.Telemetry) + if err != nil { + s.mtx.Unlock() + return err + } + + s.metrics = m + s.registerMetrics() + } tmCfg := tmrpcserver.DefaultConfig() tmCfg.MaxOpenConnections = int(cfg.API.MaxOpenConnections) @@ -129,13 +139,6 @@ func (s *Server) registerGRPCGatewayRoutes() { s.Router.PathPrefix("/").Handler(s.GRPCGatewayRouter) } -func (s *Server) SetTelemetry(m *telemetry.Metrics) { - s.mtx.Lock() - s.metrics = m - s.registerMetrics() - s.mtx.Unlock() -} - func (s *Server) registerMetrics() { metricsHandler := func(w http.ResponseWriter, r *http.Request) { format := strings.TrimSpace(r.FormValue("format")) diff --git a/server/start.go b/server/start.go index e61b96204c53..db20d3afb81e 100644 --- a/server/start.go +++ b/server/start.go @@ -32,7 +32,6 @@ import ( "github.com/cosmos/cosmos-sdk/server/rosetta" crgserver "github.com/cosmos/cosmos-sdk/server/rosetta/lib/server" "github.com/cosmos/cosmos-sdk/server/types" - "github.com/cosmos/cosmos-sdk/telemetry" sdktypes "github.com/cosmos/cosmos-sdk/types" ) @@ -213,16 +212,6 @@ func startStandAlone(ctx *Context, appCreator types.AppCreator) error { app := appCreator(ctx.Logger, db, traceWriter, ctx.Viper) - config, err := serverconfig.GetConfig(ctx.Viper) - if err != nil { - return err - } - - _, err = startTelemetry(config) - if err != nil { - return err - } - svr, err := server.NewServer(addr, transport, app) if err != nil { return fmt.Errorf("error creating listener: %v", err) @@ -342,11 +331,6 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App } } - metrics, err := startTelemetry(config) - if err != nil { - return err - } - var apiSrv *api.Server if config.API.Enable { genDoc, err := genDocProvider() @@ -394,9 +378,6 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App apiSrv = api.New(clientCtx, ctx.Logger.With("module", "api-server")) app.RegisterAPIRoutes(apiSrv, config.API) - if config.Telemetry.Enabled { - apiSrv.SetTelemetry(metrics) - } errCh := make(chan error) go func() { @@ -515,10 +496,3 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App // wait for signal capture and gracefully return return WaitForQuitSignals() } - -func startTelemetry(cfg serverconfig.Config) (*telemetry.Metrics, error) { - if !cfg.Telemetry.Enabled { - return nil, nil - } - return telemetry.New(cfg.Telemetry) -}