From e8e0a6b6603ac225db86485048e4d952ed154e2e Mon Sep 17 00:00:00 2001 From: Yuri Shkuro Date: Tue, 31 May 2022 12:14:46 -0400 Subject: [PATCH] Fix custom gogo codec to allow OTLP data Signed-off-by: Yuri Shkuro --- pkg/gogocodec/codec.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pkg/gogocodec/codec.go b/pkg/gogocodec/codec.go index e16e62304c0..bc3a468f577 100644 --- a/pkg/gogocodec/codec.go +++ b/pkg/gogocodec/codec.go @@ -20,20 +20,23 @@ import ( gogoproto "github.com/gogo/protobuf/proto" "google.golang.org/grpc/encoding" - "google.golang.org/protobuf/proto" + "google.golang.org/grpc/encoding/proto" ) const jaegerProtoGenPkgPath = "github.com/jaegertracing/jaeger/proto-gen" const jaegerModelPkgPath = "github.com/jaegertracing/jaeger/model" +var defaultCodec encoding.Codec + func init() { + defaultCodec = encoding.GetCodec(proto.Name) + defaultCodec.Name() // ensure it's not nil encoding.RegisterCodec(newCodec()) } // gogoCodec forces the use of gogo proto marshalling/unmarshalling for // Jaeger proto types (package jaeger/gen-proto). -type gogoCodec struct { -} +type gogoCodec struct{} var _ encoding.Codec = (*gogoCodec)(nil) @@ -43,7 +46,7 @@ func newCodec() *gogoCodec { // Name implements encoding.Codec func (c *gogoCodec) Name() string { - return "proto" + return proto.Name } // Marshal implements encoding.Codec @@ -54,7 +57,7 @@ func (c *gogoCodec) Marshal(v interface{}) ([]byte, error) { if useGogo(elem) { return gogoproto.Marshal(v.(gogoproto.Message)) } - return proto.Marshal(v.(proto.Message)) + return defaultCodec.Marshal(v) } // Unmarshal implements encoding.Codec @@ -65,7 +68,7 @@ func (c *gogoCodec) Unmarshal(data []byte, v interface{}) error { if useGogo(elem) { return gogoproto.Unmarshal(data, v.(gogoproto.Message)) } - return proto.Unmarshal(data, v.(proto.Message)) + return defaultCodec.Unmarshal(data, v) } func useGogo(t reflect.Type) bool {