Skip to content

Commit

Permalink
fix telemetry setup
Browse files Browse the repository at this point in the history
adapt for the changes in cosmos/cosmos-sdk#12448
  • Loading branch information
yihuang committed Jan 19, 2023
1 parent 3867803 commit 1e6899e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions server/start.go
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/telemetry"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -230,6 +231,16 @@ func startStandAlone(ctx *server.Context, opts StartOptions) error {

app := opts.AppCreator(ctx.Logger, db, traceWriter, ctx.Viper)

config, err := config.GetConfig(ctx.Viper)
if err != nil {
return err
}

_, err = startTelemetry(config)
if err != nil {
return err
}

svr, err := abciserver.NewServer(addr, transport, app)
if err != nil {
return fmt.Errorf("error creating listener: %v", err)
Expand Down Expand Up @@ -455,10 +466,18 @@ func startInProcess(ctx *server.Context, clientCtx client.Context, opts StartOpt
}
}

metrics, err := startTelemetry(config)
if err != nil {
return err
}

var apiSrv *api.Server
if config.API.Enable {
apiSrv = api.New(clientCtx, ctx.Logger.With("server", "api"))
app.RegisterAPIRoutes(apiSrv, config.API)
if config.Telemetry.Enabled {
apiSrv.SetTelemetry(metrics)
}
errCh := make(chan error)
go func() {
if err := apiSrv.Start(config.Config); err != nil {
Expand Down Expand Up @@ -601,3 +620,10 @@ func openTraceWriter(traceWriterFile string) (w io.Writer, err error) {
0o600,
)
}

func startTelemetry(cfg config.Config) (*telemetry.Metrics, error) {
if !cfg.Telemetry.Enabled {
return nil, nil
}
return telemetry.New(cfg.Telemetry)
}

0 comments on commit 1e6899e

Please sign in to comment.