Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic from gogo-codec when receiving OTLP over gRPC #3719

Merged
merged 1 commit into from
May 31, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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