Skip to content

Commit

Permalink
Fix custom gogo codec to allow OTLP data (#3719)
Browse files Browse the repository at this point in the history
Signed-off-by: Yuri Shkuro <github@ysh.us>
  • Loading branch information
yurishkuro committed May 31, 2022
1 parent 557ff71 commit 12c72e0
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pkg/gogocodec/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 12c72e0

Please sign in to comment.