Skip to content

Commit

Permalink
change opencensus tracing to opentelemetry tracing
Browse files Browse the repository at this point in the history
fix
fix

Signed-off-by: kpango <[email protected]>
  • Loading branch information
kpango committed Aug 25, 2022
1 parent 5262c62 commit 77a860e
Show file tree
Hide file tree
Showing 52 changed files with 1,789 additions and 4,699 deletions.
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ TEMP_DIR := $(eval TEMP_DIR := $(shell mktemp -d))$(TEMP_DIR)
OPERATOR_SDK_VERSION := $(eval OPERATOR_SDK_VERSION := $(shell cat versions/OPERATOR_SDK_VERSION))$(OPERATOR_SDK_VERSION)

KIND_VERSION ?= v0.14.0
HELM_VERSION ?= v3.9.0
HELM_VERSION ?= v3.9.3
HELM_DOCS_VERSION ?= 1.11.0
YQ_VERSION ?= v4.25.3
VALDCLI_VERSION ?= v1.5.4
TELEPRESENCE_VERSION ?= 2.6.8
KUBELINTER_VERSION ?= 0.3.0
GOLANGCILINT_VERSION ?= v1.46.2
YQ_VERSION ?= v4.27.2
VALDCLI_VERSION ?= v1.5.6
TELEPRESENCE_VERSION ?= 2.7.1
KUBELINTER_VERSION ?= 0.4.0
GOLANGCILINT_VERSION ?= v1.48.0
REVIEWDOG_VERSION ?= v0.14.1
PROTOBUF_VERSION ?= 21.2
PROTOBUF_VERSION ?= 21.5
JAEGER_OPERATOR_VERSION ?= 2.30.0

SWAP_DEPLOYMENT_TYPE ?= deployment
Expand Down
6 changes: 3 additions & 3 deletions example/client/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ replace (
github.com/kpango/glg => github.com/kpango/glg v1.6.12
github.com/pkg/sftp => github.com/pkg/sftp v1.13.5
golang.org/x/crypto => golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa
golang.org/x/net => golang.org/x/net v0.0.0-20220805013720-a33c5aa5df48
golang.org/x/net => golang.org/x/net v0.0.0-20220812174116-3211cb980234
golang.org/x/text => golang.org/x/text v0.3.7
google.golang.org/genproto => google.golang.org/genproto v0.0.0-20220805133916-01dd62135a58
google.golang.org/genproto => google.golang.org/genproto v0.0.0-20220815135757-37a418bb8959
google.golang.org/grpc => google.golang.org/grpc v1.48.0
google.golang.org/protobuf => google.golang.org/protobuf v1.28.1
gopkg.in/yaml.v2 => gopkg.in/yaml.v2 v2.4.0
Expand All @@ -35,5 +35,5 @@ require (
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/genproto v0.0.0-20220616135557-88e70c0c3a90 // indirect
google.golang.org/protobuf v1.28.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
)
8 changes: 4 additions & 4 deletions example/client/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPI
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.5.0/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
golang.org/x/net v0.0.0-20220805013720-a33c5aa5df48 h1:N9Vc/rorQUDes6B9CNdIxAn5jODGj2wzfrei2x4wNj4=
golang.org/x/net v0.0.0-20220805013720-a33c5aa5df48/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/net v0.0.0-20220812174116-3211cb980234 h1:RDqmgfe7SvlMWoqC3xwQ2blLO3fcWcxMa3eBLRdRW7E=
golang.org/x/net v0.0.0-20220812174116-3211cb980234/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -86,8 +86,8 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T
gonum.org/v1/hdf5 v0.0.0-20210714002203-8c5d23bc6946 h1:vJpL69PeUullhJyKtTjHjENEmZU3BkO4e+fod7nKzgM=
gonum.org/v1/hdf5 v0.0.0-20210714002203-8c5d23bc6946/go.mod h1:BQUWDHIAygjdt1HnUPQ0eWqLN2n5FwJycrpYUVUOx2I=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20220805133916-01dd62135a58 h1:sRT5xdTkj1Kbk30qbYC7VyMj73N5pZYsw6v+Nrzdhno=
google.golang.org/genproto v0.0.0-20220805133916-01dd62135a58/go.mod h1:iHe1svFLAZg9VWz891+QbRMwUv9O/1Ww+/mngYeThbc=
google.golang.org/genproto v0.0.0-20220815135757-37a418bb8959 h1:hw4Y42zL1VyVKxPgRHHh191fpVBGV8sNVmcow5Z8VXY=
google.golang.org/genproto v0.0.0-20220815135757-37a418bb8959/go.mod h1:dbqgFATTzChvnt+ujMdZwITVAJHFtfyN1qUhDqEiIlk=
google.golang.org/grpc v1.48.0 h1:rQOsyJ/8+ufEDJd/Gdsz7HG220Mh9HAhFHRGnIjda0w=
google.golang.org/grpc v1.48.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
Expand Down
174 changes: 88 additions & 86 deletions go.mod

Large diffs are not rendered by default.

316 changes: 105 additions & 211 deletions go.sum

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions hack/go.mod.default
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ replace (
cloud.google.com/go/trace => cloud.google.com/go/trace latest
code.cloudfoundry.org/bytefmt => code.cloudfoundry.org/bytefmt latest
contrib.go.opencensus.io/exporter/aws => contrib.go.opencensus.io/exporter/aws latest
contrib.go.opencensus.io/exporter/jaeger => contrib.go.opencensus.io/exporter/jaeger latest
contrib.go.opencensus.io/exporter/prometheus => contrib.go.opencensus.io/exporter/prometheus latest
contrib.go.opencensus.io/exporter/stackdriver => contrib.go.opencensus.io/exporter/stackdriver latest
contrib.go.opencensus.io/integrations/ocsql => contrib.go.opencensus.io/integrations/ocsql latest
git.sr.ht/~sbinet/gg => git.sr.ht/~sbinet/gg latest
github.com/AdaLogics/go-fuzz-headers => github.com/AdaLogics/go-fuzz-headers latest
Expand Down Expand Up @@ -477,6 +475,7 @@ replace (
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc => go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc latest
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp => go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp latest
go.opentelemetry.io/otel => go.opentelemetry.io/otel latest
go.opentelemetry.io/otel/exporters/jaeger => go.opentelemetry.io/otel/exporters/jaeger latest
go.opentelemetry.io/otel/exporters/otlp => go.opentelemetry.io/otel/exporters/otlp latest
go.opentelemetry.io/otel/exporters/otlp/internal/retry => go.opentelemetry.io/otel/exporters/otlp/internal/retry latest
go.opentelemetry.io/otel/exporters/otlp/otlptrace => go.opentelemetry.io/otel/exporters/otlp/otlptrace latest
Expand Down
1 change: 1 addition & 0 deletions hack/license/gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func dirwalk(dir string) []string {
".html",
".json",
".key",
".kvsdb",
".lock",
".md",
".md5",
Expand Down
118 changes: 118 additions & 0 deletions internal/circuitbreaker/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -964,3 +964,121 @@ func TestWithClosedRefreshTimeout(t *testing.T) {
})
}
}

func TestWithHalfOpenErrorTripper(t *testing.T) {
// Change interface type to the type of object you are testing
type T = interface{}
type args struct {
tp Tripper
}
type want struct {
obj *T
// Uncomment this line if the option returns an error, otherwise delete it
// err error
}
type test struct {
name string
args args
want want
// Use the first line if the option returns an error. otherwise use the second line
// checkFunc func(want, *T, error) error
// checkFunc func(want, *T) error
beforeFunc func(args)
afterFunc func(args)
}

// Uncomment this block if the option returns an error, otherwise delete it
/*
defaultCheckFunc := func(w want, obj *T, err error) error {
if !errors.Is(err, w.err) {
return errors.Errorf("got_error: \"%#v\",\n\t\t\t\twant: \"%#v\"", err, w.err)
}
if !reflect.DeepEqual(obj, w.obj) {
return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", obj, w.obj)
}
return nil
}
*/

// Uncomment this block if the option do not returns an error, otherwise delete it
/*
defaultCheckFunc := func(w want, obj *T) error {
if !reflect.DeepEqual(obj, w.obj) {
return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", obj, w.obj)
}
return nil
}
*/

tests := []test{
// TODO test cases
/*
{
name: "test_case_1",
args: args {
tp: nil,
},
want: want {
obj: new(T),
},
},
*/

// TODO test cases
/*
func() test {
return test {
name: "test_case_2",
args: args {
tp: nil,
},
want: want {
obj: new(T),
},
}
}(),
*/
}

for _, tc := range tests {
test := tc
t.Run(test.name, func(tt *testing.T) {
tt.Parallel()
defer goleak.VerifyNone(tt, goleak.IgnoreCurrent())
if test.beforeFunc != nil {
test.beforeFunc(test.args)
}
if test.afterFunc != nil {
defer test.afterFunc(test.args)
}

// Uncomment this block if the option returns an error, otherwise delete it
/*
checkFunc := test.checkFunc
if test.checkFunc == nil {
checkFunc = defaultCheckFunc
}
got := WithHalfOpenErrorTripper(test.args.tp)
obj := new(T)
if err := checkFunc(test.want, obj, got(obj)); err != nil {
tt.Errorf("error = %v", err)
}
*/

// Uncomment this block if the option do not return an error, otherwise delete it
/*
checkFunc := test.checkFunc
if test.checkFunc == nil {
checkFunc = defaultCheckFunc
}
got := WithHalfOpenErrorTripper(test.args.tp)
obj := new(T)
got(obj)
if err := checkFunc(test.want, obj); err != nil {
tt.Errorf("error = %v", err)
}
*/
})
}
}
10 changes: 5 additions & 5 deletions internal/config/observability.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ package config

// Observability represents the configuration for the observability.
type Observability struct {
Enabled bool `json:"enabled" yaml:"enabled"`
Collector *Collector `json:"collector" yaml:"collector"`
Trace *Trace `json:"trace" yaml:"trace"`
Prometheus *Prometheus `json:"prometheus" yaml:"prometheus"`
Jaeger *Jaeger `json:"jaeger" yaml:"jaeger"`
Enabled bool `json:"enabled" yaml:"enabled"`
Collector *Collector `json:"collector" yaml:"collector"`
Trace *Trace `json:"trace" yaml:"trace"`
Prometheus *Prometheus `json:"prometheus" yaml:"prometheus"`
Jaeger *Jaeger `json:"jaeger" yaml:"jaeger"`
}

// Collector represents the configuration for the collector.
Expand Down
4 changes: 2 additions & 2 deletions internal/net/grpc/interceptor/server/logging/accesslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func AccessLogInterceptor() grpc.UnaryServerInterceptor {

span := trace.FromContext(ctx)
if span != nil {
traceID = span.SpanContext().TraceID.String()
traceID = span.SpanContext().TraceID().String()
}

start := time.Now()
Expand Down Expand Up @@ -108,7 +108,7 @@ func AccessLogStreamInterceptor() grpc.StreamServerInterceptor {

span := trace.FromContext(ss.Context())
if span != nil {
traceID = span.SpanContext().TraceID.String()
traceID = span.SpanContext().TraceID().String()
}

start := time.Now()
Expand Down
10 changes: 5 additions & 5 deletions internal/net/grpc/interceptor/server/trace/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,22 @@ func TracePayloadInterceptor() grpc.UnaryServerInterceptor {
}

service, method := parseMethod(info.FullMethod)
span.AddAttributes(
span.SetAttributes(
trace.StringAttribute(traceAttrGRPCKind, grpcKindUnary),
trace.StringAttribute(traceAttrGRPCService, service),
trace.StringAttribute(traceAttrGRPCMethod, method),
)

if reqj := marshalJSON(req); reqj != "" {
span.AddAttributes(
span.SetAttributes(
trace.StringAttribute(traceAttrGRPCRequestPayload, reqj),
)
}

resp, err = handler(ctx, req)

if resj := marshalJSON(resp); resj != "" {
span.AddAttributes(
span.SetAttributes(
trace.StringAttribute(traceAttrGRPCResponsePayload, resj),
)
}
Expand All @@ -97,7 +97,7 @@ func TracePayloadStreamInterceptor() grpc.StreamServerInterceptor {
}

service, method := parseMethod(info.FullMethod)
span.AddAttributes(
span.SetAttributes(
trace.StringAttribute(traceAttrGRPCKind, grpcKindStream),
trace.StringAttribute(traceAttrGRPCService, service),
trace.StringAttribute(traceAttrGRPCMethod, method),
Expand All @@ -109,7 +109,7 @@ func TracePayloadStreamInterceptor() grpc.StreamServerInterceptor {

err := handler(srv, tss)

span.AddAttributes(
span.SetAttributes(
trace.StringAttribute(traceAttrGRPCRequestPayload, tss.request),
trace.StringAttribute(traceAttrGRPCResponsePayload, tss.response),
)
Expand Down
4 changes: 2 additions & 2 deletions internal/net/grpc/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,10 @@ func withDetails(st *Status, err error, details ...interface{}) *Status {
for _, d := range v.Proto().Details {
msgs = append(msgs, proto.ToMessageV1(errdetails.AnyToErrorDetail(d)))
}
case *info.Detail:
msgs = append(msgs, errdetails.DebugInfoFromInfoDetail(v))
case info.Detail:
msgs = append(msgs, errdetails.DebugInfoFromInfoDetail(&v))
case *info.Detail:
msgs = append(msgs, errdetails.DebugInfoFromInfoDetail(v))
case proto.Message:
msgs = append(msgs, proto.ToMessageV1(v))
case *proto.Message:
Expand Down
12 changes: 9 additions & 3 deletions internal/net/grpc/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ func BidirectionalStream(ctx context.Context, stream ServerStream,
}
st, msg, err := status.ParseError(errs, codes.Internal, "failed to parse BidirectionalStream final gRPC error response")
if span != nil {
span.SetStatus(trace.FromGRPCStatus(st.Code(), msg))
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetStatus(trace.StatusError, msg)
}
return err
}
Expand Down Expand Up @@ -119,7 +121,9 @@ func BidirectionalStream(ctx context.Context, stream ServerStream,
errMap.Store(err.Error(), err)
st, msg, err := status.ParseError(err, codes.Internal, fmt.Sprintf("failed to parse BidirectionalStream id= %020d gRPC error response", id))
if sspan != nil {
sspan.SetStatus(trace.FromGRPCStatus(st.Code(), msg))
sspan.RecordError(err)
sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
sspan.SetStatus(trace.StatusError, msg)
}
if err != nil {
log.Error(err)
Expand All @@ -137,7 +141,9 @@ func BidirectionalStream(ctx context.Context, stream ServerStream,
ServingData: errdetails.Serialize(res),
})
if sspan != nil {
sspan.SetStatus(trace.FromGRPCStatus(st.Code(), msg))
sspan.RecordError(err)
sspan.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
sspan.SetStatus(trace.StatusError, msg)
}
return err
}
Expand Down
Loading

0 comments on commit 77a860e

Please sign in to comment.