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
Original file line number Diff line number Diff line change
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.