@@ -21,7 +21,6 @@ import (
21
21
"github.com/gogo/protobuf/proto"
22
22
spb "google.golang.org/genproto/googleapis/rpc/status"
23
23
24
- "go.opentelemetry.io/collector/model/otlp"
25
24
"go.opentelemetry.io/collector/model/otlpgrpc"
26
25
)
27
26
@@ -31,18 +30,8 @@ const (
31
30
)
32
31
33
32
var (
34
- pbEncoder = & protoEncoder {}
35
- jsEncoder = & jsonEncoder {}
36
-
37
- tracesPbUnmarshaler = otlp .NewProtobufTracesUnmarshaler ()
38
- tracesJSONUnmarshaler = otlp .NewJSONTracesUnmarshaler ()
39
-
40
- metricsPbUnmarshaler = otlp .NewProtobufMetricsUnmarshaler ()
41
- metricsJSONUnmarshaler = otlp .NewJSONMetricsUnmarshaler ()
42
-
43
- logsPbUnmarshaler = otlp .NewProtobufLogsUnmarshaler ()
44
- logsJSONUnmarshaler = otlp .NewJSONLogsUnmarshaler ()
45
-
33
+ pbEncoder = & protoEncoder {}
34
+ jsEncoder = & jsonEncoder {}
46
35
jsonMarshaler = & jsonpb.Marshaler {}
47
36
)
48
37
@@ -63,33 +52,15 @@ type encoder interface {
63
52
type protoEncoder struct {}
64
53
65
54
func (protoEncoder ) unmarshalTracesRequest (buf []byte ) (otlpgrpc.TracesRequest , error ) {
66
- td , err := tracesPbUnmarshaler .UnmarshalTraces (buf )
67
- if err != nil {
68
- return otlpgrpc.TracesRequest {}, err
69
- }
70
- req := otlpgrpc .NewTracesRequest ()
71
- req .SetTraces (td )
72
- return req , nil
55
+ return otlpgrpc .UnmarshalTracesRequest (buf )
73
56
}
74
57
75
58
func (protoEncoder ) unmarshalMetricsRequest (buf []byte ) (otlpgrpc.MetricsRequest , error ) {
76
- td , err := metricsPbUnmarshaler .UnmarshalMetrics (buf )
77
- if err != nil {
78
- return otlpgrpc.MetricsRequest {}, err
79
- }
80
- req := otlpgrpc .NewMetricsRequest ()
81
- req .SetMetrics (td )
82
- return req , nil
59
+ return otlpgrpc .UnmarshalMetricsRequest (buf )
83
60
}
84
61
85
62
func (protoEncoder ) unmarshalLogsRequest (buf []byte ) (otlpgrpc.LogsRequest , error ) {
86
- ld , err := logsPbUnmarshaler .UnmarshalLogs (buf )
87
- if err != nil {
88
- return otlpgrpc.LogsRequest {}, err
89
- }
90
- req := otlpgrpc .NewLogsRequest ()
91
- req .SetLogs (ld )
92
- return req , nil
63
+ return otlpgrpc .UnmarshalLogsRequest (buf )
93
64
}
94
65
95
66
func (protoEncoder ) marshalTracesResponse (resp otlpgrpc.TracesResponse ) ([]byte , error ) {
@@ -115,33 +86,15 @@ func (protoEncoder) contentType() string {
115
86
type jsonEncoder struct {}
116
87
117
88
func (jsonEncoder ) unmarshalTracesRequest (buf []byte ) (otlpgrpc.TracesRequest , error ) {
118
- td , err := tracesJSONUnmarshaler .UnmarshalTraces (buf )
119
- if err != nil {
120
- return otlpgrpc.TracesRequest {}, err
121
- }
122
- req := otlpgrpc .NewTracesRequest ()
123
- req .SetTraces (td )
124
- return req , nil
89
+ return otlpgrpc .UnmarshalJSONTracesRequest (buf )
125
90
}
126
91
127
92
func (jsonEncoder ) unmarshalMetricsRequest (buf []byte ) (otlpgrpc.MetricsRequest , error ) {
128
- td , err := metricsJSONUnmarshaler .UnmarshalMetrics (buf )
129
- if err != nil {
130
- return otlpgrpc.MetricsRequest {}, err
131
- }
132
- req := otlpgrpc .NewMetricsRequest ()
133
- req .SetMetrics (td )
134
- return req , nil
93
+ return otlpgrpc .UnmarshalJSONMetricsRequest (buf )
135
94
}
136
95
137
96
func (jsonEncoder ) unmarshalLogsRequest (buf []byte ) (otlpgrpc.LogsRequest , error ) {
138
- ld , err := logsJSONUnmarshaler .UnmarshalLogs (buf )
139
- if err != nil {
140
- return otlpgrpc.LogsRequest {}, err
141
- }
142
- req := otlpgrpc .NewLogsRequest ()
143
- req .SetLogs (ld )
144
- return req , nil
97
+ return otlpgrpc .UnmarshalJSONLogsRequest (buf )
145
98
}
146
99
147
100
func (jsonEncoder ) marshalTracesResponse (resp otlpgrpc.TracesResponse ) ([]byte , error ) {
0 commit comments