Skip to content

Commit

Permalink
[log] fix JSON log, better trace log (#3914)
Browse files Browse the repository at this point in the history
  • Loading branch information
millken authored Nov 3, 2023
1 parent b6310db commit 32cbd3c
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 123 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18.5
go-version: 1.19.12
cache: false

- name: Build Go
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.18.5
go-version: 1.19.12

- name: make iotex-server/ioctl
if: startsWith(matrix.os, 'windows-latest') != true
Expand Down
5 changes: 1 addition & 4 deletions api/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

apitypes "github.com/iotexproject/iotex-core/api/types"
"github.com/iotexproject/iotex-core/pkg/log"
"github.com/iotexproject/iotex-core/pkg/tracer"
"github.com/iotexproject/iotex-core/pkg/util/httputil"
)

Expand Down Expand Up @@ -64,14 +63,12 @@ func newHTTPHandler(web3Handler Web3Handler) *hTTPHandler {
}

func (handler *hTTPHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
ctx, span := tracer.NewSpan(req.Context(), "handler.ServeHTTP")
defer span.End()
if req.Method != "POST" {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}

if err := handler.msgHandler.HandlePOSTReq(ctx, req.Body,
if err := handler.msgHandler.HandlePOSTReq(req.Context(), req.Body,
apitypes.NewResponseWriter(
func(resp interface{}) (int, error) {
w.Header().Set("Access-Control-Allow-Origin", "*")
Expand Down
12 changes: 2 additions & 10 deletions api/web3server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/tidwall/gjson"
"go.opentelemetry.io/otel/attribute"
"go.uber.org/zap"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -139,13 +138,8 @@ func (svr *web3Handler) handleWeb3Req(ctx context.Context, web3Req *gjson.Result
size int
)
defer func(start time.Time) { svr.coreService.Track(ctx, start, method.(string), int64(size), err == nil) }(time.Now())
span := tracer.SpanFromContext(ctx)
defer span.End()
span.AddEvent("handleWeb3Req")
span.SetAttributes(
attribute.String("method", method.(string)),
)
log.Logger("api").Debug("web3Debug", zap.String("requestParams", fmt.Sprintf("%+v", web3Req)))

log.T(ctx).Info("handleWeb3Req", zap.String("method", method.(string)), zap.String("requestParams", fmt.Sprintf("%+v", web3Req)))
_web3ServerMtc.WithLabelValues(method.(string)).Inc()
_web3ServerMtc.WithLabelValues("requests_total").Inc()
switch method {
Expand Down Expand Up @@ -254,8 +248,6 @@ func (svr *web3Handler) handleWeb3Req(ctx context.Context, web3Req *gjson.Result
}

func parseWeb3Reqs(reader io.Reader) (gjson.Result, error) {
_, span := tracer.NewSpan(context.Background(), "parseWeb3Reqs")
defer span.End()
data, err := io.ReadAll(reader)
if err != nil {
return gjson.Result{}, err
Expand Down
72 changes: 37 additions & 35 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
module github.com/iotexproject/iotex-core

go 1.18
go 1.19

require (
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/cespare/xxhash/v2 v2.2.0
github.com/ethereum/go-ethereum v1.10.26
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a
github.com/go-redis/redis/v8 v8.11.4
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.2
github.com/golang/protobuf v1.5.3
github.com/golang/snappy v0.0.4
github.com/gorilla/websocket v1.4.2
github.com/grpc-ecosystem/go-grpc-middleware v1.2.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/hashicorp/vault/api v1.1.0
github.com/holiman/uint256 v1.2.0
github.com/iotexproject/go-fsm v1.0.0
github.com/iotexproject/go-p2p v0.3.5
github.com/iotexproject/go-pkgs v0.1.13
Expand All @@ -22,52 +25,47 @@ require (
github.com/iotexproject/iotex-election v0.3.5-0.20210611041425-20ddf674363d
github.com/iotexproject/iotex-proto v0.5.14
github.com/libp2p/go-libp2p-core v0.8.5
github.com/mattn/go-sqlite3 v1.14.8 // indirect
github.com/mackerelio/go-osstat v0.2.4
github.com/miguelmota/go-ethereum-hdwallet v0.1.1
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1
github.com/multiformats/go-multiaddr v0.3.3
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.11.1
github.com/prometheus/client_model v0.2.0
github.com/rodaine/table v1.0.1
github.com/schollz/progressbar/v2 v2.15.0
github.com/shirou/gopsutil/v3 v3.22.2
github.com/spf13/cobra v1.1.1
github.com/stretchr/testify v1.8.1
github.com/stretchr/testify v1.8.3
github.com/tidwall/gjson v1.11.0
github.com/tyler-smith/go-bip39 v1.0.2
github.com/uptrace/opentelemetry-go-extra/otelzap v0.2.2
go.elastic.co/ecszap v1.0.0
go.etcd.io/bbolt v1.3.5
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.25.0
go.opentelemetry.io/otel v1.9.0
go.opentelemetry.io/otel/exporters/jaeger v1.0.1
go.opentelemetry.io/otel/sdk v1.0.1
go.opentelemetry.io/otel/trace v1.9.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.42.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0
go.opentelemetry.io/otel v1.16.0
go.opentelemetry.io/otel/exporters/jaeger v1.16.0
go.opentelemetry.io/otel/sdk v1.16.0
go.opentelemetry.io/otel/trace v1.16.0
go.uber.org/automaxprocs v1.2.0
go.uber.org/config v1.3.1
go.uber.org/zap v1.16.0
golang.org/x/crypto v0.1.0
golang.org/x/net v0.7.0
go.uber.org/zap v1.24.0
golang.org/x/crypto v0.10.0
golang.org/x/exp v0.0.0-20230206171751-46f607a40771
golang.org/x/net v0.11.0
golang.org/x/sync v0.1.0
google.golang.org/genproto v0.0.0-20230127162408-596548ed4efa
google.golang.org/grpc v1.53.0
google.golang.org/protobuf v1.28.1
golang.org/x/text v0.10.0
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc
google.golang.org/grpc v1.56.1
google.golang.org/protobuf v1.30.0
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
github.com/cespare/xxhash/v2 v2.2.0
github.com/holiman/uint256 v1.2.0
github.com/mackerelio/go-osstat v0.2.4
github.com/prometheus/client_model v0.2.0
github.com/shirou/gopsutil/v3 v3.22.2
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.34.0
golang.org/x/exp v0.0.0-20230206171751-46f607a40771
golang.org/x/text v0.7.0
)

require (
cloud.google.com/go/compute v1.23.0 // indirect
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
github.com/benbjohnson/clock v1.0.3 // indirect
github.com/benbjohnson/clock v1.1.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd v0.21.0-beta // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
Expand All @@ -79,12 +77,13 @@ require (
github.com/dustinxie/gmsm v1.4.0 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/flynn/noise v1.0.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/gopacket v1.1.19 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
Expand Down Expand Up @@ -152,6 +151,7 @@ require (
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magefile/mage v1.9.0 // indirect
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect
github.com/mattn/go-sqlite3 v1.14.8 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/miekg/dns v1.1.41 // indirect
github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect
Expand Down Expand Up @@ -185,17 +185,19 @@ require (
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tklauser/go-sysconf v0.3.9 // indirect
github.com/tklauser/numcpus v0.3.0 // indirect
github.com/uptrace/opentelemetry-go-extra/otelutil v0.2.2 // indirect
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect
github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 // indirect
github.com/whyrusleeping/timecache v0.0.0-20160911033111-cfcb2f1abfee // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel/metric v0.31.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/time v0.1.0 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/term v0.9.0 // indirect
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/square/go-jose.v2 v2.5.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit 32cbd3c

Please sign in to comment.