diff --git a/exporter/zipkinexporter/go.mod b/exporter/zipkinexporter/go.mod index 708600db7caf8..1cf960db7ed56 100644 --- a/exporter/zipkinexporter/go.mod +++ b/exporter/zipkinexporter/go.mod @@ -15,13 +15,11 @@ require ( require ( github.com/apache/thrift v0.17.0 // indirect github.com/cenkalti/backoff/v4 v4.1.3 // indirect - github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/felixge/httpsnoop v1.0.3 // indirect github.com/go-logr/logr v1.2.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/jaegertracing/jaeger v1.38.0 // indirect @@ -34,7 +32,6 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.61.0 // indirect - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/opencensus v0.61.0 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rs/cors v1.8.2 // indirect diff --git a/exporter/zipkinexporter/go.sum b/exporter/zipkinexporter/go.sum index 5dac64058d288..28db9e5e3ffe7 100644 --- a/exporter/zipkinexporter/go.sum +++ b/exporter/zipkinexporter/go.sum @@ -34,8 +34,6 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB github.com/cenkalti/backoff/v4 v4.1.3 h1:cFAlzYUlVYDysBEH2T5hyJZMh3+5+WCBvSnK6Q8UtC4= github.com/cenkalti/backoff/v4 v4.1.3/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/census-instrumentation/opencensus-proto v0.4.1 h1:iKLQ0xPNFxR/2hzXZMrBo8f1j86j5WHzznCCQxV/b8g= -github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= @@ -92,7 +90,6 @@ github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69 github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= -github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -130,9 +127,7 @@ github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7 github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= -github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 h1:lLT7ZLSzGLI08vc9cpd+tYmNWjdKDqyr/2L+f6U12Fk= github.com/hashicorp/consul/api v1.13.0/go.mod h1:ZlVrynguJKcYr54zGaDbaL3fOvKC9m72FhPvA8T35KQ= github.com/hashicorp/consul/sdk v0.8.0/go.mod h1:GBvyrGALthsZObzUGsfgHZQDXjg4lOjagTIwIR1vPms= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= diff --git a/pkg/translator/zipkin/go.mod b/pkg/translator/zipkin/go.mod index d84cca6ccc91d..4ac16d61bc594 100644 --- a/pkg/translator/zipkin/go.mod +++ b/pkg/translator/zipkin/go.mod @@ -3,24 +3,18 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/ go 1.18 require ( - github.com/census-instrumentation/opencensus-proto v0.4.1 - github.com/google/go-cmp v0.5.9 github.com/jaegertracing/jaeger v1.38.0 github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.61.0 - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/opencensus v0.61.0 github.com/openzipkin/zipkin-go v0.4.0 github.com/stretchr/testify v1.8.0 go.opentelemetry.io/collector/pdata v0.61.0 go.opentelemetry.io/collector/semconv v0.61.0 - google.golang.org/protobuf v1.28.1 - ) require ( github.com/apache/thrift v0.17.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect @@ -29,7 +23,6 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect github.com/uber/jaeger-lib v2.4.1+incompatible // indirect - go.opencensus.io v0.23.0 // indirect go.uber.org/atomic v1.10.0 // indirect go.uber.org/multierr v1.8.0 // indirect go.uber.org/zap v1.23.0 // indirect @@ -38,9 +31,8 @@ require ( golang.org/x/text v0.3.7 // indirect google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc // indirect google.golang.org/grpc v1.49.0 // indirect + google.golang.org/protobuf v1.28.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal => ../../../internal/coreinternal - -replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/opencensus => ../../../pkg/translator/opencensus diff --git a/pkg/translator/zipkin/go.sum b/pkg/translator/zipkin/go.sum index db27253f98228..0ba7ade70bb2e 100644 --- a/pkg/translator/zipkin/go.sum +++ b/pkg/translator/zipkin/go.sum @@ -9,8 +9,6 @@ github.com/apache/thrift v0.17.0 h1:cMd2aj52n+8VoAtvSvLn4kDC3aZ6IAkBuqWQ2IDu7wo= github.com/apache/thrift v0.17.0/go.mod h1:OLxhMRJxomX+1I/KUw03qoV3mMz16BwaKI+d4fPBx7Q= github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/census-instrumentation/opencensus-proto v0.4.1 h1:iKLQ0xPNFxR/2hzXZMrBo8f1j86j5WHzznCCQxV/b8g= -github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= @@ -39,9 +37,6 @@ github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg78 github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= -github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -63,19 +58,15 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= -github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 h1:lLT7ZLSzGLI08vc9cpd+tYmNWjdKDqyr/2L+f6U12Fk= github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/jaegertracing/jaeger v1.38.0 h1:rDQ36TnSxUX4gTskMQzEdpieS0BGYdfXXnUJmGnNMGw= @@ -149,8 +140,6 @@ github.com/xdg-go/scram v1.0.2/go.mod h1:1WAq6h33pAW+iRreB34OORO2Nf7qel3VV3fjBj+ github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -go.opencensus.io v0.23.0 h1:gqCw0LfLxScz8irSi8exQc7fyQ0fKQU/qnC/X8+V/1M= -go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= go.opentelemetry.io/collector/pdata v0.61.0 h1:jPUReUpR/D1xsigfRxyXA7cYMnXfnK+D7z61W6F9moo= go.opentelemetry.io/collector/pdata v0.61.0/go.mod h1:0hqgNMRneVXaLNelv3q0XKJbyBW9aMDwyC15pKd30+E= go.opentelemetry.io/collector/semconv v0.61.0 h1:RMrzDugNuFsUjppvvNZWiWcNneogZ3Zo4idWyIUWR9k= @@ -188,7 +177,6 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.0.0-20210917221730-978cfadd31cf/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= @@ -251,7 +239,6 @@ google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyac google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0= -google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU= google.golang.org/grpc v1.41.0/go.mod h1:U3l9uK9J0sini8mHphKoXyaqDA/8VyGnDee1zzIUK6k= google.golang.org/grpc v1.49.0 h1:WTLtQzmQori5FUH25Pq4WT22oCsv8USpQ+F6rqtsmxw= diff --git a/pkg/translator/zipkin/zipkinv1/consumerdata.go b/pkg/translator/zipkin/zipkinv1/consumerdata.go deleted file mode 100644 index ce9ed51379090..0000000000000 --- a/pkg/translator/zipkin/zipkinv1/consumerdata.go +++ /dev/null @@ -1,29 +0,0 @@ -// 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 zipkinv1 // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/zipkin/zipkinv1" - -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/pkg/translator/zipkin/zipkinv1/grpc_http_mapper.go b/pkg/translator/zipkin/zipkinv1/grpc_http_mapper.go deleted file mode 100644 index 161ab2fa3bd51..0000000000000 --- a/pkg/translator/zipkin/zipkinv1/grpc_http_mapper.go +++ /dev/null @@ -1,65 +0,0 @@ -// 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 zipkinv1 // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/zipkin/zipkinv1" - -// https://github.com/googleapis/googleapis/blob/bee79fbe03254a35db125dc6d2f1e9b752b390fe/google/rpc/code.proto#L33-L186 -const ( - ocOK = 0 - ocCancelled = 1 - ocUnknown = 2 - ocInvalidArgument = 3 - ocDeadlineExceeded = 4 - ocNotFound = 5 - // ocAlreadyExists = 6 - ocPermissionDenied = 7 - ocResourceExhausted = 8 - // ocFailedPrecondition = 9 - // ocAborted = 10 - // ocOutOfRange = 11 - ocUnimplemented = 12 - ocInternal = 13 - ocUnavailable = 14 - // ocDataLoss = 15 - ocUnauthenticated = 16 -) - -var httpToOCCodeMap = map[int32]int32{ - 401: ocUnauthenticated, - 403: ocPermissionDenied, - 404: ocNotFound, - 429: ocResourceExhausted, - 499: ocCancelled, - 501: ocUnimplemented, - 503: ocUnavailable, - 504: ocDeadlineExceeded, -} - -// ocStatusCodeFromHTTP takes an HTTP status code and return the appropriate OpenTelemetry status code -// See: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/data-http.md -func ocStatusCodeFromHTTP(code int32) int32 { - if code >= 100 && code < 400 { - return ocOK - } - if c, ok := httpToOCCodeMap[code]; ok { - return c - } - if code >= 400 && code < 500 { - return ocInvalidArgument - } - if code >= 500 && code < 600 { - return ocInternal - } - return ocUnknown -} diff --git a/pkg/translator/zipkin/zipkinv1/grpc_http_mapper_test.go b/pkg/translator/zipkin/zipkinv1/grpc_http_mapper_test.go deleted file mode 100644 index 3b5fdde1beba0..0000000000000 --- a/pkg/translator/zipkin/zipkinv1/grpc_http_mapper_test.go +++ /dev/null @@ -1,28 +0,0 @@ -// 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 zipkinv1 - -import ( - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestOTStatusFromHTTPStatus(t *testing.T) { - for httpStatus := int32(100); httpStatus <= 604; httpStatus++ { - otelStatus := ocStatusCodeFromHTTP(httpStatus) - assert.True(t, otelStatus >= ocOK && otelStatus <= ocUnauthenticated) - } -} diff --git a/pkg/translator/zipkin/zipkinv1/json.go b/pkg/translator/zipkin/zipkinv1/json.go index 70fa4e3dba186..7e2a4070ce4a0 100644 --- a/pkg/translator/zipkin/zipkinv1/json.go +++ b/pkg/translator/zipkin/zipkinv1/json.go @@ -15,6 +15,7 @@ package zipkinv1 // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/zipkin/zipkinv1" import ( + "encoding/hex" "encoding/json" "errors" "fmt" @@ -22,15 +23,11 @@ import ( "strconv" "time" - commonpb "github.com/census-instrumentation/opencensus-proto/gen-go/agent/common/v1" - tracepb "github.com/census-instrumentation/opencensus-proto/gen-go/trace/v1" "github.com/jaegertracing/jaeger/thrift-gen/zipkincore" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/ptrace" - "google.golang.org/protobuf/types/known/timestamppb" + conventions "go.opentelemetry.io/collector/semconv/v1.6.1" - "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/idutils" - "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/tracetranslator" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/zipkin/internal/zipkin" ) @@ -42,10 +39,8 @@ var ( msgZipkinV1ParentIDError = "zipkinV1 span parentId" // Generic hex to ID conversion errors errHexTraceIDWrongLen = errors.New("hex traceId span has wrong length (expected 16 or 32)") - errHexTraceIDParsing = errors.New("failed to parse hex traceId") errHexTraceIDZero = errors.New("traceId is zero") errHexIDWrongLen = errors.New("hex Id has wrong length (expected 16)") - errHexIDParsing = errors.New("failed to parse hex Id") errHexIDZero = errors.New("ID is zero") ) @@ -56,11 +51,7 @@ type jsonUnmarshaler struct { // UnmarshalTraces from JSON bytes. func (j jsonUnmarshaler) UnmarshalTraces(buf []byte) (ptrace.Traces, error) { - tds, err := v1JSONBatchToOCProto(buf, j.ParseStringTags) - if err != nil { - return ptrace.Traces{}, err - } - return toTraces(tds) + return jsonBatchToTraces(buf, j.ParseStringTags) } // NewJSONTracesUnmarshaler returns an unmarshaler for Zipkin JSON. @@ -70,9 +61,9 @@ func NewJSONTracesUnmarshaler(parseStringTags bool) ptrace.Unmarshaler { // Trace translation from Zipkin V1 is a bit of special case since there is no model // defined in golang for Zipkin V1 spans and there is no need to define one here, given -// that the zipkinV1Span defined below is as defined at: +// that the jsonSpan defined below is as defined at: // https://zipkin.io/zipkin-api/zipkin-api.yaml -type zipkinV1Span struct { +type jsonSpan struct { TraceID string `json:"traceId"` Name string `json:"name,omitempty"` ParentID string `json:"parentId,omitempty"` @@ -84,7 +75,7 @@ type zipkinV1Span struct { BinaryAnnotations []*binaryAnnotation `json:"binaryAnnotations,omitempty"` } -// endpoint structure used by zipkinV1Span. +// endpoint structure used by jsonSpan. type endpoint struct { ServiceName string `json:"serviceName"` IPv4 string `json:"ipv4"` @@ -92,229 +83,158 @@ type endpoint struct { Port int32 `json:"port"` } -// annotation struct used by zipkinV1Span. +// annotation struct used by jsonSpan. type annotation struct { Timestamp int64 `json:"timestamp"` Value string `json:"value"` Endpoint *endpoint `json:"endpoint"` } -// binaryAnnotation used by zipkinV1Span. +// binaryAnnotation used by jsonSpan. type binaryAnnotation struct { Key string `json:"key"` Value string `json:"value"` Endpoint *endpoint `json:"endpoint"` } -// v1JSONBatchToOCProto converts a JSON blob with a list of Zipkin v1 spans to OC Proto. -func v1JSONBatchToOCProto(blob []byte, parseStringTags bool) ([]traceData, error) { - var zSpans []*zipkinV1Span +// jsonBatchToTraces converts a JSON blob with a list of Zipkin v1 spans to ptrace.Traces. +func jsonBatchToTraces(blob []byte, parseStringTags bool) (ptrace.Traces, error) { + var zSpans []*jsonSpan if err := json.Unmarshal(blob, &zSpans); err != nil { - return nil, fmt.Errorf("%s: %w", msgZipkinV1JSONUnmarshalError, err) + return ptrace.Traces{}, fmt.Errorf("%s: %w", msgZipkinV1JSONUnmarshalError, err) } - ocSpansAndParsedAnnotations := make([]ocSpanAndParsedAnnotations, 0, len(zSpans)) + spanAndEndpoints := make([]spanAndEndpoint, 0, len(zSpans)) for _, zSpan := range zSpans { - ocSpan, parsedAnnotations, err := zipkinV1ToOCSpan(zSpan, parseStringTags) + sae, err := jsonToSpanAndEndpoint(zSpan, parseStringTags) if err != nil { // error from internal package function, it already wraps the error to give better context. - return nil, err + return ptrace.Traces{}, err } - ocSpansAndParsedAnnotations = append(ocSpansAndParsedAnnotations, ocSpanAndParsedAnnotations{ - ocSpan: ocSpan, - parsedAnnotations: parsedAnnotations, - }) + spanAndEndpoints = append(spanAndEndpoints, sae) } - return zipkinToOCProtoBatch(ocSpansAndParsedAnnotations) + return zipkinToTraces(spanAndEndpoints) } -type ocSpanAndParsedAnnotations struct { - ocSpan *tracepb.Span - parsedAnnotations *annotationParseResult +type spanAndEndpoint struct { + span ptrace.Span + endpoint *endpoint } -func zipkinToOCProtoBatch(ocSpansAndParsedAnnotations []ocSpanAndParsedAnnotations) ([]traceData, error) { +func zipkinToTraces(spanAndEndpoints []spanAndEndpoint) (ptrace.Traces, error) { + td := ptrace.NewTraces() // Service to batch maps the service name to the trace request with the corresponding node. - svcToTD := make(map[string]*traceData) - for _, curr := range ocSpansAndParsedAnnotations { - req := getOrCreateNodeRequest(svcToTD, curr.parsedAnnotations.Endpoint) - req.Spans = append(req.Spans, curr.ocSpan) - } - - tds := make([]traceData, 0, len(svcToTD)) - for _, v := range svcToTD { - tds = append(tds, *v) + svcToTD := make(map[string]ptrace.SpanSlice) + for _, curr := range spanAndEndpoints { + ss := getOrCreateNodeRequest(svcToTD, td, curr.endpoint) + curr.span.MoveTo(ss.AppendEmpty()) } - return tds, nil + return td, nil } -func zipkinV1ToOCSpan(zSpan *zipkinV1Span, parseStringTags bool) (*tracepb.Span, *annotationParseResult, error) { - traceID, err := hexTraceIDToOCTraceID(zSpan.TraceID) +func jsonToSpanAndEndpoint(zSpan *jsonSpan, parseStringTags bool) (spanAndEndpoint, error) { + traceID, err := hexToTraceID(zSpan.TraceID) if err != nil { - return nil, nil, fmt.Errorf("%s: %w", msgZipkinV1TraceIDError, err) + return spanAndEndpoint{}, fmt.Errorf("%s: %w", msgZipkinV1TraceIDError, err) } - spanID, err := hexIDToOCID(zSpan.ID) + spanID, err := hexToSpanID(zSpan.ID) if err != nil { - return nil, nil, fmt.Errorf("%s: %w", msgZipkinV1SpanIDError, err) + return spanAndEndpoint{}, fmt.Errorf("%s: %w", msgZipkinV1SpanIDError, err) } - var parentID []byte + var parentID [8]byte if zSpan.ParentID != "" { - id, err := hexIDToOCID(zSpan.ParentID) + parentID, err = hexToSpanID(zSpan.ParentID) if err != nil { - return nil, nil, fmt.Errorf("%s: %w", msgZipkinV1ParentIDError, err) + return spanAndEndpoint{}, fmt.Errorf("%s: %w", msgZipkinV1ParentIDError, err) } - parentID = id - } - - parsedAnnotations := parseZipkinV1Annotations(zSpan.Annotations) - attributes, ocStatus, localComponent := zipkinV1BinAnnotationsToOCAttributes(zSpan.BinaryAnnotations, parseStringTags) - if parsedAnnotations.Endpoint.ServiceName == unknownServiceName && localComponent != "" { - parsedAnnotations.Endpoint.ServiceName = localComponent - } - var startTime, endTime *timestamppb.Timestamp - if zSpan.Timestamp == 0 { - startTime = parsedAnnotations.EarlyAnnotationTime - endTime = parsedAnnotations.LateAnnotationTime - } else { - startTime = epochMicrosecondsToTimestamp(zSpan.Timestamp) - endTime = epochMicrosecondsToTimestamp(zSpan.Timestamp + zSpan.Duration) } - ocSpan := &tracepb.Span{ - TraceId: traceID, - SpanId: spanID, - ParentSpanId: parentID, - Status: ocStatus, - Kind: parsedAnnotations.Kind, - TimeEvents: parsedAnnotations.TimeEvents, - StartTime: startTime, - EndTime: endTime, - Attributes: attributes, + span, edpt := jsonAnnotationsToSpanAndEndpoint(zSpan.Annotations) + localComponent := jsonBinAnnotationsToSpanAttributes(span, zSpan.BinaryAnnotations, parseStringTags) + if edpt.ServiceName == unknownServiceName && localComponent != "" { + edpt.ServiceName = localComponent } - - if zSpan.Name != "" { - ocSpan.Name = &tracepb.TruncatableString{Value: zSpan.Name} + if zSpan.Timestamp != 0 { + span.SetStartTimestamp(epochMicrosecondsToTimestamp(zSpan.Timestamp)) + span.SetEndTimestamp(epochMicrosecondsToTimestamp(zSpan.Timestamp + zSpan.Duration)) } - setSpanKind(ocSpan, parsedAnnotations.Kind, parsedAnnotations.ExtendedKind) - setTimestampsIfUnset(ocSpan) + span.SetName(zSpan.Name) + span.SetTraceID(traceID) + span.SetSpanID(spanID) + span.SetParentSpanID(parentID) + setTimestampsIfUnset(span) - return ocSpan, parsedAnnotations, nil + return spanAndEndpoint{span: span, endpoint: edpt}, nil } -func setSpanKind(ocSpan *tracepb.Span, kind tracepb.Span_SpanKind, extendedKind tracetranslator.OpenTracingSpanKind) { - if kind == tracepb.Span_SPAN_KIND_UNSPECIFIED && - extendedKind != tracetranslator.OpenTracingSpanKindUnspecified { - // Span kind has no equivalent in OC, so we cannot represent it in the Kind field. - // We will set a TagSpanKind attribute in the span. This will successfully transfer - // in the pipeline until it reaches the exporter which is responsible for - // reverse translation. - if ocSpan.Attributes == nil { - ocSpan.Attributes = &tracepb.Span_Attributes{} - } - if ocSpan.Attributes.AttributeMap == nil { - ocSpan.Attributes.AttributeMap = make(map[string]*tracepb.AttributeValue, 1) - } - ocSpan.Attributes.AttributeMap[tracetranslator.TagSpanKind] = - &tracepb.AttributeValue{Value: &tracepb.AttributeValue_StringValue{ - StringValue: &tracepb.TruncatableString{Value: string(extendedKind)}, - }} - } -} - -func zipkinV1BinAnnotationsToOCAttributes(binAnnotations []*binaryAnnotation, parseStringTags bool) (attributes *tracepb.Span_Attributes, status *tracepb.Status, fallbackServiceName string) { +func jsonBinAnnotationsToSpanAttributes(span ptrace.Span, binAnnotations []*binaryAnnotation, parseStringTags bool) string { + var fallbackServiceName string if len(binAnnotations) == 0 { - return nil, nil, "" + return fallbackServiceName } sMapper := &statusMapper{} var localComponent string - attributeMap := make(map[string]*tracepb.AttributeValue) for _, binAnnotation := range binAnnotations { if binAnnotation.Endpoint != nil && binAnnotation.Endpoint.ServiceName != "" { fallbackServiceName = binAnnotation.Endpoint.ServiceName } - pbAttrib := parseAnnotationValue(binAnnotation.Value, parseStringTags) - key := binAnnotation.Key - if key == zipkincore.LOCAL_COMPONENT { // TODO: (@pjanotti) add reference to OpenTracing and change related tags to use them key = "component" localComponent = binAnnotation.Value } - if drop := sMapper.fromAttribute(key, pbAttrib); drop { + val := parseAnnotationValue(binAnnotation.Value, parseStringTags) + if drop := sMapper.fromAttribute(key, val); drop { continue } - attributeMap[key] = pbAttrib - } - - status = sMapper.ocStatus() - - if len(attributeMap) == 0 { - return nil, status, "" + val.CopyTo(span.Attributes().PutEmpty(key)) } if fallbackServiceName == "" { fallbackServiceName = localComponent } - attributes = &tracepb.Span_Attributes{ - AttributeMap: attributeMap, - } - - return attributes, status, fallbackServiceName + sMapper.status(span.Status()) + return fallbackServiceName } -func parseAnnotationValue(value string, parseStringTags bool) *tracepb.AttributeValue { - pbAttrib := &tracepb.AttributeValue{} - +func parseAnnotationValue(value string, parseStringTags bool) pcommon.Value { if parseStringTags { switch zipkin.DetermineValueType(value) { case pcommon.ValueTypeInt: iValue, _ := strconv.ParseInt(value, 10, 64) - pbAttrib.Value = &tracepb.AttributeValue_IntValue{IntValue: iValue} + return pcommon.NewValueInt(iValue) case pcommon.ValueTypeDouble: fValue, _ := strconv.ParseFloat(value, 64) - pbAttrib.Value = &tracepb.AttributeValue_DoubleValue{DoubleValue: fValue} + return pcommon.NewValueDouble(fValue) case pcommon.ValueTypeBool: bValue, _ := strconv.ParseBool(value) - pbAttrib.Value = &tracepb.AttributeValue_BoolValue{BoolValue: bValue} + return pcommon.NewValueBool(bValue) default: - pbAttrib.Value = &tracepb.AttributeValue_StringValue{StringValue: &tracepb.TruncatableString{Value: value}} + return pcommon.NewValueString(value) } - } else { - pbAttrib.Value = &tracepb.AttributeValue_StringValue{StringValue: &tracepb.TruncatableString{Value: value}} } - return pbAttrib -} - -// annotationParseResult stores the results of examining the original annotations, -// this way multiple passes on the annotations are not needed. -type annotationParseResult struct { - Endpoint *endpoint - TimeEvents *tracepb.Span_TimeEvents - Kind tracepb.Span_SpanKind - ExtendedKind tracetranslator.OpenTracingSpanKind - EarlyAnnotationTime *timestamppb.Timestamp - LateAnnotationTime *timestamppb.Timestamp + return pcommon.NewValueString(value) } // Unknown service name works both as a default value and a flag to indicate that a valid endpoint was found. const unknownServiceName = "unknown-service" -func parseZipkinV1Annotations(annotations []*annotation) *annotationParseResult { - // Zipkin V1 annotations have a timestamp so they fit well with OC TimeEvent +func jsonAnnotationsToSpanAndEndpoint(annotations []*annotation) (ptrace.Span, *endpoint) { + // Zipkin V1 annotations have a timestamp so they fit well with ptrace.SpanEvent earlyAnnotationTimestamp := int64(math.MaxInt64) lateAnnotationTimestamp := int64(math.MinInt64) - res := &annotationParseResult{} - timeEvents := make([]*tracepb.Span_TimeEvent, 0, len(annotations)) + var edpt *endpoint + span := ptrace.NewSpan() // We want to set the span kind from the first annotation that contains information // about the span kind. This flags ensures we only set span kind once from @@ -340,8 +260,8 @@ func parseZipkinV1Annotations(annotations []*annotation) *annotationParseResult // Populate the endpoint if it is not already populated and current endpoint // has a service name and span kind. - if res.Endpoint == nil && endpointName != unknownServiceName && annotationHasSpanKind { - res.Endpoint = currAnnotation.Endpoint + if edpt == nil && endpointName != unknownServiceName && annotationHasSpanKind { + edpt = currAnnotation.Endpoint } if !spanKindIsSet && annotationHasSpanKind { @@ -350,21 +270,13 @@ func parseZipkinV1Annotations(annotations []*annotation) *annotationParseResult // pair of internal fields. switch currAnnotation.Value { case "cs", "cr": - res.Kind = tracepb.Span_CLIENT - res.ExtendedKind = tracetranslator.OpenTracingSpanKindClient - + span.SetKind(ptrace.SpanKindClient) case "ms": - // "ms" and "mr" are PRODUCER and CONSUMER kinds which have no equivalent - // representation in OC. We keep res.Kind unspecified and will use - // ExtendedKind for translations. - res.ExtendedKind = tracetranslator.OpenTracingSpanKindProducer - + span.SetKind(ptrace.SpanKindProducer) case "mr": - res.ExtendedKind = tracetranslator.OpenTracingSpanKindConsumer - + span.SetKind(ptrace.SpanKindConsumer) case "ss", "sr": - res.Kind = tracepb.Span_SERVER - res.ExtendedKind = tracetranslator.OpenTracingSpanKindServer + span.SetKind(ptrace.SpanKindServer) } // Remember that we populated the span kind, so that we don't do it again. @@ -374,11 +286,11 @@ func parseZipkinV1Annotations(annotations []*annotation) *annotationParseResult ts := epochMicrosecondsToTimestamp(currAnnotation.Timestamp) if currAnnotation.Timestamp < earlyAnnotationTimestamp { earlyAnnotationTimestamp = currAnnotation.Timestamp - res.EarlyAnnotationTime = ts + span.SetStartTimestamp(ts) } if currAnnotation.Timestamp > lateAnnotationTimestamp { lateAnnotationTimestamp = currAnnotation.Timestamp - res.LateAnnotationTime = ts + span.SetEndTimestamp(ts) } if annotationHasSpanKind { @@ -386,153 +298,114 @@ func parseZipkinV1Annotations(annotations []*annotation) *annotationParseResult continue } - timeEvent := &tracepb.Span_TimeEvent{ - Time: ts, - // More economically we could use a tracepb.Span_TimeEvent_Message, however, it will mean the loss of some information. - // Using the more expensive annotation until/if something cheaper is needed. - Value: &tracepb.Span_TimeEvent_Annotation_{ - Annotation: &tracepb.Span_TimeEvent_Annotation{ - Description: &tracepb.TruncatableString{Value: currAnnotation.Value}, - }, - }, - } - - timeEvents = append(timeEvents, timeEvent) + ev := span.Events().AppendEmpty() + ev.SetTimestamp(ts) + ev.SetName(currAnnotation.Value) } - if len(timeEvents) > 0 { - res.TimeEvents = &tracepb.Span_TimeEvents{TimeEvent: timeEvents} - } - - if res.Endpoint == nil { - res.Endpoint = &endpoint{ + if edpt == nil { + edpt = &endpoint{ ServiceName: unknownServiceName, } } - return res + return span, edpt } -func hexTraceIDToOCTraceID(hex string) ([]byte, error) { +func hexToTraceID(hexStr string) (pcommon.TraceID, error) { // Per info at https://zipkin.io/zipkin-api/zipkin-api.yaml it should be 16 or 32 characters - hexLen := len(hex) + hexLen := len(hexStr) if hexLen != 16 && hexLen != 32 { - return nil, errHexTraceIDWrongLen + return pcommon.NewTraceIDEmpty(), errHexTraceIDWrongLen } - var high, low uint64 - var err error - if hexLen == 32 { - if high, err = strconv.ParseUint(hex[:16], 16, 64); err != nil { - return nil, errHexTraceIDParsing + var id [16]byte + if hexLen == 16 { + if _, err := hex.Decode(id[8:], []byte(hexStr)); err != nil { + return pcommon.NewTraceIDEmpty(), err + } + if pcommon.TraceID(id).IsEmpty() { + return pcommon.NewTraceIDEmpty(), errHexTraceIDZero } + return id, nil } - if low, err = strconv.ParseUint(hex[hexLen-16:], 16, 64); err != nil { - return nil, errHexTraceIDParsing + if _, err := hex.Decode(id[:], []byte(hexStr)); err != nil { + return pcommon.NewTraceIDEmpty(), err } - - if high == 0 && low == 0 { - return nil, errHexTraceIDZero + if pcommon.TraceID(id).IsEmpty() { + return pcommon.NewTraceIDEmpty(), errHexTraceIDZero } - - tidBytes := idutils.UInt64ToTraceID(high, low) - return tidBytes[:], nil + return id, nil } -func hexIDToOCID(hex string) ([]byte, error) { +func hexToSpanID(hexStr string) (pcommon.SpanID, error) { // Per info at https://zipkin.io/zipkin-api/zipkin-api.yaml it should be 16 characters - if len(hex) != 16 { - return nil, errHexIDWrongLen + if len(hexStr) != 16 { + return pcommon.NewSpanIDEmpty(), errHexIDWrongLen } - idValue, err := strconv.ParseUint(hex, 16, 64) - if err != nil { - return nil, errHexIDParsing + var id [8]byte + if _, err := hex.Decode(id[:], []byte(hexStr)); err != nil { + return pcommon.NewSpanIDEmpty(), err } - - if idValue == 0 { - return nil, errHexIDZero + if pcommon.SpanID(id).IsEmpty() { + return pcommon.NewSpanIDEmpty(), errHexIDZero } - - idBytes := idutils.UInt64ToSpanID(idValue) - return idBytes[:], nil + return id, nil } -func epochMicrosecondsToTimestamp(msecs int64) *timestamppb.Timestamp { +func epochMicrosecondsToTimestamp(msecs int64) pcommon.Timestamp { if msecs <= 0 { - return nil + return pcommon.Timestamp(0) } - t := ×tamppb.Timestamp{} - t.Seconds = msecs / 1e6 - t.Nanos = int32(msecs%1e6) * 1e3 - return t + return pcommon.Timestamp(uint64(msecs) * 1e6) } -func getOrCreateNodeRequest(m map[string]*traceData, endpoint *endpoint) *traceData { +func getOrCreateNodeRequest(m map[string]ptrace.SpanSlice, td ptrace.Traces, endpoint *endpoint) ptrace.SpanSlice { // this private function assumes that the caller never passes an nil endpoint nodeKey := endpoint.string() - req := m[nodeKey] - - if req != nil { - return req + ss, found := m[nodeKey] + if found { + return ss } - req = &traceData{ - Node: &commonpb.Node{ - ServiceInfo: &commonpb.ServiceInfo{Name: endpoint.ServiceName}, - }, - } - - if attributeMap := endpoint.createAttributeMap(); attributeMap != nil { - req.Node.Attributes = attributeMap - } - - m[nodeKey] = req - - return req + rs := td.ResourceSpans().AppendEmpty() + rs.Resource().Attributes().PutString(conventions.AttributeServiceName, endpoint.ServiceName) + endpoint.setAttributes(rs.Resource().Attributes()) + ss = rs.ScopeSpans().AppendEmpty().Spans() + m[nodeKey] = ss + return ss } func (ep *endpoint) string() string { return fmt.Sprintf("%s-%s-%s-%d", ep.ServiceName, ep.IPv4, ep.IPv6, ep.Port) } -func (ep *endpoint) createAttributeMap() map[string]string { +func (ep *endpoint) setAttributes(dest pcommon.Map) { if ep.IPv4 == "" && ep.IPv6 == "" && ep.Port == 0 { - return nil + return } - attributeMap := make(map[string]string, 3) if ep.IPv4 != "" { - attributeMap["ipv4"] = ep.IPv4 + dest.PutString("ipv4", ep.IPv4) } if ep.IPv6 != "" { - attributeMap["ipv6"] = ep.IPv6 + dest.PutString("ipv6", ep.IPv6) } if ep.Port != 0 { - attributeMap["port"] = strconv.Itoa(int(ep.Port)) + dest.PutString("port", strconv.Itoa(int(ep.Port))) } - return attributeMap } -func setTimestampsIfUnset(span *tracepb.Span) { +func setTimestampsIfUnset(span ptrace.Span) { // zipkin allows timestamp to be unset, but opentelemetry-collector expects it to have a value. // If this is unset, the conversion from open census to the internal trace format breaks // what should be an identity transformation oc -> internal -> oc - if span.StartTime == nil { - now := timestamppb.New(time.Now()) - span.StartTime = now - span.EndTime = now - - if span.Attributes == nil { - span.Attributes = &tracepb.Span_Attributes{} - } - if span.Attributes.AttributeMap == nil { - span.Attributes.AttributeMap = make(map[string]*tracepb.AttributeValue, 1) - } - span.Attributes.AttributeMap[zipkin.StartTimeAbsent] = &tracepb.AttributeValue{ - Value: &tracepb.AttributeValue_BoolValue{ - BoolValue: true, - }} + if span.StartTimestamp() == 0 { + now := time.Now() + span.SetStartTimestamp(pcommon.NewTimestampFromTime(now)) + span.SetEndTimestamp(pcommon.NewTimestampFromTime(now)) + span.Attributes().PutBool(zipkin.StartTimeAbsent, true) } } diff --git a/pkg/translator/zipkin/zipkinv1/json_test.go b/pkg/translator/zipkin/zipkinv1/json_test.go index 3db4b50b04ac7..91f07dcc4e60c 100644 --- a/pkg/translator/zipkin/zipkinv1/json_test.go +++ b/pkg/translator/zipkin/zipkinv1/json_test.go @@ -15,34 +15,24 @@ package zipkinv1 import ( + "encoding/hex" "encoding/json" "os" - "sort" "strconv" "testing" "time" - commonpb "github.com/census-instrumentation/opencensus-proto/gen-go/agent/common/v1" - tracepb "github.com/census-instrumentation/opencensus-proto/gen-go/trace/v1" zipkinmodel "github.com/openzipkin/zipkin-go/model" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/pdata/pcommon" + "go.opentelemetry.io/collector/pdata/ptrace" conventions "go.opentelemetry.io/collector/semconv/v1.6.1" - "google.golang.org/protobuf/types/known/timestamppb" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/tracetranslator" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/zipkin/internal/zipkin" ) -func TestSingleJSONV1BatchToTraces(t *testing.T) { - blob, err := os.ReadFile("./testdata/zipkin_v1_single_batch.json") - require.NoError(t, err, "Failed to load test data") - - td, err := NewJSONTracesUnmarshaler(false).UnmarshalTraces(blob) - require.NoError(t, err, "Failed to translate zipkinv1 to OC proto") - assert.Equal(t, 5, td.SpanCount()) -} - func TestErrorSpanToTraces(t *testing.T) { blob, err := os.ReadFile("./testdata/zipkin_v1_error_batch.json") require.NoError(t, err, "Failed to load test data") @@ -51,96 +41,91 @@ func TestErrorSpanToTraces(t *testing.T) { assert.Error(t, err, "Should have generated error") } -func Test_hexIDToOCID(t *testing.T) { +func TestHexIDToSpanID(t *testing.T) { tests := []struct { name string hexStr string - want []byte + want pcommon.SpanID wantErr error }{ { name: "empty hex string", hexStr: "", - want: nil, wantErr: errHexIDWrongLen, }, { name: "wrong length", hexStr: "0000", - want: nil, wantErr: errHexIDWrongLen, }, { name: "parse error", hexStr: "000000000000000-", - want: nil, - wantErr: errHexIDParsing, + wantErr: hex.InvalidByteError(0x2d), }, { name: "all zero", hexStr: "0000000000000000", - want: nil, wantErr: errHexIDZero, }, { name: "happy path", hexStr: "0706050400010203", - want: []byte{7, 6, 5, 4, 0, 1, 2, 3}, + want: [8]byte{7, 6, 5, 4, 0, 1, 2, 3}, wantErr: nil, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := hexIDToOCID(tt.hexStr) + got, err := hexToSpanID(tt.hexStr) require.Equal(t, tt.wantErr, err) + if tt.wantErr != nil { + return + } assert.Equal(t, tt.want, got) }) } } -func Test_hexTraceIDToOCTraceID(t *testing.T) { +func TestHexToTraceID(t *testing.T) { tests := []struct { name string hexStr string - want []byte + want [16]byte wantErr error }{ { name: "empty hex string", hexStr: "", - want: nil, wantErr: errHexTraceIDWrongLen, }, { name: "wrong length", hexStr: "000000000000000010", - want: nil, wantErr: errHexTraceIDWrongLen, }, { name: "parse error", hexStr: "000000000000000X0000000000000000", - want: nil, - wantErr: errHexTraceIDParsing, + wantErr: hex.InvalidByteError(0x58), }, { name: "all zero", hexStr: "00000000000000000000000000000000", - want: nil, wantErr: errHexTraceIDZero, }, { name: "happy path", hexStr: "00000000000000010000000000000002", - want: []byte{0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2}, + want: [16]byte{0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2}, wantErr: nil, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := hexTraceIDToOCTraceID(tt.hexStr) + got, err := hexToTraceID(tt.hexStr) require.Equal(t, tt.wantErr, err) - assert.Equal(t, tt.want, got) + assert.EqualValues(t, tt.want, got) }) } } @@ -149,36 +134,38 @@ func TestZipkinJSONFallbackToLocalComponent(t *testing.T) { blob, err := os.ReadFile("./testdata/zipkin_v1_local_component.json") require.NoError(t, err, "Failed to load test data") - reqs, err := v1JSONBatchToOCProto(blob, false) - require.NoError(t, err, "Failed to translate zipkinv1 to OC proto") - require.Equal(t, 2, len(reqs), "Invalid trace service requests count") - - // Ensure the order of nodes - sort.Slice(reqs, func(i, j int) bool { - return reqs[i].Node.ServiceInfo.Name < reqs[j].Node.ServiceInfo.Name - }) + reqs, err := jsonBatchToTraces(blob, false) + require.NoError(t, err) + require.Equal(t, 2, reqs.ResourceSpans().Len(), "Invalid trace service requests count") // First span didn't have a host/endpoint to give service name, use the local component. - got := reqs[0].Node.ServiceInfo.Name - require.Equal(t, "myLocalComponent", got) - - // Second span have a host/endpoint to give service name, do not use local component. - got = reqs[1].Node.ServiceInfo.Name - require.Equal(t, "myServiceName", got) + gotFirst, found := reqs.ResourceSpans().At(0).Resource().Attributes().Get(conventions.AttributeServiceName) + require.True(t, found) + + gotSecond, found := reqs.ResourceSpans().At(1).Resource().Attributes().Get(conventions.AttributeServiceName) + require.True(t, found) + + if gotFirst.AsString() == "myLocalComponent" { + require.Equal(t, "myLocalComponent", gotFirst.Str()) + require.Equal(t, "myServiceName", gotSecond.Str()) + } else { + require.Equal(t, "myServiceName", gotFirst.Str()) + require.Equal(t, "myLocalComponent", gotSecond.Str()) + } } -func TestSingleJSONV1BatchToOCProto(t *testing.T) { +func TestSingleJSONV1BatchToTraces(t *testing.T) { blob, err := os.ReadFile("./testdata/zipkin_v1_single_batch.json") require.NoError(t, err, "Failed to load test data") - parseStringTags := true // This test relies on parsing int/bool to the typed span attributes - got, err := v1JSONBatchToOCProto(blob, parseStringTags) - require.NoError(t, err, "Failed to translate zipkinv1 to OC proto") + // This test relies on parsing int/bool to the typed span attributes + got, err := jsonBatchToTraces(blob, true) + require.NoError(t, err) - compareTraceData(t, got, ocBatchesFromZipkinV1) + compareTraces(t, tracesFromZipkinV1, got) } -func TestMultipleJSONV1BatchesToOCProto(t *testing.T) { +func TestMultipleJSONV1BatchesToTraces(t *testing.T) { blob, err := os.ReadFile("./testdata/zipkin_v1_multiple_batches.json") require.NoError(t, err, "Failed to load test data") @@ -186,47 +173,39 @@ func TestMultipleJSONV1BatchesToOCProto(t *testing.T) { err = json.Unmarshal(blob, &batches) require.NoError(t, err, "Failed to load the batches") - nodeToTraceReqs := make(map[string]*traceData) - var got []traceData + got := map[string]map[string]ptrace.Span{} for _, batch := range batches { jsonBatch, err := json.Marshal(batch) require.NoError(t, err, "Failed to marshal interface back to blob") - parseStringTags := true // This test relies on parsing int/bool to the typed span attributes - g, err := v1JSONBatchToOCProto(jsonBatch, parseStringTags) - require.NoError(t, err, "Failed to translate zipkinv1 to OC proto") + // This test relies on parsing int/bool to the typed span attributes + g, err := jsonBatchToTraces(jsonBatch, true) + require.NoError(t, err) // Coalesce the nodes otherwise they will differ due to multiple // nodes representing same logical service - for i := range g { - key := g[i].Node.String() - if pTsr, ok := nodeToTraceReqs[key]; ok { - pTsr.Spans = append(pTsr.Spans, g[i].Spans...) - } else { - nodeToTraceReqs[key] = &g[i] + mps := mapperTraces(t, g) + for k, v := range mps { + sps, ok := got[k] + if !ok { + sps = map[string]ptrace.Span{} + got[k] = map[string]ptrace.Span{} + } + for kk, vv := range v { + sps[kk] = vv } } } - for _, tsr := range nodeToTraceReqs { - got = append(got, *tsr) - } - - compareTraceData(t, got, ocBatchesFromZipkinV1) + assert.EqualValues(t, mapperTraces(t, tracesFromZipkinV1), got) } -func sortTraceByNodeName(trace []traceData) { - sort.Slice(trace, func(i, j int) bool { - return trace[i].Node.ServiceInfo.Name < trace[j].Node.ServiceInfo.Name - }) -} - -func TestZipkinAnnotationsToOCStatus(t *testing.T) { +func TestZipkinAnnotationsToSpanStatus(t *testing.T) { type test struct { name string haveTags []*binaryAnnotation - wantAttributes *tracepb.Span_Attributes - wantStatus *tracepb.Status + wantAttributes pcommon.Map + wantStatus ptrace.SpanStatus } cases := []test{ @@ -234,12 +213,14 @@ func TestZipkinAnnotationsToOCStatus(t *testing.T) { name: "only otel.status_code tag", haveTags: []*binaryAnnotation{{ Key: conventions.OtelStatusCode, - Value: "13", + Value: "2", }}, - wantAttributes: nil, - wantStatus: &tracepb.Status{ - Code: 13, - }, + wantAttributes: pcommon.NewMap(), + wantStatus: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + return ret + }(), }, { @@ -248,8 +229,8 @@ func TestZipkinAnnotationsToOCStatus(t *testing.T) { Key: conventions.OtelStatusDescription, Value: "Forbidden", }}, - wantAttributes: nil, - wantStatus: nil, + wantAttributes: pcommon.NewMap(), + wantStatus: ptrace.NewSpanStatus(), }, { @@ -257,18 +238,20 @@ func TestZipkinAnnotationsToOCStatus(t *testing.T) { haveTags: []*binaryAnnotation{ { Key: conventions.OtelStatusCode, - Value: "13", + Value: "2", }, { Key: conventions.OtelStatusDescription, Value: "Forbidden", }, }, - wantAttributes: nil, - wantStatus: &tracepb.Status{ - Code: 13, - Message: "Forbidden", - }, + wantAttributes: pcommon.NewMap(), + wantStatus: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + ret.SetMessage("Forbidden") + return ret + }(), }, { @@ -283,24 +266,18 @@ func TestZipkinAnnotationsToOCStatus(t *testing.T) { Value: "NotFound", }, }, - wantAttributes: &tracepb.Span_Attributes{ - AttributeMap: map[string]*tracepb.AttributeValue{ - conventions.AttributeHTTPStatusCode: { - Value: &tracepb.AttributeValue_IntValue{ - IntValue: 404, - }, - }, - tracetranslator.TagHTTPStatusMsg: { - Value: &tracepb.AttributeValue_StringValue{ - StringValue: &tracepb.TruncatableString{Value: "NotFound"}, - }, - }, - }, - }, - wantStatus: &tracepb.Status{ - Code: 5, - Message: "NotFound", - }, + wantAttributes: func() pcommon.Map { + ret := pcommon.NewMap() + ret.PutInt(conventions.AttributeHTTPStatusCode, 404) + ret.PutString(tracetranslator.TagHTTPStatusMsg, "NotFound") + return ret + }(), + wantStatus: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + ret.SetMessage("NotFound") + return ret + }(), }, { @@ -316,31 +293,25 @@ func TestZipkinAnnotationsToOCStatus(t *testing.T) { }, { Key: conventions.OtelStatusCode, - Value: "13", + Value: "2", }, { Key: conventions.OtelStatusDescription, Value: "Forbidden", }, }, - wantAttributes: &tracepb.Span_Attributes{ - AttributeMap: map[string]*tracepb.AttributeValue{ - conventions.AttributeHTTPStatusCode: { - Value: &tracepb.AttributeValue_IntValue{ - IntValue: 404, - }, - }, - tracetranslator.TagHTTPStatusMsg: { - Value: &tracepb.AttributeValue_StringValue{ - StringValue: &tracepb.TruncatableString{Value: "NotFound"}, - }, - }, - }, - }, - wantStatus: &tracepb.Status{ - Code: 13, - Message: "Forbidden", - }, + wantAttributes: func() pcommon.Map { + ret := pcommon.NewMap() + ret.PutInt(conventions.AttributeHTTPStatusCode, 404) + ret.PutString(tracetranslator.TagHTTPStatusMsg, "NotFound") + return ret + }(), + wantStatus: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + ret.SetMessage("Forbidden") + return ret + }(), }, { @@ -356,26 +327,20 @@ func TestZipkinAnnotationsToOCStatus(t *testing.T) { }, { Key: conventions.OtelStatusCode, - Value: "14", + Value: "2", }, }, - wantAttributes: &tracepb.Span_Attributes{ - AttributeMap: map[string]*tracepb.AttributeValue{ - conventions.AttributeHTTPStatusCode: { - Value: &tracepb.AttributeValue_IntValue{ - IntValue: 404, - }, - }, - tracetranslator.TagHTTPStatusMsg: { - Value: &tracepb.AttributeValue_StringValue{ - StringValue: &tracepb.TruncatableString{Value: "NotFound"}, - }, - }, - }, - }, - wantStatus: &tracepb.Status{ - Code: 14, - }, + wantAttributes: func() pcommon.Map { + ret := pcommon.NewMap() + ret.PutInt(conventions.AttributeHTTPStatusCode, 404) + ret.PutString(tracetranslator.TagHTTPStatusMsg, "NotFound") + return ret + }(), + wantStatus: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + return ret + }(), }, { @@ -394,24 +359,18 @@ func TestZipkinAnnotationsToOCStatus(t *testing.T) { Value: "Forbidden", }, }, - wantAttributes: &tracepb.Span_Attributes{ - AttributeMap: map[string]*tracepb.AttributeValue{ - conventions.AttributeHTTPStatusCode: { - Value: &tracepb.AttributeValue_IntValue{ - IntValue: 404, - }, - }, - tracetranslator.TagHTTPStatusMsg: { - Value: &tracepb.AttributeValue_StringValue{ - StringValue: &tracepb.TruncatableString{Value: "NotFound"}, - }, - }, - }, - }, - wantStatus: &tracepb.Status{ - Code: 5, - Message: "NotFound", - }, + wantAttributes: func() pcommon.Map { + ret := pcommon.NewMap() + ret.PutInt(conventions.AttributeHTTPStatusCode, 404) + ret.PutString(tracetranslator.TagHTTPStatusMsg, "NotFound") + return ret + }(), + wantStatus: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + ret.SetMessage("NotFound") + return ret + }(), }, { @@ -426,11 +385,13 @@ func TestZipkinAnnotationsToOCStatus(t *testing.T) { Value: "RPCError", }, }, - wantAttributes: nil, - wantStatus: &tracepb.Status{ - Code: 10, - Message: "RPCError", - }, + wantAttributes: pcommon.NewMap(), + wantStatus: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + ret.SetMessage("RPCError") + return ret + }(), }, { @@ -461,24 +422,18 @@ func TestZipkinAnnotationsToOCStatus(t *testing.T) { Value: "7", }, }, - wantAttributes: &tracepb.Span_Attributes{ - AttributeMap: map[string]*tracepb.AttributeValue{ - conventions.AttributeHTTPStatusCode: { - Value: &tracepb.AttributeValue_IntValue{ - IntValue: 404, - }, - }, - tracetranslator.TagHTTPStatusMsg: { - Value: &tracepb.AttributeValue_StringValue{ - StringValue: &tracepb.TruncatableString{Value: "NotFound"}, - }, - }, - }, - }, - wantStatus: &tracepb.Status{ - Code: 10, - Message: "RPCError", - }, + wantAttributes: func() pcommon.Map { + ret := pcommon.NewMap() + ret.PutInt(conventions.AttributeHTTPStatusCode, 404) + ret.PutString(tracetranslator.TagHTTPStatusMsg, "NotFound") + return ret + }(), + wantStatus: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + ret.SetMessage("RPCError") + return ret + }(), }, } @@ -487,27 +442,21 @@ func TestZipkinAnnotationsToOCStatus(t *testing.T) { for i, c := range cases { t.Run(c.name, func(t *testing.T) { - zSpans := []*zipkinV1Span{{ + zSpans := []*jsonSpan{{ ID: fakeSpanID, TraceID: fakeTraceID, BinaryAnnotations: c.haveTags, Timestamp: 1, }} zBytes, err := json.Marshal(zSpans) - if err != nil { - t.Errorf("#%d: Unexpected error: %v", i, err) - return - } - - parseStringTags := true // This test relies on parsing int/bool to the typed span attributes - gb, err := v1JSONBatchToOCProto(zBytes, parseStringTags) - if err != nil { - t.Errorf("#%d: Unexpected error: %v", i, err) - return - } - gs := gb[0].Spans[0] - require.Equal(t, c.wantAttributes, gs.Attributes, "Unsuccessful conversion %d", i) - require.Equal(t, c.wantStatus, gs.Status, "Unsuccessful conversion %d", i) + require.NoError(t, err) + + // This test relies on parsing int/bool to the typed span attributes + td, err := jsonBatchToTraces(zBytes, true) + require.NoError(t, err) + gs := td.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0) + require.Equal(t, c.wantAttributes.Sort(), gs.Attributes().Sort(), "Unsuccessful conversion %d", i) + require.Equal(t, c.wantStatus, gs.Status(), "Unsuccessful conversion %d", i) }) } } @@ -515,7 +464,7 @@ func TestZipkinAnnotationsToOCStatus(t *testing.T) { func TestSpanWithoutTimestampGetsTag(t *testing.T) { fakeTraceID := "00000000000000010000000000000002" fakeSpanID := "0000000000000001" - zSpans := []*zipkinV1Span{ + zSpans := []*jsonSpan{ { ID: fakeSpanID, TraceID: fakeTraceID, @@ -523,44 +472,30 @@ func TestSpanWithoutTimestampGetsTag(t *testing.T) { }, } zBytes, err := json.Marshal(zSpans) - if err != nil { - t.Errorf("Unexpected error: %v", err) - return - } + require.NoError(t, err) testStart := time.Now() - gb, err := v1JSONBatchToOCProto(zBytes, false) - if err != nil { - t.Errorf("Unexpected error: %v", err) - return - } + td, err := jsonBatchToTraces(zBytes, false) + require.NoError(t, err) - gs := gb[0].Spans[0] - assert.NotNil(t, gs.StartTime) - assert.NotNil(t, gs.EndTime) + gs := td.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0) + assert.NotZero(t, gs.StartTimestamp()) + assert.NotZero(t, gs.EndTimestamp()) - assert.True(t, gs.StartTime.AsTime().Sub(testStart) >= 0) + assert.True(t, gs.StartTimestamp().AsTime().Sub(testStart) >= 0) - wantAttributes := &tracepb.Span_Attributes{ - AttributeMap: map[string]*tracepb.AttributeValue{ - zipkin.StartTimeAbsent: { - Value: &tracepb.AttributeValue_BoolValue{ - BoolValue: true, - }, - }, - }, - } - - assert.EqualValues(t, gs.Attributes, wantAttributes) + wantAttributes := pcommon.NewMap() + wantAttributes.PutBool(zipkin.StartTimeAbsent, true) + assert.EqualValues(t, wantAttributes, gs.Attributes()) } -func TestJSONHTTPToGRPCStatusCode(t *testing.T) { +func TestJSONHTTPToStatusCode(t *testing.T) { fakeTraceID := "00000000000000010000000000000002" fakeSpanID := "0000000000000001" for i := int32(100); i <= 600; i++ { - wantStatus := ocStatusCodeFromHTTP(i) - zBytes, err := json.Marshal([]*zipkinV1Span{{ + wantStatus := statusCodeFromHTTP(i) + zBytes, err := json.Marshal([]*jsonSpan{{ ID: fakeSpanID, TraceID: fakeTraceID, BinaryAnnotations: []*binaryAnnotation{ @@ -570,172 +505,117 @@ func TestJSONHTTPToGRPCStatusCode(t *testing.T) { }, }, }}) - if err != nil { - t.Errorf("#%d: Unexpected error: %v", i, err) - continue - } - gb, err := v1JSONBatchToOCProto(zBytes, false) - if err != nil { - t.Errorf("#%d: Unexpected error: %v", i, err) - continue - } - - gs := gb[0].Spans[0] - require.Equal(t, wantStatus, gs.Status.Code, "Unsuccessful conversion %d", i) + require.NoError(t, err) + td, err := jsonBatchToTraces(zBytes, false) + require.NoError(t, err) + gs := td.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0) + require.EqualValues(t, wantStatus, gs.Status().Code(), "Unsuccessful conversion %d", i) } } -// 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 = []traceData{ - { - Node: &commonpb.Node{ - ServiceInfo: &commonpb.ServiceInfo{Name: "front-proxy"}, - Attributes: map[string]string{"ipv4": "172.31.0.2"}, - }, - Spans: []*tracepb.Span{ - { - TraceId: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0xd2, 0xe6, 0x3c, 0xbe, 0x71, 0xf5, 0xa8}, - SpanId: []byte{0x0e, 0xd2, 0xe6, 0x3c, 0xbe, 0x71, 0xf5, 0xa8}, - ParentSpanId: nil, - Name: &tracepb.TruncatableString{Value: "checkAvailability"}, - Kind: tracepb.Span_CLIENT, - StartTime: ×tamppb.Timestamp{Seconds: 1544805927, Nanos: 446743000}, - EndTime: ×tamppb.Timestamp{Seconds: 1544805927, Nanos: 459699000}, - TimeEvents: nil, - }, - }, - }, - { - Node: &commonpb.Node{ - ServiceInfo: &commonpb.ServiceInfo{Name: "service1"}, - Attributes: map[string]string{"ipv4": "172.31.0.4"}, - }, - Spans: []*tracepb.Span{ - { - TraceId: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0xd2, 0xe6, 0x3c, 0xbe, 0x71, 0xf5, 0xa8}, - SpanId: []byte{0x0e, 0xd2, 0xe6, 0x3c, 0xbe, 0x71, 0xf5, 0xa8}, - ParentSpanId: nil, - Name: &tracepb.TruncatableString{Value: "checkAvailability"}, - Kind: tracepb.Span_SERVER, - StartTime: ×tamppb.Timestamp{Seconds: 1544805927, Nanos: 448081000}, - EndTime: ×tamppb.Timestamp{Seconds: 1544805927, Nanos: 460102000}, - TimeEvents: &tracepb.Span_TimeEvents{ - TimeEvent: []*tracepb.Span_TimeEvent{ - { - Time: ×tamppb.Timestamp{Seconds: 1544805927, Nanos: 450000000}, - Value: &tracepb.Span_TimeEvent_Annotation_{ - Annotation: &tracepb.Span_TimeEvent_Annotation{ - Description: &tracepb.TruncatableString{Value: "custom time event"}, - }, - }, - }, - }, - }, - }, - { - TraceId: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0xd2, 0xe6, 0x3c, 0xbe, 0x71, 0xf5, 0xa8}, - SpanId: []byte{0xf9, 0xeb, 0xb6, 0xe6, 0x48, 0x80, 0x61, 0x2a}, - ParentSpanId: []byte{0x0e, 0xd2, 0xe6, 0x3c, 0xbe, 0x71, 0xf5, 0xa8}, - Name: &tracepb.TruncatableString{Value: "checkStock"}, - Kind: tracepb.Span_CLIENT, - StartTime: ×tamppb.Timestamp{Seconds: 1544805927, Nanos: 453923000}, - EndTime: ×tamppb.Timestamp{Seconds: 1544805927, Nanos: 457663000}, - TimeEvents: nil, - }, - }, - }, - { - Node: &commonpb.Node{ - ServiceInfo: &commonpb.ServiceInfo{Name: "service2"}, - Attributes: map[string]string{"ipv4": "172.31.0.7"}, - }, - Spans: []*tracepb.Span{ - { - TraceId: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0xd2, 0xe6, 0x3c, 0xbe, 0x71, 0xf5, 0xa8}, - SpanId: []byte{0xf9, 0xeb, 0xb6, 0xe6, 0x48, 0x80, 0x61, 0x2a}, - ParentSpanId: []byte{0x0e, 0xd2, 0xe6, 0x3c, 0xbe, 0x71, 0xf5, 0xa8}, - Name: &tracepb.TruncatableString{Value: "checkStock"}, - Kind: tracepb.Span_SERVER, - StartTime: ×tamppb.Timestamp{Seconds: 1544805927, Nanos: 454487000}, - EndTime: ×tamppb.Timestamp{Seconds: 1544805927, Nanos: 457320000}, - Status: &tracepb.Status{ - Code: 0, - }, - Attributes: &tracepb.Span_Attributes{ - AttributeMap: map[string]*tracepb.AttributeValue{ - "http.status_code": { - Value: &tracepb.AttributeValue_IntValue{IntValue: 200}, - }, - "http.url": { - Value: &tracepb.AttributeValue_StringValue{StringValue: &tracepb.TruncatableString{Value: "http://localhost:9000/trace/2"}}, - }, - "success": { - Value: &tracepb.AttributeValue_BoolValue{BoolValue: true}, - }, - "processed": { - Value: &tracepb.AttributeValue_DoubleValue{DoubleValue: 1.5}, - }, - }, - }, - TimeEvents: nil, - }, - }, - }, - { - Node: &commonpb.Node{ - ServiceInfo: &commonpb.ServiceInfo{Name: "unknown-service"}, - }, - Spans: []*tracepb.Span{ - { - TraceId: []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0xd2, 0xe6, 0x3c, 0xbe, 0x71, 0xf5, 0xa8}, - SpanId: []byte{0xfe, 0x35, 0x1a, 0x05, 0x3f, 0xbc, 0xac, 0x1f}, - ParentSpanId: []byte{0x0e, 0xd2, 0xe6, 0x3c, 0xbe, 0x71, 0xf5, 0xa8}, - Name: &tracepb.TruncatableString{Value: "checkStock"}, - Kind: tracepb.Span_SPAN_KIND_UNSPECIFIED, - StartTime: ×tamppb.Timestamp{Seconds: 1544805927, Nanos: 453923000}, - EndTime: ×tamppb.Timestamp{Seconds: 1544805927, Nanos: 457663000}, - Attributes: nil, - }, - }, - }, -} +// tracesFromZipkinV1 has the "pdata" Traces used in the test. +var tracesFromZipkinV1 = func() ptrace.Traces { + td := ptrace.NewTraces() + rm := td.ResourceSpans().AppendEmpty() + rm.Resource().Attributes().PutString(conventions.AttributeServiceName, "front-proxy") + rm.Resource().Attributes().PutString("ipv4", "172.31.0.2") + + span := rm.ScopeSpans().AppendEmpty().Spans().AppendEmpty() + span.SetTraceID([16]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0xd2, 0xe6, 0x3c, 0xbe, 0x71, 0xf5, 0xa8}) + span.SetSpanID([8]byte{0x0e, 0xd2, 0xe6, 0x3c, 0xbe, 0x71, 0xf5, 0xa8}) + span.SetName("checkAvailability") + span.SetKind(ptrace.SpanKindClient) + span.SetStartTimestamp(pcommon.NewTimestampFromTime(time.Unix(1544805927, 446743000))) + span.SetEndTimestamp(pcommon.NewTimestampFromTime(time.Unix(1544805927, 459699000))) + + rm = td.ResourceSpans().AppendEmpty() + rm.Resource().Attributes().PutString(conventions.AttributeServiceName, "service1") + rm.Resource().Attributes().PutString("ipv4", "172.31.0.4") + + span = rm.ScopeSpans().AppendEmpty().Spans().AppendEmpty() + span.SetTraceID([16]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0xd2, 0xe6, 0x3c, 0xbe, 0x71, 0xf5, 0xa8}) + span.SetSpanID([8]byte{0x0e, 0xd2, 0xe6, 0x3c, 0xbe, 0x71, 0xf5, 0xa8}) + span.SetName("checkAvailability") + span.SetKind(ptrace.SpanKindServer) + span.SetStartTimestamp(pcommon.NewTimestampFromTime(time.Unix(1544805927, 448081000))) + span.SetEndTimestamp(pcommon.NewTimestampFromTime(time.Unix(1544805927, 460102000))) + ev := span.Events().AppendEmpty() + ev.SetTimestamp(pcommon.NewTimestampFromTime(time.Unix(1544805927, 450000000))) + ev.SetName("custom time event") + + span = rm.ScopeSpans().At(0).Spans().AppendEmpty() + span.SetTraceID([16]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0xd2, 0xe6, 0x3c, 0xbe, 0x71, 0xf5, 0xa8}) + span.SetSpanID([8]byte{0xf9, 0xeb, 0xb6, 0xe6, 0x48, 0x80, 0x61, 0x2a}) + span.SetParentSpanID([8]byte{0x0e, 0xd2, 0xe6, 0x3c, 0xbe, 0x71, 0xf5, 0xa8}) + span.SetName("checkStock") + span.SetKind(ptrace.SpanKindClient) + span.SetStartTimestamp(pcommon.NewTimestampFromTime(time.Unix(1544805927, 453923000))) + span.SetEndTimestamp(pcommon.NewTimestampFromTime(time.Unix(1544805927, 457663000))) + + rm = td.ResourceSpans().AppendEmpty() + rm.Resource().Attributes().PutString(conventions.AttributeServiceName, "service2") + rm.Resource().Attributes().PutString("ipv4", "172.31.0.7") + span = rm.ScopeSpans().AppendEmpty().Spans().AppendEmpty() + span.SetTraceID([16]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0xd2, 0xe6, 0x3c, 0xbe, 0x71, 0xf5, 0xa8}) + span.SetSpanID([8]byte{0xf9, 0xeb, 0xb6, 0xe6, 0x48, 0x80, 0x61, 0x2a}) + span.SetParentSpanID([8]byte{0x0e, 0xd2, 0xe6, 0x3c, 0xbe, 0x71, 0xf5, 0xa8}) + span.SetName("checkStock") + span.SetKind(ptrace.SpanKindServer) + span.SetStartTimestamp(pcommon.NewTimestampFromTime(time.Unix(1544805927, 454487000))) + span.SetEndTimestamp(pcommon.NewTimestampFromTime(time.Unix(1544805927, 457320000))) + span.Attributes().FromRaw(map[string]interface{}{ + "http.status_code": 200, + "http.url": "http://localhost:9000/trace/2", + "success": true, + "processed": 1.5, + }) + + rm = td.ResourceSpans().AppendEmpty() + rm.Resource().Attributes().PutString(conventions.AttributeServiceName, "unknown-service") + span = rm.ScopeSpans().AppendEmpty().Spans().AppendEmpty() + span.SetTraceID([16]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0xd2, 0xe6, 0x3c, 0xbe, 0x71, 0xf5, 0xa8}) + span.SetSpanID([8]byte{0xfe, 0x35, 0x1a, 0x05, 0x3f, 0xbc, 0xac, 0x1f}) + span.SetParentSpanID([8]byte{0x0e, 0xd2, 0xe6, 0x3c, 0xbe, 0x71, 0xf5, 0xa8}) + span.SetName("checkStock") + span.SetKind(ptrace.SpanKindUnspecified) + span.SetStartTimestamp(pcommon.NewTimestampFromTime(time.Unix(1544805927, 453923000))) + span.SetEndTimestamp(pcommon.NewTimestampFromTime(time.Unix(1544805927, 457663000))) + + return td +}() func TestSpanKindTranslation(t *testing.T) { tests := []struct { zipkinV1Kind string zipkinV2Kind zipkinmodel.Kind - ocKind tracepb.Span_SpanKind - ocAttrSpanKind tracetranslator.OpenTracingSpanKind + kind ptrace.SpanKind jaegerSpanKind string }{ { zipkinV1Kind: "cr", zipkinV2Kind: zipkinmodel.Client, - ocKind: tracepb.Span_CLIENT, + kind: ptrace.SpanKindClient, jaegerSpanKind: "client", }, { zipkinV1Kind: "sr", zipkinV2Kind: zipkinmodel.Server, - ocKind: tracepb.Span_SERVER, + kind: ptrace.SpanKindServer, jaegerSpanKind: "server", }, { zipkinV1Kind: "ms", zipkinV2Kind: zipkinmodel.Producer, - ocKind: tracepb.Span_SPAN_KIND_UNSPECIFIED, - ocAttrSpanKind: tracetranslator.OpenTracingSpanKindProducer, + kind: ptrace.SpanKindProducer, jaegerSpanKind: "producer", }, { zipkinV1Kind: "mr", zipkinV2Kind: zipkinmodel.Consumer, - ocKind: tracepb.Span_SPAN_KIND_UNSPECIFIED, - ocAttrSpanKind: tracetranslator.OpenTracingSpanKindConsumer, + kind: ptrace.SpanKindConsumer, jaegerSpanKind: "consumer", }, } @@ -743,7 +623,7 @@ func TestSpanKindTranslation(t *testing.T) { for _, test := range tests { t.Run(test.zipkinV1Kind, func(t *testing.T) { // Create Zipkin V1 span. - zSpan := &zipkinV1Span{ + zSpan := &jsonSpan{ TraceID: "1234567890123456", ID: "0123456789123456", Annotations: []*annotation{ @@ -752,45 +632,35 @@ func TestSpanKindTranslation(t *testing.T) { }, } - // Translate to OC and verify that span kind is correctly translated. - ocSpan, parsedAnnotations, err := zipkinV1ToOCSpan(zSpan, false) + // Translate to SpanAndEndpoint and verify that span kind is correctly translated. + sae, err := jsonToSpanAndEndpoint(zSpan, false) assert.NoError(t, err) - assert.EqualValues(t, test.ocKind, ocSpan.Kind) - assert.NotNil(t, parsedAnnotations) - if test.ocAttrSpanKind != "" { - require.NotNil(t, ocSpan.Attributes) - // This is a special case, verify that TagSpanKind attribute is set. - expected := &tracepb.AttributeValue{ - Value: &tracepb.AttributeValue_StringValue{ - StringValue: &tracepb.TruncatableString{Value: string(test.ocAttrSpanKind)}, - }, - } - assert.EqualValues(t, expected, ocSpan.Attributes.AttributeMap[tracetranslator.TagSpanKind]) - } + assert.EqualValues(t, test.kind, sae.span.Kind()) + assert.NotNil(t, sae.endpoint) }) } } -func TestZipkinV1ToOCSpanInvalidTraceId(t *testing.T) { - zSpan := &zipkinV1Span{ +func TestZipkinV1ToSpanAnsEndpointInvalidTraceId(t *testing.T) { + zSpan := &jsonSpan{ TraceID: "abc", ID: "0123456789123456", Annotations: []*annotation{ {Value: "cr"}, }, } - _, _, err := zipkinV1ToOCSpan(zSpan, false) + _, err := jsonToSpanAndEndpoint(zSpan, false) assert.EqualError(t, err, "zipkinV1 span traceId: hex traceId span has wrong length (expected 16 or 32)") } -func TestZipkinV1ToOCSpanInvalidSpanId(t *testing.T) { - zSpan := &zipkinV1Span{ +func TestZipkinV1ToSpanAnsEndpointInvalidSpanId(t *testing.T) { + zSpan := &jsonSpan{ TraceID: "1234567890123456", ID: "abc", Annotations: []*annotation{ {Value: "cr"}, }, } - _, _, err := zipkinV1ToOCSpan(zSpan, false) + _, err := jsonToSpanAndEndpoint(zSpan, false) assert.EqualError(t, err, "zipkinV1 span id: hex Id has wrong length (expected 16)") } diff --git a/pkg/translator/zipkin/zipkinv1/status_code.go b/pkg/translator/zipkin/zipkinv1/status_code.go index 41e384d777bca..acfa78c603eaf 100644 --- a/pkg/translator/zipkin/zipkinv1/status_code.go +++ b/pkg/translator/zipkin/zipkinv1/status_code.go @@ -19,14 +19,15 @@ import ( "math" "strconv" - tracepb "github.com/census-instrumentation/opencensus-proto/gen-go/trace/v1" + "go.opentelemetry.io/collector/pdata/pcommon" + "go.opentelemetry.io/collector/pdata/ptrace" conventions "go.opentelemetry.io/collector/semconv/v1.6.1" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/tracetranslator" ) type status struct { - codePtr *int32 + codePtr *ptrace.StatusCode message string } @@ -50,12 +51,12 @@ type statusMapper struct { fromErrorTagUnknown status } -// ocStatus returns an OC status from the best possible extraction source. +// status fills the given ptrace.SpanStatus from the best possible extraction source. // It'll first try to return status extracted from "census.status_code" to account for zipkin // then fallback on code extracted from "status.code" tags // and finally fallback on code extracted and translated from "http.status_code" -// ocStatus must be called after all tags/attributes are processed with the `fromAttribute` method. -func (m *statusMapper) ocStatus() *tracepb.Status { +// status must be called after all tags/attributes are processed with the `fromAttribute` method. +func (m *statusMapper) status(dest ptrace.SpanStatus) { var s status switch { case m.fromCensus.codePtr != nil: @@ -76,75 +77,75 @@ func (m *statusMapper) ocStatus() *tracepb.Status { } if s.codePtr != nil { - code := int32(0) + code := ptrace.StatusCodeUnset if s.codePtr != nil { code = *s.codePtr } - return &tracepb.Status{ - Code: code, - Message: s.message, - } + dest.SetCode(code) + dest.SetMessage(s.message) } - return nil } -func (m *statusMapper) fromAttribute(key string, attrib *tracepb.AttributeValue) bool { +func (m *statusMapper) fromAttribute(key string, attrib pcommon.Value) bool { switch key { case tagZipkinCensusCode: - code, err := attribToStatusCode(attrib) + ocCode, err := attribToStatusCode(attrib) if err == nil { + // Convert oc status (OK == 0) to otel (OK == 1), anything else is error. + code := ptrace.StatusCodeOk + if ocCode != 0 { + code = ptrace.StatusCodeError + } m.fromCensus.codePtr = &code } return true case tagZipkinCensusMsg, tagZipkinOpenCensusMsg: - m.fromCensus.message = attrib.GetStringValue().GetValue() + m.fromCensus.message = attrib.Str() return true case conventions.OtelStatusCode: + // Keep the code as is, even if unknown. Since we are allowed to receive unknown values for enums. code, err := attribToStatusCode(attrib) if err == nil { - m.fromStatus.codePtr = &code + m.fromStatus.codePtr = (*ptrace.StatusCode)(&code) } return true case conventions.OtelStatusDescription: - m.fromStatus.message = attrib.GetStringValue().GetValue() + m.fromStatus.message = attrib.Str() return true case conventions.AttributeHTTPStatusCode: httpCode, err := attribToStatusCode(attrib) if err == nil { - code := ocStatusCodeFromHTTP(httpCode) + code := statusCodeFromHTTP(httpCode) m.fromHTTP.codePtr = &code } case tracetranslator.TagHTTPStatusMsg: - m.fromHTTP.message = attrib.GetStringValue().GetValue() + m.fromHTTP.message = attrib.Str() case tracetranslator.TagError: - code, ok := extractStatusFromError(attrib) - if ok { - m.fromErrorTag.codePtr = code - return true - } - m.fromErrorTagUnknown.codePtr = code + // The status is stored with the "error" key, but otel does not care about the old census values. + // See https://github.com/census-instrumentation/opencensus-go/blob/1eb9a13c7dd02141e065a665f6bf5c99a090a16a/exporter/zipkin/zipkin.go#L160-L165 + code := ptrace.StatusCodeError + m.fromErrorTag.codePtr = &code + return true } return false } // attribToStatusCode maps an integer or string attribute value to a status code. // The function return nil if the value is of another type or cannot be converted to an int32 value. -func attribToStatusCode(attr *tracepb.AttributeValue) (int32, error) { - if attr == nil { +func attribToStatusCode(attr pcommon.Value) (int32, error) { + switch attr.Type() { + case pcommon.ValueTypeEmpty: return 0, fmt.Errorf("nil attribute") - } - - switch val := attr.Value.(type) { - case *tracepb.AttributeValue_IntValue: - return toInt32(int(val.IntValue)) - case *tracepb.AttributeValue_StringValue: - i, err := strconv.Atoi(val.StringValue.GetValue()) + case pcommon.ValueTypeInt: + return toInt32(attr.Int()) + case pcommon.ValueTypeStr: + i, err := strconv.ParseInt(attr.Str(), 10, 64) if err != nil { return 0, err } @@ -153,52 +154,18 @@ func attribToStatusCode(attr *tracepb.AttributeValue) (int32, error) { return 0, fmt.Errorf("invalid attribute type") } -func toInt32(i int) (int32, error) { +func toInt32(i int64) (int32, error) { if i <= math.MaxInt32 && i >= math.MinInt32 { return int32(i), nil } return 0, fmt.Errorf("outside of the int32 range") } -func extractStatusFromError(attrib *tracepb.AttributeValue) (*int32, bool) { - // The status is stored with the "error" key - // See https://github.com/census-instrumentation/opencensus-go/blob/1eb9a13c7dd02141e065a665f6bf5c99a090a16a/exporter/zipkin/zipkin.go#L160-L165 - var unknown int32 = 2 - - switch val := attrib.Value.(type) { - case *tracepb.AttributeValue_StringValue: - canonicalCodeStr := val.StringValue.GetValue() - if canonicalCodeStr == "" { - return nil, true - } - code, set := canonicalCodesMap[canonicalCodeStr] - if set { - return &code, true - } - default: - break +// statusCodeFromHTTP takes an HTTP status code and return the appropriate OpenTelemetry status code +// See: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md +func statusCodeFromHTTP(code int32) ptrace.StatusCode { + if code >= 100 && code < 400 { + return ptrace.StatusCodeUnset } - - return &unknown, false -} - -var canonicalCodesMap = map[string]int32{ - // https://github.com/googleapis/googleapis/blob/bee79fbe03254a35db125dc6d2f1e9b752b390fe/google/rpc/code.proto#L33-L186 - "OK": 0, - "CANCELLED": 1, - "UNKNOWN": 2, - "INVALID_ARGUMENT": 3, - "DEADLINE_EXCEEDED": 4, - "NOT_FOUND": 5, - "ALREADY_EXISTS": 6, - "PERMISSION_DENIED": 7, - "RESOURCE_EXHAUSTED": 8, - "FAILED_PRECONDITION": 9, - "ABORTED": 10, - "OUT_OF_RANGE": 11, - "UNIMPLEMENTED": 12, - "INTERNAL": 13, - "UNAVAILABLE": 14, - "DATA_LOSS": 15, - "UNAUTHENTICATED": 16, + return ptrace.StatusCodeError } diff --git a/pkg/translator/zipkin/zipkinv1/status_code_test.go b/pkg/translator/zipkin/zipkinv1/status_code_test.go index 3b84f2687b50d..22d13c451650d 100644 --- a/pkg/translator/zipkin/zipkinv1/status_code_test.go +++ b/pkg/translator/zipkin/zipkinv1/status_code_test.go @@ -19,67 +19,56 @@ import ( "strconv" "testing" - tracepb "github.com/census-instrumentation/opencensus-proto/gen-go/trace/v1" "github.com/stretchr/testify/assert" + "go.opentelemetry.io/collector/pdata/pcommon" + "go.opentelemetry.io/collector/pdata/ptrace" ) func TestAttribToStatusCode(t *testing.T) { - _, atoiError := strconv.Atoi("nan") + _, atoiError := strconv.ParseInt("nan", 10, 64) tests := []struct { name string - attr *tracepb.AttributeValue + attr pcommon.Value code int32 err error }{ { name: "nil", - attr: nil, + attr: pcommon.NewValueEmpty(), code: 0, err: fmt.Errorf("nil attribute"), }, { name: "valid-int-code", - attr: &tracepb.AttributeValue{ - Value: &tracepb.AttributeValue_IntValue{IntValue: int64(0)}, - }, + attr: pcommon.NewValueInt(0), code: 0, - err: nil, }, { name: "invalid-int-code", - attr: &tracepb.AttributeValue{ - Value: &tracepb.AttributeValue_IntValue{IntValue: int64(1 << 32)}, - }, + attr: pcommon.NewValueInt(int64(1 << 32)), code: 0, err: fmt.Errorf("outside of the int32 range"), }, { name: "valid-string-code", - attr: &tracepb.AttributeValue{ - Value: &tracepb.AttributeValue_StringValue{StringValue: &tracepb.TruncatableString{Value: "200"}}, - }, + attr: pcommon.NewValueString("200"), code: 200, - err: nil, }, { name: "invalid-string-code", - attr: &tracepb.AttributeValue{ - Value: &tracepb.AttributeValue_StringValue{StringValue: &tracepb.TruncatableString{Value: "nan"}}, - }, + attr: pcommon.NewValueString("nan"), code: 0, err: atoiError, }, { name: "bool-code", - attr: &tracepb.AttributeValue{ - Value: &tracepb.AttributeValue_BoolValue{BoolValue: true}, - }, + attr: pcommon.NewValueBool(true), code: 0, err: fmt.Errorf("invalid attribute type"), }, @@ -97,20 +86,24 @@ func TestAttribToStatusCode(t *testing.T) { func TestStatusCodeMapperCases(t *testing.T) { tests := []struct { name string - expected *tracepb.Status + expected ptrace.SpanStatus attributes map[string]string }{ { name: "no relevant attributes", - expected: nil, + expected: ptrace.NewSpanStatus(), attributes: map[string]string{ "not.relevant": "data", }, }, { - name: "http: 500", - expected: &tracepb.Status{Code: 13}, + name: "http: 500", + expected: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + return ret + }(), attributes: map[string]string{ "http.status_code": "500", }, @@ -118,15 +111,20 @@ func TestStatusCodeMapperCases(t *testing.T) { { name: "http: message only, nil", - expected: nil, + expected: ptrace.NewSpanStatus(), attributes: map[string]string{ "http.status_message": "something", }, }, { - name: "http: 500", - expected: &tracepb.Status{Code: 13, Message: "a message"}, + name: "http: 500", + expected: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + ret.SetMessage("a message") + return ret + }(), attributes: map[string]string{ "http.status_code": "500", "http.status_message": "a message", @@ -134,8 +132,12 @@ func TestStatusCodeMapperCases(t *testing.T) { }, { - name: "http: 500, with error attribute", - expected: &tracepb.Status{Code: 13}, + name: "http: 500, with error attribute", + expected: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + return ret + }(), attributes: map[string]string{ "http.status_code": "500", "error": "an error occurred", @@ -143,8 +145,13 @@ func TestStatusCodeMapperCases(t *testing.T) { }, { - name: "oc: internal", - expected: &tracepb.Status{Code: 13, Message: "a description"}, + name: "oc: internal", + expected: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + ret.SetMessage("a description") + return ret + }(), attributes: map[string]string{ "census.status_code": "13", "census.status_description": "a description", @@ -152,8 +159,13 @@ func TestStatusCodeMapperCases(t *testing.T) { }, { - name: "oc: description and error", - expected: &tracepb.Status{Code: 13, Message: "a description"}, + name: "oc: description and error", + expected: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + ret.SetMessage("a description") + return ret + }(), attributes: map[string]string{ "opencensus.status_description": "a description", "error": "INTERNAL", @@ -161,16 +173,24 @@ func TestStatusCodeMapperCases(t *testing.T) { }, { - name: "oc: error only", - expected: &tracepb.Status{Code: 13, Message: ""}, + name: "oc: error only", + expected: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + return ret + }(), attributes: map[string]string{ "error": "INTERNAL", }, }, { - name: "oc: empty error tag", - expected: nil, + name: "oc: empty error tag", + expected: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + return ret + }(), attributes: map[string]string{ "error": "", }, @@ -178,15 +198,20 @@ func TestStatusCodeMapperCases(t *testing.T) { { name: "oc: description only, no status", - expected: nil, + expected: ptrace.NewSpanStatus(), attributes: map[string]string{ "opencensus.status_description": "a description", }, }, { - name: "oc: priority over http", - expected: &tracepb.Status{Code: 4, Message: "deadline expired"}, + name: "oc: priority over http", + expected: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + ret.SetMessage("deadline expired") + return ret + }(), attributes: map[string]string{ "census.status_description": "deadline expired", "census.status_code": "4", @@ -197,8 +222,12 @@ func TestStatusCodeMapperCases(t *testing.T) { }, { - name: "error: valid oc status priority over http", - expected: &tracepb.Status{Code: 4}, + name: "error: valid oc status priority over http", + expected: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + return ret + }(), attributes: map[string]string{ "error": "DEADLINE_EXCEEDED", @@ -208,8 +237,12 @@ func TestStatusCodeMapperCases(t *testing.T) { }, { - name: "error: invalid oc status uses http", - expected: &tracepb.Status{Code: 13, Message: "a description"}, + name: "error: invalid oc status uses http", + expected: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + return ret + }(), attributes: map[string]string{ "error": "123", @@ -219,32 +252,48 @@ func TestStatusCodeMapperCases(t *testing.T) { }, { - name: "error only: string description", - expected: &tracepb.Status{Code: 2}, + name: "error only: string description", + expected: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + return ret + }(), attributes: map[string]string{ "error": "a description", }, }, { - name: "error only: true", - expected: &tracepb.Status{Code: 2}, + name: "error only: true", + expected: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + return ret + }(), attributes: map[string]string{ "error": "true", }, }, { - name: "error only: false", - expected: &tracepb.Status{Code: 2}, + name: "error only: false", + expected: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + return ret + }(), attributes: map[string]string{ "error": "false", }, }, { - name: "error only: 1", - expected: &tracepb.Status{Code: 2}, + name: "error only: 1", + expected: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + return ret + }(), attributes: map[string]string{ "error": "1", }, @@ -253,25 +302,26 @@ func TestStatusCodeMapperCases(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - attributes := attributesFromMap(test.attributes) - sMapper := &statusMapper{} - for k, v := range attributes { - sMapper.fromAttribute(k, v) + for k, v := range test.attributes { + sMapper.fromAttribute(k, pcommon.NewValueString(v)) } - got := sMapper.ocStatus() - assert.EqualValues(t, test.expected, got) + spanStatus := ptrace.NewSpanStatus() + sMapper.status(spanStatus) + assert.EqualValues(t, test.expected, spanStatus) }) } } -func attributesFromMap(mapValues map[string]string) map[string]*tracepb.AttributeValue { - res := map[string]*tracepb.AttributeValue{} +func TestOTStatusFromHTTPStatus(t *testing.T) { + for httpStatus := int32(100); httpStatus < 400; httpStatus++ { + otelStatus := statusCodeFromHTTP(httpStatus) + assert.Equal(t, ptrace.StatusCodeUnset, otelStatus) + } - for k, v := range mapValues { - pbAttrib := parseAnnotationValue(v, false) - res[k] = pbAttrib + for httpStatus := int32(400); httpStatus <= 604; httpStatus++ { + otelStatus := statusCodeFromHTTP(httpStatus) + assert.Equal(t, ptrace.StatusCodeError, otelStatus) } - return res } diff --git a/pkg/translator/zipkin/zipkinv1/thrift.go b/pkg/translator/zipkin/zipkinv1/thrift.go index 51ca0cdd71f35..33326bd68ce19 100644 --- a/pkg/translator/zipkin/zipkinv1/thrift.go +++ b/pkg/translator/zipkin/zipkinv1/thrift.go @@ -23,11 +23,10 @@ import ( "math" "net" - tracepb "github.com/census-instrumentation/opencensus-proto/gen-go/trace/v1" jaegerzipkin "github.com/jaegertracing/jaeger/model/converter/thrift/zipkin" "github.com/jaegertracing/jaeger/thrift-gen/zipkincore" + "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/ptrace" - "google.golang.org/protobuf/types/known/timestamppb" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/idutils" ) @@ -40,11 +39,7 @@ func (t thriftUnmarshaler) UnmarshalTraces(buf []byte) (ptrace.Traces, error) { if err != nil { return ptrace.Traces{}, err } - tds, err := v1ThriftBatchToOCProto(spans) - if err != nil { - return ptrace.Traces{}, err - } - return toTraces(tds) + return thriftBatchToTraces(spans) } // NewThriftTracesUnmarshaler returns an unmarshaler for Zipkin Thrift. @@ -52,80 +47,58 @@ func NewThriftTracesUnmarshaler() ptrace.Unmarshaler { return thriftUnmarshaler{} } -// v1ThriftBatchToOCProto converts Zipkin v1 spans to OC Proto. -func v1ThriftBatchToOCProto(zSpans []*zipkincore.Span) ([]traceData, error) { - ocSpansAndParsedAnnotations := make([]ocSpanAndParsedAnnotations, 0, len(zSpans)) +// thriftBatchToTraces converts Zipkin v1 spans to ptrace.Traces. +func thriftBatchToTraces(zSpans []*zipkincore.Span) (ptrace.Traces, error) { + spanAndEndpoints := make([]spanAndEndpoint, 0, len(zSpans)) for _, zSpan := range zSpans { - ocSpan, parsedAnnotations := zipkinV1ThriftToOCSpan(zSpan) - ocSpansAndParsedAnnotations = append(ocSpansAndParsedAnnotations, ocSpanAndParsedAnnotations{ - ocSpan: ocSpan, - parsedAnnotations: parsedAnnotations, - }) + spanAndEndpoints = append(spanAndEndpoints, thriftToSpanAndEndpoint(zSpan)) } - return zipkinToOCProtoBatch(ocSpansAndParsedAnnotations) + return zipkinToTraces(spanAndEndpoints) } -func zipkinV1ThriftToOCSpan(zSpan *zipkincore.Span) (*tracepb.Span, *annotationParseResult) { +func thriftToSpanAndEndpoint(zSpan *zipkincore.Span) spanAndEndpoint { traceIDHigh := int64(0) if zSpan.TraceIDHigh != nil { traceIDHigh = *zSpan.TraceIDHigh } - // TODO: (@pjanotti) ideally we should error here instead of generating invalid OC proto + // TODO: (@pjanotti) ideally we should error here instead of generating invalid Traces // however per https://go.opentelemetry.io/collector/issues/349 // failures on the receivers in general are silent at this moment, so letting them // proceed for now. We should validate the traceID, spanID and parentID are good with - // OC proto requirements. + // OTLP requirements. traceID := idutils.UInt64ToTraceID(uint64(traceIDHigh), uint64(zSpan.TraceID)) spanID := idutils.UInt64ToSpanID(uint64(zSpan.ID)) - var parentID []byte + var parentID pcommon.SpanID if zSpan.ParentID != nil { - parentIDBytes := idutils.UInt64ToSpanID(uint64(*zSpan.ParentID)) - parentID = parentIDBytes[:] + parentID = idutils.UInt64ToSpanID(uint64(*zSpan.ParentID)) } - parsedAnnotations := parseZipkinV1ThriftAnnotations(zSpan.Annotations) - attributes, ocStatus, localComponent := zipkinV1ThriftBinAnnotationsToOCAttributes(zSpan.BinaryAnnotations) - if parsedAnnotations.Endpoint.ServiceName == unknownServiceName && localComponent != "" { - parsedAnnotations.Endpoint.ServiceName = localComponent + span, edpt := thriftAnnotationsToSpanAndEndpoint(zSpan.Annotations) + localComponent := thriftBinAnnotationsToSpanAttributes(span, zSpan.BinaryAnnotations) + if edpt.ServiceName == unknownServiceName && localComponent != "" { + edpt.ServiceName = localComponent } - var startTime, endTime *timestamppb.Timestamp - if zSpan.Timestamp == nil { - startTime = parsedAnnotations.EarlyAnnotationTime - endTime = parsedAnnotations.LateAnnotationTime - } else { - startTime = epochMicrosecondsToTimestamp(*zSpan.Timestamp) + if zSpan.Timestamp != nil { + span.SetStartTimestamp(epochMicrosecondsToTimestamp(*zSpan.Timestamp)) var duration int64 if zSpan.Duration != nil { duration = *zSpan.Duration } - endTime = epochMicrosecondsToTimestamp(*zSpan.Timestamp + duration) - } - - ocSpan := &tracepb.Span{ - TraceId: traceID[:], - SpanId: spanID[:], - ParentSpanId: parentID, - Status: ocStatus, - Kind: parsedAnnotations.Kind, - TimeEvents: parsedAnnotations.TimeEvents, - StartTime: startTime, - EndTime: endTime, - Attributes: attributes, - } - - if zSpan.Name != "" { - ocSpan.Name = &tracepb.TruncatableString{Value: zSpan.Name} + span.SetEndTimestamp(epochMicrosecondsToTimestamp(*zSpan.Timestamp + duration)) } - setSpanKind(ocSpan, parsedAnnotations.Kind, parsedAnnotations.ExtendedKind) + span.SetName(zSpan.Name) + span.SetTraceID(traceID) + span.SetSpanID(spanID) + span.SetParentSpanID(parentID) - return ocSpan, parsedAnnotations + return spanAndEndpoint{span: span, endpoint: edpt} } -func parseZipkinV1ThriftAnnotations(ztAnnotations []*zipkincore.Annotation) *annotationParseResult { +func thriftAnnotationsToSpanAndEndpoint(ztAnnotations []*zipkincore.Annotation) (ptrace.Span, *endpoint) { annotations := make([]*annotation, 0, len(ztAnnotations)) for _, ztAnnot := range ztAnnotations { annot := &annotation{ @@ -135,7 +108,7 @@ func parseZipkinV1ThriftAnnotations(ztAnnotations []*zipkincore.Annotation) *ann } annotations = append(annotations, annot) } - return parseZipkinV1Annotations(annotations) + return jsonAnnotationsToSpanAndEndpoint(annotations) } func toTranslatorEndpoint(e *zipkincore.Endpoint) *endpoint { @@ -160,16 +133,16 @@ func toTranslatorEndpoint(e *zipkincore.Endpoint) *endpoint { var trueByteSlice = []byte{1} -func zipkinV1ThriftBinAnnotationsToOCAttributes(ztBinAnnotations []*zipkincore.BinaryAnnotation) (attributes *tracepb.Span_Attributes, status *tracepb.Status, fallbackServiceName string) { +func thriftBinAnnotationsToSpanAttributes(span ptrace.Span, ztBinAnnotations []*zipkincore.BinaryAnnotation) string { + var fallbackServiceName string if len(ztBinAnnotations) == 0 { - return nil, nil, "" + return fallbackServiceName } sMapper := &statusMapper{} var localComponent string - attributeMap := make(map[string]*tracepb.AttributeValue) for _, binaryAnnotation := range ztBinAnnotations { - pbAttrib := &tracepb.AttributeValue{} + val := pcommon.NewValueEmpty() binAnnotationType := binaryAnnotation.AnnotationType if binaryAnnotation.Host != nil { fallbackServiceName = binaryAnnotation.Host.ServiceName @@ -177,41 +150,38 @@ func zipkinV1ThriftBinAnnotationsToOCAttributes(ztBinAnnotations []*zipkincore.B switch binaryAnnotation.AnnotationType { case zipkincore.AnnotationType_BOOL: isTrue := bytes.Equal(binaryAnnotation.Value, trueByteSlice) - pbAttrib.Value = &tracepb.AttributeValue_BoolValue{BoolValue: isTrue} + val.SetBool(isTrue) case zipkincore.AnnotationType_BYTES: bytesStr := base64.StdEncoding.EncodeToString(binaryAnnotation.Value) - pbAttrib.Value = &tracepb.AttributeValue_StringValue{ - StringValue: &tracepb.TruncatableString{Value: bytesStr}} + val.SetStr(bytesStr) case zipkincore.AnnotationType_DOUBLE: if d, err := bytesFloat64ToFloat64(binaryAnnotation.Value); err != nil { - pbAttrib.Value = strAttributeForError(err) + strAttributeForError(val, err) } else { - pbAttrib.Value = &tracepb.AttributeValue_DoubleValue{DoubleValue: d} + val.SetDouble(d) } case zipkincore.AnnotationType_I16: if i, err := bytesInt16ToInt64(binaryAnnotation.Value); err != nil { - pbAttrib.Value = strAttributeForError(err) + strAttributeForError(val, err) } else { - pbAttrib.Value = &tracepb.AttributeValue_IntValue{IntValue: i} + val.SetInt(i) } case zipkincore.AnnotationType_I32: if i, err := bytesInt32ToInt64(binaryAnnotation.Value); err != nil { - pbAttrib.Value = strAttributeForError(err) + strAttributeForError(val, err) } else { - pbAttrib.Value = &tracepb.AttributeValue_IntValue{IntValue: i} + val.SetInt(i) } case zipkincore.AnnotationType_I64: if i, err := bytesInt64ToInt64(binaryAnnotation.Value); err != nil { - pbAttrib.Value = strAttributeForError(err) + strAttributeForError(val, err) } else { - pbAttrib.Value = &tracepb.AttributeValue_IntValue{IntValue: i} + val.SetInt(i) } case zipkincore.AnnotationType_STRING: - pbAttrib.Value = &tracepb.AttributeValue_StringValue{ - StringValue: &tracepb.TruncatableString{Value: string(binaryAnnotation.Value)}} + val.SetStr(string(binaryAnnotation.Value)) default: - err := fmt.Errorf("unknown zipkin v1 binary annotation type (%d)", int(binAnnotationType)) - pbAttrib.Value = strAttributeForError(err) + strAttributeForError(val, fmt.Errorf("unknown zipkin v1 binary annotation type (%d)", int(binAnnotationType))) } key := binaryAnnotation.Key @@ -221,27 +191,19 @@ func zipkinV1ThriftBinAnnotationsToOCAttributes(ztBinAnnotations []*zipkincore.B localComponent = string(binaryAnnotation.Value) } - if drop := sMapper.fromAttribute(key, pbAttrib); drop { + if drop := sMapper.fromAttribute(key, val); drop { continue } - attributeMap[key] = pbAttrib - } - - status = sMapper.ocStatus() - - if len(attributeMap) == 0 { - return nil, status, "" + val.CopyTo(span.Attributes().PutEmpty(key)) } if fallbackServiceName == "" { fallbackServiceName = localComponent } - attributes = &tracepb.Span_Attributes{ - AttributeMap: attributeMap, - } - return attributes, status, fallbackServiceName + sMapper.status(span.Status()) + return fallbackServiceName } var errNotEnoughBytes = errors.New("not enough bytes representing the number") @@ -279,10 +241,6 @@ func bytesFloat64ToFloat64(b []byte) (float64, error) { return math.Float64frombits(bits), nil } -func strAttributeForError(err error) *tracepb.AttributeValue_StringValue { - return &tracepb.AttributeValue_StringValue{ - StringValue: &tracepb.TruncatableString{ - Value: "<" + err.Error() + ">", - }, - } +func strAttributeForError(dest pcommon.Value, err error) { + dest.SetStr("<" + err.Error() + ">") } diff --git a/pkg/translator/zipkin/zipkinv1/thrift_test.go b/pkg/translator/zipkin/zipkinv1/thrift_test.go index 074d60b4f6eef..ac93697c502a1 100644 --- a/pkg/translator/zipkin/zipkinv1/thrift_test.go +++ b/pkg/translator/zipkin/zipkinv1/thrift_test.go @@ -19,28 +19,41 @@ import ( "encoding/json" "math" "os" - "sort" "testing" - tracepb "github.com/census-instrumentation/opencensus-proto/gen-go/trace/v1" - "github.com/google/go-cmp/cmp" "github.com/jaegertracing/jaeger/model/converter/thrift/zipkin" "github.com/jaegertracing/jaeger/thrift-gen/zipkincore" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.opentelemetry.io/collector/pdata/pcommon" + "go.opentelemetry.io/collector/pdata/ptrace" conventions "go.opentelemetry.io/collector/semconv/v1.6.1" - "google.golang.org/protobuf/testing/protocmp" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/tracetranslator" ) -// compareTraceData compares got to want while ignoring order. Both are modified in place. -func compareTraceData(t *testing.T, got []traceData, want []traceData) { - sortTraceByNodeName(want) - sortTraceByNodeName(got) - if diff := cmp.Diff(want, got, protocmp.Transform()); diff != "" { - t.Errorf("Unexpected difference:\n%v", diff) +// compareTraces compares got to want while ignoring order. Both are modified in place. +func compareTraces(t *testing.T, want ptrace.Traces, got ptrace.Traces) { + require.Equal(t, mapperTraces(t, want), mapperTraces(t, got)) +} + +func mapperTraces(t *testing.T, td ptrace.Traces) map[string]map[string]ptrace.Span { + ret := map[string]map[string]ptrace.Span{} + for i := 0; i < td.ResourceSpans().Len(); i++ { + rs := td.ResourceSpans().At(i) + service, found := rs.Resource().Attributes().Get(conventions.AttributeServiceName) + require.True(t, found) + sps, ok := ret[service.Str()] + if !ok { + sps = map[string]ptrace.Span{} + ret[service.Str()] = map[string]ptrace.Span{} + } + spans := rs.ScopeSpans().At(0).Spans() + for j := 0; j < spans.Len(); j++ { + sps[spans.At(j).Name()] = spans.At(j) + } } + return ret } func TestV1ThriftToTraces(t *testing.T) { @@ -64,22 +77,24 @@ func TestZipkinThriftFallbackToLocalComponent(t *testing.T) { err = json.Unmarshal(blob, &ztSpans) require.NoError(t, err, "Failed to unmarshal json into zipkin v1 thrift") - reqs, err := v1ThriftBatchToOCProto(ztSpans) + reqs, err := thriftBatchToTraces(ztSpans) require.NoError(t, err, "Failed to translate zipkinv1 thrift to OC proto") - require.Equal(t, 2, len(reqs), "Invalid trace service requests count") - - // Ensure the order of nodes - sort.Slice(reqs, func(i, j int) bool { - return reqs[i].Node.ServiceInfo.Name < reqs[j].Node.ServiceInfo.Name - }) + require.Equal(t, 2, reqs.ResourceSpans().Len(), "Invalid trace service requests count") // First span didn't have a host/endpoint to give service name, use the local component. - got := reqs[0].Node.ServiceInfo.Name - require.Equal(t, "myLocalComponent", got) - - // Second span have a host/endpoint to give service name, do not use local component. - got = reqs[1].Node.ServiceInfo.Name - require.Equal(t, "myServiceName", got) + gotFirst, found := reqs.ResourceSpans().At(0).Resource().Attributes().Get(conventions.AttributeServiceName) + require.True(t, found) + + gotSecond, found := reqs.ResourceSpans().At(1).Resource().Attributes().Get(conventions.AttributeServiceName) + require.True(t, found) + + if gotFirst.AsString() == "myLocalComponent" { + require.Equal(t, "myLocalComponent", gotFirst.Str()) + require.Equal(t, "myServiceName", gotSecond.Str()) + } else { + require.Equal(t, "myServiceName", gotFirst.Str()) + require.Equal(t, "myLocalComponent", gotSecond.Str()) + } } func TestV1ThriftToOCProto(t *testing.T) { @@ -90,10 +105,10 @@ func TestV1ThriftToOCProto(t *testing.T) { err = json.Unmarshal(blob, &ztSpans) require.NoError(t, err, "Failed to unmarshal json into zipkin v1 thrift") - got, err := v1ThriftBatchToOCProto(ztSpans) + got, err := thriftBatchToTraces(ztSpans) require.NoError(t, err, "Failed to translate zipkinv1 thrift to OC proto") - compareTraceData(t, got, ocBatchesFromZipkinV1) + compareTraces(t, got, tracesFromZipkinV1) } func BenchmarkV1ThriftToOCProto(b *testing.B) { @@ -105,79 +120,88 @@ func BenchmarkV1ThriftToOCProto(b *testing.B) { require.NoError(b, err, "Failed to unmarshal json into zipkin v1 thrift") for n := 0; n < b.N; n++ { - _, err = v1ThriftBatchToOCProto(ztSpans) + _, err = thriftBatchToTraces(ztSpans) require.NoError(b, err) } } func TestZipkinThriftAnnotationsToOCStatus(t *testing.T) { type test struct { + name string haveTags []*zipkincore.BinaryAnnotation - wantAttributes *tracepb.Span_Attributes - wantStatus *tracepb.Status + wantAttributes pcommon.Map + wantStatus ptrace.SpanStatus } cases := []test{ - // too large code for OC { + name: "too large code for OC", haveTags: []*zipkincore.BinaryAnnotation{{ Key: conventions.OtelStatusCode, Value: uint64ToBytes(math.MaxInt64), AnnotationType: zipkincore.AnnotationType_I64, }}, - wantAttributes: nil, - wantStatus: nil, + wantAttributes: pcommon.NewMap(), + wantStatus: ptrace.NewSpanStatus(), }, - // only status.code tag { + name: "census.status_code int64", haveTags: []*zipkincore.BinaryAnnotation{{ - Key: conventions.OtelStatusCode, + Key: tagZipkinCensusCode, Value: uint64ToBytes(5), AnnotationType: zipkincore.AnnotationType_I64, }}, - wantAttributes: nil, - wantStatus: &tracepb.Status{ - Code: 5, - }, + wantAttributes: pcommon.NewMap(), + wantStatus: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + return ret + }(), }, { + name: "census.status_code int32", haveTags: []*zipkincore.BinaryAnnotation{{ - Key: conventions.OtelStatusCode, + Key: tagZipkinCensusCode, Value: uint32ToBytes(6), AnnotationType: zipkincore.AnnotationType_I32, }}, - wantAttributes: nil, - wantStatus: &tracepb.Status{ - Code: 6, - }, + wantAttributes: pcommon.NewMap(), + wantStatus: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + return ret + }(), }, { + name: "census.status_code int16", haveTags: []*zipkincore.BinaryAnnotation{{ - Key: conventions.OtelStatusCode, + Key: tagZipkinCensusCode, Value: uint16ToBytes(7), AnnotationType: zipkincore.AnnotationType_I16, }}, - wantAttributes: nil, - wantStatus: &tracepb.Status{ - Code: 7, - }, + wantAttributes: pcommon.NewMap(), + wantStatus: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + return ret + }(), }, - // only status.message tag { + name: "only status.message tag", haveTags: []*zipkincore.BinaryAnnotation{{ Key: conventions.OtelStatusDescription, Value: []byte("Forbidden"), AnnotationType: zipkincore.AnnotationType_STRING, }}, - wantAttributes: nil, - wantStatus: nil, + wantAttributes: pcommon.NewMap(), + wantStatus: ptrace.NewSpanStatus(), }, - // both status.code and status.message { + name: "both status.code and status.message", haveTags: []*zipkincore.BinaryAnnotation{ { Key: conventions.OtelStatusCode, - Value: uint32ToBytes(13), + Value: uint32ToBytes(2), AnnotationType: zipkincore.AnnotationType_I32, }, { @@ -186,15 +210,17 @@ func TestZipkinThriftAnnotationsToOCStatus(t *testing.T) { AnnotationType: zipkincore.AnnotationType_STRING, }, }, - wantAttributes: nil, - wantStatus: &tracepb.Status{ - Code: 13, - Message: "Forbidden", - }, + wantAttributes: pcommon.NewMap(), + wantStatus: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + ret.SetMessage("Forbidden") + return ret + }(), }, - // http status.code { + name: "http status.code", haveTags: []*zipkincore.BinaryAnnotation{ { Key: "http.status_code", @@ -207,28 +233,22 @@ func TestZipkinThriftAnnotationsToOCStatus(t *testing.T) { AnnotationType: zipkincore.AnnotationType_STRING, }, }, - wantAttributes: &tracepb.Span_Attributes{ - AttributeMap: map[string]*tracepb.AttributeValue{ - conventions.AttributeHTTPStatusCode: { - Value: &tracepb.AttributeValue_IntValue{ - IntValue: 404, - }, - }, - tracetranslator.TagHTTPStatusMsg: { - Value: &tracepb.AttributeValue_StringValue{ - StringValue: &tracepb.TruncatableString{Value: "NotFound"}, - }, - }, - }, - }, - wantStatus: &tracepb.Status{ - Code: 5, - Message: "NotFound", - }, + wantAttributes: func() pcommon.Map { + ret := pcommon.NewMap() + ret.PutInt(conventions.AttributeHTTPStatusCode, 404) + ret.PutString(tracetranslator.TagHTTPStatusMsg, "NotFound") + return ret + }(), + wantStatus: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + ret.SetMessage("NotFound") + return ret + }(), }, - // http and oc { + name: "http and otel", haveTags: []*zipkincore.BinaryAnnotation{ { Key: "http.status_code", @@ -242,7 +262,7 @@ func TestZipkinThriftAnnotationsToOCStatus(t *testing.T) { }, { Key: conventions.OtelStatusCode, - Value: uint32ToBytes(13), + Value: uint32ToBytes(2), AnnotationType: zipkincore.AnnotationType_I32, }, { @@ -251,28 +271,22 @@ func TestZipkinThriftAnnotationsToOCStatus(t *testing.T) { AnnotationType: zipkincore.AnnotationType_STRING, }, }, - wantAttributes: &tracepb.Span_Attributes{ - AttributeMap: map[string]*tracepb.AttributeValue{ - conventions.AttributeHTTPStatusCode: { - Value: &tracepb.AttributeValue_IntValue{ - IntValue: 404, - }, - }, - tracetranslator.TagHTTPStatusMsg: { - Value: &tracepb.AttributeValue_StringValue{ - StringValue: &tracepb.TruncatableString{Value: "NotFound"}, - }, - }, - }, - }, - wantStatus: &tracepb.Status{ - Code: 13, - Message: "Forbidden", - }, + wantAttributes: func() pcommon.Map { + ret := pcommon.NewMap() + ret.PutInt(conventions.AttributeHTTPStatusCode, 404) + ret.PutString(tracetranslator.TagHTTPStatusMsg, "NotFound") + return ret + }(), + wantStatus: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + ret.SetMessage("Forbidden") + return ret + }(), }, - // http and only oc code { + name: "http and only otel code", haveTags: []*zipkincore.BinaryAnnotation{ { Key: "http.status_code", @@ -286,30 +300,24 @@ func TestZipkinThriftAnnotationsToOCStatus(t *testing.T) { }, { Key: conventions.OtelStatusCode, - Value: uint32ToBytes(14), + Value: uint32ToBytes(2), AnnotationType: zipkincore.AnnotationType_I32, }, }, - wantAttributes: &tracepb.Span_Attributes{ - AttributeMap: map[string]*tracepb.AttributeValue{ - conventions.AttributeHTTPStatusCode: { - Value: &tracepb.AttributeValue_IntValue{ - IntValue: 404, - }, - }, - tracetranslator.TagHTTPStatusMsg: { - Value: &tracepb.AttributeValue_StringValue{ - StringValue: &tracepb.TruncatableString{Value: "NotFound"}, - }, - }, - }, - }, - wantStatus: &tracepb.Status{ - Code: 14, - }, + wantAttributes: func() pcommon.Map { + ret := pcommon.NewMap() + ret.PutInt(conventions.AttributeHTTPStatusCode, 404) + ret.PutString(tracetranslator.TagHTTPStatusMsg, "NotFound") + return ret + }(), + wantStatus: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + return ret + }(), }, - // http and only oc message { + name: "http and only oc message", haveTags: []*zipkincore.BinaryAnnotation{ { Key: "http.status_code", @@ -327,28 +335,22 @@ func TestZipkinThriftAnnotationsToOCStatus(t *testing.T) { AnnotationType: zipkincore.AnnotationType_STRING, }, }, - wantAttributes: &tracepb.Span_Attributes{ - AttributeMap: map[string]*tracepb.AttributeValue{ - conventions.AttributeHTTPStatusCode: { - Value: &tracepb.AttributeValue_IntValue{ - IntValue: 404, - }, - }, - tracetranslator.TagHTTPStatusMsg: { - Value: &tracepb.AttributeValue_StringValue{ - StringValue: &tracepb.TruncatableString{Value: "NotFound"}, - }, - }, - }, - }, - wantStatus: &tracepb.Status{ - Code: 5, - Message: "NotFound", - }, + wantAttributes: func() pcommon.Map { + ret := pcommon.NewMap() + ret.PutInt(conventions.AttributeHTTPStatusCode, 404) + ret.PutString(tracetranslator.TagHTTPStatusMsg, "NotFound") + return ret + }(), + wantStatus: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + ret.SetMessage("NotFound") + return ret + }(), }, - // census tags { + name: "census tags", haveTags: []*zipkincore.BinaryAnnotation{ { Key: "census.status_code", @@ -361,15 +363,17 @@ func TestZipkinThriftAnnotationsToOCStatus(t *testing.T) { AnnotationType: zipkincore.AnnotationType_STRING, }, }, - wantAttributes: nil, - wantStatus: &tracepb.Status{ - Code: 18, - Message: "RPCError", - }, + wantAttributes: pcommon.NewMap(), + wantStatus: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + ret.SetMessage("RPCError") + return ret + }(), }, - // census tags priority over others { + name: "census tags priority over others", haveTags: []*zipkincore.BinaryAnnotation{ { Key: "census.status_code", @@ -402,48 +406,41 @@ func TestZipkinThriftAnnotationsToOCStatus(t *testing.T) { AnnotationType: zipkincore.AnnotationType_I32, }, }, - wantAttributes: &tracepb.Span_Attributes{ - AttributeMap: map[string]*tracepb.AttributeValue{ - conventions.AttributeHTTPStatusCode: { - Value: &tracepb.AttributeValue_IntValue{ - IntValue: 404, - }, - }, - tracetranslator.TagHTTPStatusMsg: { - Value: &tracepb.AttributeValue_StringValue{ - StringValue: &tracepb.TruncatableString{Value: "NotFound"}, - }, - }, - }, - }, - wantStatus: &tracepb.Status{ - Code: 18, - Message: "RPCError", - }, + wantAttributes: func() pcommon.Map { + ret := pcommon.NewMap() + ret.PutInt(conventions.AttributeHTTPStatusCode, 404) + ret.PutString(tracetranslator.TagHTTPStatusMsg, "NotFound") + return ret + }(), + wantStatus: func() ptrace.SpanStatus { + ret := ptrace.NewSpanStatus() + ret.SetCode(ptrace.StatusCodeError) + ret.SetMessage("RPCError") + return ret + }(), }, } - for i, c := range cases { - zSpans := []*zipkincore.Span{{ - ID: 1, - TraceID: 1, - BinaryAnnotations: c.haveTags, - }} - gb, err := v1ThriftBatchToOCProto(zSpans) - if err != nil { - t.Errorf("#%d: Unexpected error: %v", i, err) - continue - } - gs := gb[0].Spans[0] - require.Equal(t, c.wantAttributes, gs.Attributes, "Unsuccessful conversion %d", i) - require.Equal(t, c.wantStatus, gs.Status, "Unsuccessful conversion %d", i) + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + zSpans := []*zipkincore.Span{{ + ID: 1, + TraceID: 1, + BinaryAnnotations: c.haveTags, + }} + td, err := thriftBatchToTraces(zSpans) + require.NoError(t, err) + gs := td.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0) + require.Equal(t, c.wantAttributes.Sort(), gs.Attributes().Sort()) + require.Equal(t, c.wantStatus, gs.Status()) + }) } } -func TestThriftHTTPToGRPCStatusCode(t *testing.T) { +func TestThriftHTTPToStatusCode(t *testing.T) { for i := int32(100); i <= 600; i++ { - wantStatus := ocStatusCodeFromHTTP(i) - gb, err := v1ThriftBatchToOCProto([]*zipkincore.Span{{ + wantStatus := statusCodeFromHTTP(i) + td, err := thriftBatchToTraces([]*zipkincore.Span{{ ID: 1, TraceID: 1, BinaryAnnotations: []*zipkincore.BinaryAnnotation{ @@ -454,12 +451,9 @@ func TestThriftHTTPToGRPCStatusCode(t *testing.T) { }, }, }}) - if err != nil { - t.Errorf("#%d: Unexpected error: %v", i, err) - continue - } - gs := gb[0].Spans[0] - require.Equal(t, wantStatus, gs.Status.Code, "Unsuccessful conversion %d", i) + require.NoError(t, err) + gs := td.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0) + require.EqualValues(t, wantStatus, gs.Status().Code(), "Unsuccessful conversion %d", i) } } diff --git a/pkg/translator/zipkin/zipkinv1/to_translator.go b/pkg/translator/zipkin/zipkinv1/to_translator.go deleted file mode 100644 index 9d20c6ea79eb9..0000000000000 --- a/pkg/translator/zipkin/zipkinv1/to_translator.go +++ /dev/null @@ -1,32 +0,0 @@ -// 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 zipkinv1 // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/zipkin/zipkinv1" - -import ( - "go.opentelemetry.io/collector/pdata/ptrace" - - internaldata "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/opencensus" -) - -func toTraces(ocTraces []traceData) (ptrace.Traces, error) { - td := ptrace.NewTraces() - - for _, trace := range ocTraces { - tmp := internaldata.OCToTraces(trace.Node, trace.Resource, trace.Spans) - tmp.ResourceSpans().MoveAndAppendTo(td.ResourceSpans()) - } - - return td, nil -} diff --git a/receiver/kafkareceiver/go.mod b/receiver/kafkareceiver/go.mod index 537f870e2e9e9..03c88d17981b4 100644 --- a/receiver/kafkareceiver/go.mod +++ b/receiver/kafkareceiver/go.mod @@ -23,12 +23,10 @@ require ( require ( github.com/aws/aws-sdk-go v1.44.106 // indirect github.com/cenkalti/backoff/v4 v4.1.3 // indirect - github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/eapache/go-resiliency v1.3.0 // indirect github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 // indirect github.com/eapache/queue v1.1.0 // indirect - github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/hashicorp/errwrap v1.0.0 // indirect @@ -48,7 +46,6 @@ require ( github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/opencensus v0.61.0 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect github.com/pierrec/lz4/v4 v4.1.15 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect diff --git a/receiver/kafkareceiver/go.sum b/receiver/kafkareceiver/go.sum index e440540096b95..28a831c4da9a6 100644 --- a/receiver/kafkareceiver/go.sum +++ b/receiver/kafkareceiver/go.sum @@ -72,8 +72,6 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB github.com/cenkalti/backoff/v4 v4.1.3 h1:cFAlzYUlVYDysBEH2T5hyJZMh3+5+WCBvSnK6Q8UtC4= github.com/cenkalti/backoff/v4 v4.1.3/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/census-instrumentation/opencensus-proto v0.4.1 h1:iKLQ0xPNFxR/2hzXZMrBo8f1j86j5WHzznCCQxV/b8g= -github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= @@ -139,7 +137,6 @@ github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4er github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= -github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= @@ -200,9 +197,7 @@ github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7 github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= -github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 h1:lLT7ZLSzGLI08vc9cpd+tYmNWjdKDqyr/2L+f6U12Fk= github.com/hashicorp/consul/api v1.13.0/go.mod h1:ZlVrynguJKcYr54zGaDbaL3fOvKC9m72FhPvA8T35KQ= github.com/hashicorp/consul/sdk v0.8.0/go.mod h1:GBvyrGALthsZObzUGsfgHZQDXjg4lOjagTIwIR1vPms= github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= diff --git a/receiver/pulsarreceiver/go.mod b/receiver/pulsarreceiver/go.mod index b9ff0234cc59f..caeb6dbe2058b 100644 --- a/receiver/pulsarreceiver/go.mod +++ b/receiver/pulsarreceiver/go.mod @@ -24,7 +24,6 @@ require ( github.com/apache/pulsar-client-go/oauth2 v0.0.0-20220120090717-25e59572242e // indirect github.com/ardielle/ardielle-go v1.5.2 // indirect github.com/beorn7/perks v1.0.1 // indirect - github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect github.com/danieljoos/wincred v1.0.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect @@ -32,7 +31,6 @@ require ( github.com/frankban/quicktest v1.14.2 // indirect github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect - github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c // indirect @@ -50,7 +48,6 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/mtibben/percent v0.2.1 // indirect github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.61.0 // indirect - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/opencensus v0.61.0 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect github.com/pierrec/lz4 v2.6.1+incompatible // indirect github.com/pkg/errors v0.9.1 // indirect @@ -63,7 +60,6 @@ require ( github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect github.com/uber/jaeger-lib v2.4.1+incompatible // indirect - go.opencensus.io v0.23.0 // indirect go.opentelemetry.io/otel v1.10.0 // indirect go.opentelemetry.io/otel/metric v0.32.1 // indirect go.opentelemetry.io/otel/trace v1.10.0 // indirect diff --git a/receiver/pulsarreceiver/go.sum b/receiver/pulsarreceiver/go.sum index 41ab10cfba30e..66792208f4e5c 100644 --- a/receiver/pulsarreceiver/go.sum +++ b/receiver/pulsarreceiver/go.sum @@ -88,8 +88,6 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM= github.com/bmizerany/perks v0.0.0-20141205001514-d9a9656a3a4b/go.mod h1:ac9efd0D1fsDb3EJvhqgXRbFx7bs2wqZ10HQPeU8U/Q= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/census-instrumentation/opencensus-proto v0.4.1 h1:iKLQ0xPNFxR/2hzXZMrBo8f1j86j5WHzznCCQxV/b8g= -github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= @@ -167,8 +165,6 @@ github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfU github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= -github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= @@ -240,9 +236,7 @@ github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7 github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= -github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 h1:lLT7ZLSzGLI08vc9cpd+tYmNWjdKDqyr/2L+f6U12Fk= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c h1:6rhixN/i8ZofjG1Y75iExal34USq5p+wiN1tpie8IrU= github.com/gsterjov/go-libsecret v0.0.0-20161001094733-a6f4afe4910c/go.mod h1:NMPJylDgVpX0MLRlPy15sqSwOFv/U1GZ2m21JhFfek0= github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= @@ -521,7 +515,6 @@ go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= -go.opencensus.io v0.23.0 h1:gqCw0LfLxScz8irSi8exQc7fyQ0fKQU/qnC/X8+V/1M= go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= go.opentelemetry.io/collector v0.61.0 h1:lvuhmlskup6Z3AfQKZwuRk43jRClB+1FkwjGXRoxhfs= go.opentelemetry.io/collector v0.61.0/go.mod h1:515eomlUIwLEXTBwLAEEtl2HPreJy5xtv//LYMk/SZE= diff --git a/receiver/zipkinreceiver/go.mod b/receiver/zipkinreceiver/go.mod index 3207153e8822a..64bf7797111af 100644 --- a/receiver/zipkinreceiver/go.mod +++ b/receiver/zipkinreceiver/go.mod @@ -16,13 +16,11 @@ require ( require ( github.com/apache/thrift v0.17.0 // indirect - github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/felixge/httpsnoop v1.0.3 // indirect github.com/go-logr/logr v1.2.3 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/gogo/protobuf v1.3.2 // indirect - github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.2 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/json-iterator/go v1.1.12 // indirect @@ -33,7 +31,6 @@ require ( github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/opencensus v0.61.0 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rs/cors v1.8.2 // indirect diff --git a/receiver/zipkinreceiver/go.sum b/receiver/zipkinreceiver/go.sum index 4e3406683c04e..36c4fbed907c6 100644 --- a/receiver/zipkinreceiver/go.sum +++ b/receiver/zipkinreceiver/go.sum @@ -32,8 +32,6 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/census-instrumentation/opencensus-proto v0.4.1 h1:iKLQ0xPNFxR/2hzXZMrBo8f1j86j5WHzznCCQxV/b8g= -github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= @@ -90,7 +88,6 @@ github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69 github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= -github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -128,9 +125,7 @@ github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB7 github.com/gorilla/securecookie v1.1.1/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4= github.com/gorilla/sessions v1.2.1/go.mod h1:dk2InVEVJ0sfLlnXv9EAgkf6ecYs/i80K/zI+bUmuGM= github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= -github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 h1:lLT7ZLSzGLI08vc9cpd+tYmNWjdKDqyr/2L+f6U12Fk= github.com/hashicorp/consul/api v1.13.0/go.mod h1:ZlVrynguJKcYr54zGaDbaL3fOvKC9m72FhPvA8T35KQ= github.com/hashicorp/consul/sdk v0.8.0/go.mod h1:GBvyrGALthsZObzUGsfgHZQDXjg4lOjagTIwIR1vPms= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= diff --git a/unreleased/zipkinv1-translator.yaml b/unreleased/zipkinv1-translator.yaml new file mode 100755 index 0000000000000..4679ac13d3da3 --- /dev/null +++ b/unreleased/zipkinv1-translator.yaml @@ -0,0 +1,11 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: pkg/translator/zipkin + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Change zipkin V1 conversion to use pdata. + +# One or more tracking issues related to the change +issues: [ 14592 ]