diff --git a/translator/trace/zipkin/consumerdata.go b/translator/trace/zipkin/consumerdata.go new file mode 100644 index 00000000000..6495ca93f28 --- /dev/null +++ b/translator/trace/zipkin/consumerdata.go @@ -0,0 +1,29 @@ +// Copyright The OpenTelemetry Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package zipkin + +import ( + commonpb "github.com/census-instrumentation/opencensus-proto/gen-go/agent/common/v1" + resourcepb "github.com/census-instrumentation/opencensus-proto/gen-go/resource/v1" + tracepb "github.com/census-instrumentation/opencensus-proto/gen-go/trace/v1" +) + +// traceData helper struct for zipkin conversion. +// TODO: Remove this when zipkin translates directly to pdata. +type traceData struct { + Node *commonpb.Node + Resource *resourcepb.Resource + Spans []*tracepb.Span +} diff --git a/translator/trace/zipkin/zipkinv1_thrift_to_protospan.go b/translator/trace/zipkin/zipkinv1_thrift_to_protospan.go index c1b093101d1..cf7bdbf1451 100644 --- a/translator/trace/zipkin/zipkinv1_thrift_to_protospan.go +++ b/translator/trace/zipkin/zipkinv1_thrift_to_protospan.go @@ -27,12 +27,11 @@ import ( "github.com/jaegertracing/jaeger/thrift-gen/zipkincore" "google.golang.org/protobuf/types/known/timestamppb" - "go.opentelemetry.io/collector/consumer/consumerdata" tracetranslator "go.opentelemetry.io/collector/translator/trace" ) // v1ThriftBatchToOCProto converts Zipkin v1 spans to OC Proto. -func v1ThriftBatchToOCProto(zSpans []*zipkincore.Span) ([]consumerdata.TraceData, error) { +func v1ThriftBatchToOCProto(zSpans []*zipkincore.Span) ([]traceData, error) { ocSpansAndParsedAnnotations := make([]ocSpanAndParsedAnnotations, 0, len(zSpans)) for _, zSpan := range zSpans { ocSpan, parsedAnnotations := zipkinV1ThriftToOCSpan(zSpan) diff --git a/translator/trace/zipkin/zipkinv1_to_protospan.go b/translator/trace/zipkin/zipkinv1_to_protospan.go index 95beb18cdac..7d1deac464d 100644 --- a/translator/trace/zipkin/zipkinv1_to_protospan.go +++ b/translator/trace/zipkin/zipkinv1_to_protospan.go @@ -27,7 +27,6 @@ import ( "github.com/jaegertracing/jaeger/thrift-gen/zipkincore" "google.golang.org/protobuf/types/known/timestamppb" - "go.opentelemetry.io/collector/consumer/consumerdata" "go.opentelemetry.io/collector/consumer/pdata" tracetranslator "go.opentelemetry.io/collector/translator/trace" ) @@ -86,7 +85,7 @@ type binaryAnnotation struct { } // v1JSONBatchToOCProto converts a JSON blob with a list of Zipkin v1 spans to OC Proto. -func v1JSONBatchToOCProto(blob []byte, parseStringTags bool) ([]consumerdata.TraceData, error) { +func v1JSONBatchToOCProto(blob []byte, parseStringTags bool) ([]traceData, error) { var zSpans []*zipkinV1Span if err := json.Unmarshal(blob, &zSpans); err != nil { return nil, fmt.Errorf("%s: %w", msgZipkinV1JSONUnmarshalError, err) @@ -113,15 +112,15 @@ type ocSpanAndParsedAnnotations struct { parsedAnnotations *annotationParseResult } -func zipkinToOCProtoBatch(ocSpansAndParsedAnnotations []ocSpanAndParsedAnnotations) ([]consumerdata.TraceData, error) { +func zipkinToOCProtoBatch(ocSpansAndParsedAnnotations []ocSpanAndParsedAnnotations) ([]traceData, error) { // Service to batch maps the service name to the trace request with the corresponding node. - svcToTD := make(map[string]*consumerdata.TraceData) + svcToTD := make(map[string]*traceData) for _, curr := range ocSpansAndParsedAnnotations { req := getOrCreateNodeRequest(svcToTD, curr.parsedAnnotations.Endpoint) req.Spans = append(req.Spans, curr.ocSpan) } - tds := make([]consumerdata.TraceData, 0, len(svcToTD)) + tds := make([]traceData, 0, len(svcToTD)) for _, v := range svcToTD { tds = append(tds, *v) } @@ -448,7 +447,7 @@ func epochMicrosecondsToTimestamp(msecs int64) *timestamppb.Timestamp { return t } -func getOrCreateNodeRequest(m map[string]*consumerdata.TraceData, endpoint *endpoint) *consumerdata.TraceData { +func getOrCreateNodeRequest(m map[string]*traceData, endpoint *endpoint) *traceData { // this private function assumes that the caller never passes an nil endpoint nodeKey := endpoint.string() req := m[nodeKey] @@ -457,7 +456,7 @@ func getOrCreateNodeRequest(m map[string]*consumerdata.TraceData, endpoint *endp return req } - req = &consumerdata.TraceData{ + req = &traceData{ Node: &commonpb.Node{ ServiceInfo: &commonpb.ServiceInfo{Name: endpoint.ServiceName}, }, diff --git a/translator/trace/zipkin/zipkinv1_to_protospan_test.go b/translator/trace/zipkin/zipkinv1_to_protospan_test.go index 44455959187..e602462fa0f 100644 --- a/translator/trace/zipkin/zipkinv1_to_protospan_test.go +++ b/translator/trace/zipkin/zipkinv1_to_protospan_test.go @@ -31,7 +31,6 @@ import ( "google.golang.org/protobuf/testing/protocmp" "google.golang.org/protobuf/types/known/timestamppb" - "go.opentelemetry.io/collector/consumer/consumerdata" tracetranslator "go.opentelemetry.io/collector/translator/trace" ) @@ -174,8 +173,8 @@ func TestMultipleJSONV1BatchesToOCProto(t *testing.T) { err = json.Unmarshal(blob, &batches) require.NoError(t, err, "Failed to load the batches") - nodeToTraceReqs := make(map[string]*consumerdata.TraceData) - var got []consumerdata.TraceData + nodeToTraceReqs := make(map[string]*traceData) + var got []traceData for _, batch := range batches { jsonBatch, err := json.Marshal(batch) require.NoError(t, err, "Failed to marshal interface back to blob") @@ -209,7 +208,7 @@ func TestMultipleJSONV1BatchesToOCProto(t *testing.T) { } } -func sortTraceByNodeName(trace []consumerdata.TraceData) { +func sortTraceByNodeName(trace []traceData) { sort.Slice(trace, func(i, j int) bool { return trace[i].Node.ServiceInfo.Name < trace[j].Node.ServiceInfo.Name }) @@ -581,7 +580,7 @@ func TestJSONHTTPToGRPCStatusCode(t *testing.T) { // ocBatches has the OpenCensus proto batches used in the test. They are hard coded because // structs like tracepb.AttributeMap cannot be ready from JSON. -var ocBatchesFromZipkinV1 = []consumerdata.TraceData{ +var ocBatchesFromZipkinV1 = []traceData{ { Node: &commonpb.Node{ ServiceInfo: &commonpb.ServiceInfo{Name: "front-proxy"},