1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15- package tracetranslator
15+ package jaeger
1616
1717import (
1818 "encoding/base64"
19- "encoding/binary"
2019 "fmt"
2120 "reflect"
2221 "strconv"
2322 "time"
2423
25- "github.com/census-instrumentation/opencensus-service/internal"
26-
2724 commonpb "github.com/census-instrumentation/opencensus-proto/gen-go/agent/common/v1"
2825 agenttracepb "github.com/census-instrumentation/opencensus-proto/gen-go/agent/trace/v1"
2926 tracepb "github.com/census-instrumentation/opencensus-proto/gen-go/trace/v1"
3027 "github.com/jaegertracing/jaeger/thrift-gen/jaeger"
28+
29+ "github.com/census-instrumentation/opencensus-service/internal"
30+ "github.com/census-instrumentation/opencensus-service/translator/trace"
3131)
3232
33- // JaegerThriftBatchToOCProto converts a single Jaeger Thrift batch of spans to a OC proto batch.
34- func JaegerThriftBatchToOCProto (jbatch * jaeger.Batch ) (* agenttracepb.ExportTraceServiceRequest , error ) {
33+ // ThriftBatchToOCProto converts a single Jaeger Thrift batch of spans to a OC proto batch.
34+ func ThriftBatchToOCProto (jbatch * jaeger.Batch ) (* agenttracepb.ExportTraceServiceRequest , error ) {
3535 ocbatch := & agenttracepb.ExportTraceServiceRequest {
3636 Node : jProcessToOCProtoNode (jbatch .GetProcess ()),
3737 Spans : jSpansToOCProtoSpans (jbatch .GetSpans ()),
@@ -106,10 +106,10 @@ func jSpansToOCProtoSpans(jspans []*jaeger.Span) []*tracepb.Span {
106106 startTime := epochMicrosecondsAsTime (uint64 (jspan .StartTime ))
107107 _ , sKind , sStatus , sAttributes := jtagsToAttributes (jspan .Tags )
108108 span := & tracepb.Span {
109- TraceId : jTraceIDToOCProtoTraceID (jspan .TraceIdHigh , jspan .TraceIdLow ),
110- SpanId : jSpanIDToOCProtoSpanID (jspan .SpanId ),
109+ TraceId : tracetranslator . Int64TraceIDToByteTraceID (jspan .TraceIdHigh , jspan .TraceIdLow ),
110+ SpanId : tracetranslator . Int64SpanIDToByteSpanID (jspan .SpanId ),
111111 // TODO: Tracestate: Check RFC status and if is applicable,
112- ParentSpanId : jSpanIDToOCProtoSpanID (jspan .ParentSpanId ),
112+ ParentSpanId : tracetranslator . Int64SpanIDToByteSpanID (jspan .ParentSpanId ),
113113 Name : strToTruncatableString (jspan .OperationName ),
114114 Kind : sKind ,
115115 StartTime : internal .TimeToTimestamp (startTime ),
@@ -171,8 +171,8 @@ func jReferencesToOCProtoLinks(jrefs []*jaeger.SpanRef) *tracepb.Span_Links {
171171 }
172172
173173 link := & tracepb.Span_Link {
174- TraceId : jTraceIDToOCProtoTraceID (jref .TraceIdHigh , jref .TraceIdLow ),
175- SpanId : jSpanIDToOCProtoSpanID (jref .SpanId ),
174+ TraceId : tracetranslator . Int64TraceIDToByteTraceID (jref .TraceIdHigh , jref .TraceIdLow ),
175+ SpanId : tracetranslator . Int64SpanIDToByteSpanID (jref .SpanId ),
176176 Type : linkType ,
177177 }
178178 links = append (links , link )
@@ -181,25 +181,6 @@ func jReferencesToOCProtoLinks(jrefs []*jaeger.SpanRef) *tracepb.Span_Links {
181181 return & tracepb.Span_Links {Link : links }
182182}
183183
184- func jTraceIDToOCProtoTraceID (high , low int64 ) []byte {
185- if high == 0 && low == 0 {
186- return nil
187- }
188- traceID := make ([]byte , 16 )
189- binary .BigEndian .PutUint64 (traceID [:8 ], uint64 (high ))
190- binary .BigEndian .PutUint64 (traceID [8 :], uint64 (low ))
191- return traceID
192- }
193-
194- func jSpanIDToOCProtoSpanID (id int64 ) []byte {
195- if id == 0 {
196- return nil
197- }
198- spanID := make ([]byte , 8 )
199- binary .BigEndian .PutUint64 (spanID , uint64 (id ))
200- return spanID
201- }
202-
203184func jtagsToAttributes (tags []* jaeger.Tag ) (string , tracepb.Span_SpanKind , * tracepb.Status , * tracepb.Span_Attributes ) {
204185 if tags == nil {
205186 return "" , tracepb .Span_SPAN_KIND_UNSPECIFIED , nil , nil
0 commit comments