diff --git a/CHANGELOG.md b/CHANGELOG.md index 690bc7bdc33..a262e1c86b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,6 +76,11 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - The `go.opentelemetry.io/otel/exporters/otlp/internal` package is deprecated. (#4421) - The `go.opentelemetry.io/otel/exporters/otlp/internal/envconfig` package is deprecated. (#4421) - The `go.opentelemetry.io/otel/exporters/otlp/internal/retry` package is deprecated. (#4421) +- The `go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal` package is deprecated. (#4425) +- The `go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/envconfig` package is deprecated. (#4425) +- The `go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/otlpconfig` package is deprecated. (#4425) +- The `go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/otlptracetest` package is deprecated. (#4425) +- The `go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/retry` package is deprecated. (#4425) ## [1.16.0/0.39.0] 2023-05-18 diff --git a/internal/shared/otlp/otlptrace/tracetransform/resource.go.tmpl b/exporters/otlp/otlptrace/internal/doc.go similarity index 56% rename from internal/shared/otlp/otlptrace/tracetransform/resource.go.tmpl rename to exporters/otlp/otlptrace/internal/doc.go index 1d2d26ed88a..d1c019d8bb2 100644 --- a/internal/shared/otlp/otlptrace/tracetransform/resource.go.tmpl +++ b/exporters/otlp/otlptrace/internal/doc.go @@ -1,6 +1,3 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/tracetransform/resource.go.tmpl - // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,17 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -package tracetransform - -import ( - "go.opentelemetry.io/otel/sdk/resource" - resourcepb "go.opentelemetry.io/proto/otlp/resource/v1" -) - -// Resource transforms a Resource into an OTLP Resource. -func Resource(r *resource.Resource) *resourcepb.Resource { - if r == nil { - return nil - } - return &resourcepb.Resource{Attributes: ResourceAttributes(r)} -} +// Package internal contains common functionality for all OTLP trace exporters. +// +// Deprecated: package internal exists for historical compatibility, it should +// not be used. +package internal // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal" diff --git a/internal/shared/otlp/otlptrace/tracetransform/instrumentation.go.tmpl b/exporters/otlp/otlptrace/internal/envconfig/doc.go similarity index 55% rename from internal/shared/otlp/otlptrace/tracetransform/instrumentation.go.tmpl rename to exporters/otlp/otlptrace/internal/envconfig/doc.go index 3e43a81474e..f2887ee8ffb 100644 --- a/internal/shared/otlp/otlptrace/tracetransform/instrumentation.go.tmpl +++ b/exporters/otlp/otlptrace/internal/envconfig/doc.go @@ -1,6 +1,3 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/tracetransform/instrumentation.go.tmpl - // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,19 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -package tracetransform - -import ( - "go.opentelemetry.io/otel/sdk/instrumentation" - commonpb "go.opentelemetry.io/proto/otlp/common/v1" -) - -func InstrumentationScope(il instrumentation.Scope) *commonpb.InstrumentationScope { - if il == (instrumentation.Scope{}) { - return nil - } - return &commonpb.InstrumentationScope{ - Name: il.Name, - Version: il.Version, - } -} +// Package envconfig contains common functionality for all OTLP trace exporters +// to handle environment variable configuration. +// +// Deprecated: package envconfig exists for historical compatibility, it should +// not be used. +package envconfig // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/envconfig" diff --git a/exporters/otlp/otlptrace/internal/envconfig/envconfig.go b/exporters/otlp/otlptrace/internal/envconfig/envconfig.go index b1db08f29c4..04d87af9e59 100644 --- a/exporters/otlp/otlptrace/internal/envconfig/envconfig.go +++ b/exporters/otlp/otlptrace/internal/envconfig/envconfig.go @@ -1,6 +1,3 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/envconfig/envconfig.go.tmpl - // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/exporters/otlp/otlptrace/internal/envconfig/envconfig_test.go b/exporters/otlp/otlptrace/internal/envconfig/envconfig_test.go index cec506208d5..0c959a1f3fd 100644 --- a/exporters/otlp/otlptrace/internal/envconfig/envconfig_test.go +++ b/exporters/otlp/otlptrace/internal/envconfig/envconfig_test.go @@ -1,6 +1,3 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/envconfig/envconfig_test.go.tmpl - // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/exporters/otlp/otlptrace/internal/gen.go b/exporters/otlp/otlptrace/internal/gen.go deleted file mode 100644 index 7b9684c2679..00000000000 --- a/exporters/otlp/otlptrace/internal/gen.go +++ /dev/null @@ -1,43 +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 internal // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal" - -//go:generate gotmpl --body=../../../../internal/shared/otlp/otlptrace/header.go.tmpl "--data={}" --out=header.go -//go:generate gotmpl --body=../../../../internal/shared/otlp/otlptrace/header_test.go.tmpl "--data={}" --out=header_test.go - -//go:generate gotmpl --body=../../../../internal/shared/otlp/envconfig/envconfig.go.tmpl "--data={}" --out=envconfig/envconfig.go -//go:generate gotmpl --body=../../../../internal/shared/otlp/envconfig/envconfig_test.go.tmpl "--data={}" --out=envconfig/envconfig_test.go - -//go:generate gotmpl --body=../../../../internal/shared/otlp/otlptrace/otlpconfig/envconfig.go.tmpl "--data={\"envconfigImportPath\": \"go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/envconfig\"}" --out=otlpconfig/envconfig.go -//go:generate gotmpl --body=../../../../internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl "--data={\"retryImportPath\": \"go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/retry\"}" --out=otlpconfig/options.go -//go:generate gotmpl --body=../../../../internal/shared/otlp/otlptrace/otlpconfig/options_test.go.tmpl "--data={\"envconfigImportPath\": \"go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/envconfig\"}" --out=otlpconfig/options_test.go -//go:generate gotmpl --body=../../../../internal/shared/otlp/otlptrace/otlpconfig/optiontypes.go.tmpl "--data={}" --out=otlpconfig/optiontypes.go -//go:generate gotmpl --body=../../../../internal/shared/otlp/otlptrace/otlpconfig/tls.go.tmpl "--data={}" --out=otlpconfig/tls.go - -//go:generate gotmpl --body=../../../../internal/shared/otlp/otlptrace/otlptracetest/client.go.tmpl "--data={}" --out=otlptracetest/client.go -//go:generate gotmpl --body=../../../../internal/shared/otlp/otlptrace/otlptracetest/collector.go.tmpl "--data={}" --out=otlptracetest/collector.go -//go:generate gotmpl --body=../../../../internal/shared/otlp/otlptrace/otlptracetest/data.go.tmpl "--data={}" --out=otlptracetest/data.go -//go:generate gotmpl --body=../../../../internal/shared/otlp/otlptrace/otlptracetest/otlptest.go.tmpl "--data={}" --out=otlptracetest/otlptest.go - -//go:generate gotmpl --body=../../../../internal/shared/otlp/retry/retry.go.tmpl "--data={}" --out=retry/retry.go -//go:generate gotmpl --body=../../../../internal/shared/otlp/retry/retry_test.go.tmpl "--data={}" --out=retry/retry_test.go - -//go:generate gotmpl --body=../../../../internal/shared/otlp/otlptrace/tracetransform/attribute.go.tmpl "--data={}" --out=tracetransform/attribute.go -//go:generate gotmpl --body=../../../../internal/shared/otlp/otlptrace/tracetransform/attribute_test.go.tmpl "--data={}" --out=tracetransform/attribute_test.go -//go:generate gotmpl --body=../../../../internal/shared/otlp/otlptrace/tracetransform/instrumentation.go.tmpl "--data={}" --out=tracetransform/instrumentation.go -//go:generate gotmpl --body=../../../../internal/shared/otlp/otlptrace/tracetransform/resource.go.tmpl "--data={}" --out=tracetransform/resource.go -//go:generate gotmpl --body=../../../../internal/shared/otlp/otlptrace/tracetransform/resource_test.go.tmpl "--data={}" --out=tracetransform/resource_test.go -//go:generate gotmpl --body=../../../../internal/shared/otlp/otlptrace/tracetransform/span.go.tmpl "--data={}" --out=tracetransform/span.go -//go:generate gotmpl --body=../../../../internal/shared/otlp/otlptrace/tracetransform/span_test.go.tmpl "--data={}" --out=tracetransform/span_test.go diff --git a/exporters/otlp/otlptrace/internal/header.go b/exporters/otlp/otlptrace/internal/header.go index 44cea4cbd9f..65694a9019a 100644 --- a/exporters/otlp/otlptrace/internal/header.go +++ b/exporters/otlp/otlptrace/internal/header.go @@ -1,6 +1,3 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/header.go.tmpl - // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/exporters/otlp/otlptrace/internal/header_test.go b/exporters/otlp/otlptrace/internal/header_test.go index 4c80b9c28f8..d93340fc0d6 100644 --- a/exporters/otlp/otlptrace/internal/header_test.go +++ b/exporters/otlp/otlptrace/internal/header_test.go @@ -1,6 +1,3 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/header_test.go.tmpl - // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/exporters/otlp/otlptrace/internal/otlpconfig/doc.go b/exporters/otlp/otlptrace/internal/otlpconfig/doc.go new file mode 100644 index 00000000000..41047e4de95 --- /dev/null +++ b/exporters/otlp/otlptrace/internal/otlpconfig/doc.go @@ -0,0 +1,20 @@ +// 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 otlpconfig contains common functionality for configuring all OTLP +// trace exporters. +// +// Deprecated: package otlpconfig exists for historical compatibility, it +// should not be used. +package otlpconfig // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/otlpconfig" diff --git a/exporters/otlp/otlptrace/internal/otlpconfig/envconfig.go b/exporters/otlp/otlptrace/internal/otlpconfig/envconfig.go index 6e85501dc1d..1b9ecf6f949 100644 --- a/exporters/otlp/otlptrace/internal/otlpconfig/envconfig.go +++ b/exporters/otlp/otlptrace/internal/otlpconfig/envconfig.go @@ -1,6 +1,3 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/otlpconfig/envconfig.go.tmpl - // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -26,7 +23,7 @@ import ( "strings" "time" - "go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/envconfig" + "go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/envconfig" // nolint: staticcheck // Atomic deprecation. ) // DefaultEnvOptionsReader is the default environments reader. diff --git a/exporters/otlp/otlptrace/internal/otlpconfig/options.go b/exporters/otlp/otlptrace/internal/otlpconfig/options.go index e5f396e6fe8..9d99c02365d 100644 --- a/exporters/otlp/otlptrace/internal/otlpconfig/options.go +++ b/exporters/otlp/otlptrace/internal/otlpconfig/options.go @@ -1,6 +1,3 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl - // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -31,7 +28,7 @@ import ( "google.golang.org/grpc/encoding/gzip" "go.opentelemetry.io/otel/exporters/otlp/otlptrace" - "go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/retry" + "go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/retry" // nolint: staticcheck // Atomic deprecation. ) const ( diff --git a/exporters/otlp/otlptrace/internal/otlpconfig/options_test.go b/exporters/otlp/otlptrace/internal/otlpconfig/options_test.go index 34b04d36f11..e3f83e64616 100644 --- a/exporters/otlp/otlptrace/internal/otlpconfig/options_test.go +++ b/exporters/otlp/otlptrace/internal/otlpconfig/options_test.go @@ -1,6 +1,3 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/otlpconfig/options_test.go.tmpl - // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -24,7 +21,7 @@ import ( "github.com/stretchr/testify/assert" - "go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/envconfig" + "go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/envconfig" // nolint: staticcheck // Atomic deprecation. ) const ( diff --git a/exporters/otlp/otlptrace/internal/otlpconfig/optiontypes.go b/exporters/otlp/otlptrace/internal/otlpconfig/optiontypes.go index 1d276083d85..c2d6c036152 100644 --- a/exporters/otlp/otlptrace/internal/otlpconfig/optiontypes.go +++ b/exporters/otlp/otlptrace/internal/otlpconfig/optiontypes.go @@ -1,6 +1,3 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/otlpconfig/optiontypes.go.tmpl - // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/exporters/otlp/otlptrace/internal/otlpconfig/tls.go b/exporters/otlp/otlptrace/internal/otlpconfig/tls.go index ac7b9a4cc12..7287cf6cfeb 100644 --- a/exporters/otlp/otlptrace/internal/otlpconfig/tls.go +++ b/exporters/otlp/otlptrace/internal/otlpconfig/tls.go @@ -1,6 +1,3 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/otlpconfig/tls.go.tmpl - // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/exporters/otlp/otlptrace/internal/otlptracetest/client.go b/exporters/otlp/otlptrace/internal/otlptracetest/client.go index 69ec2bbd8ea..aedb8f4a9d2 100644 --- a/exporters/otlp/otlptrace/internal/otlptracetest/client.go +++ b/exporters/otlp/otlptrace/internal/otlptracetest/client.go @@ -1,6 +1,3 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/otlptracetest/client.go.tmpl - // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/exporters/otlp/otlptrace/internal/otlptracetest/collector.go b/exporters/otlp/otlptrace/internal/otlptracetest/collector.go index d60e56829a0..865fabba27d 100644 --- a/exporters/otlp/otlptrace/internal/otlptracetest/collector.go +++ b/exporters/otlp/otlptrace/internal/otlptracetest/collector.go @@ -1,6 +1,3 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/otlptracetest/collector.go.tmpl - // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/exporters/otlp/otlptrace/internal/otlptracetest/data.go b/exporters/otlp/otlptrace/internal/otlptracetest/data.go index 1da7ad7fc2c..d039105cb29 100644 --- a/exporters/otlp/otlptrace/internal/otlptracetest/data.go +++ b/exporters/otlp/otlptrace/internal/otlptracetest/data.go @@ -1,6 +1,3 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/otlptracetest/data.go.tmpl - // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/exporters/otlp/otlptrace/internal/otlptracetest/doc.go b/exporters/otlp/otlptrace/internal/otlptracetest/doc.go new file mode 100644 index 00000000000..16306de6951 --- /dev/null +++ b/exporters/otlp/otlptrace/internal/otlptracetest/doc.go @@ -0,0 +1,20 @@ +// 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 otlptracetest contains common functionality for testing all OTLP +// trace exporters. +// +// Deprecated: package otlptracetest exists for historical compatibility, it +// should not be used. +package otlptracetest // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/otlptracetest" diff --git a/exporters/otlp/otlptrace/internal/otlptracetest/otlptest.go b/exporters/otlp/otlptrace/internal/otlptracetest/otlptest.go index 09e8f75d728..91c098d1539 100644 --- a/exporters/otlp/otlptrace/internal/otlptracetest/otlptest.go +++ b/exporters/otlp/otlptrace/internal/otlptracetest/otlptest.go @@ -1,6 +1,3 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/otlptracetest/otlptest.go.tmpl - // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/exporters/otlp/otlptrace/internal/retry/retry.go b/exporters/otlp/otlptrace/internal/retry/retry.go index a8abb55ab2e..1af94419199 100644 --- a/exporters/otlp/otlptrace/internal/retry/retry.go +++ b/exporters/otlp/otlptrace/internal/retry/retry.go @@ -1,6 +1,3 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/retry/retry.go.tmpl - // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,6 +15,9 @@ // Package retry provides request retry functionality that can perform // configurable exponential backoff for transient errors and honor any // explicit throttle responses received. +// +// Deprecated: package retry exists for historical compatibility, it should not +// be used. package retry // import "go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal/retry" import ( diff --git a/exporters/otlp/otlptrace/internal/retry/retry_test.go b/exporters/otlp/otlptrace/internal/retry/retry_test.go index 9279c7c00ff..de574a73579 100644 --- a/exporters/otlp/otlptrace/internal/retry/retry_test.go +++ b/exporters/otlp/otlptrace/internal/retry/retry_test.go @@ -1,6 +1,3 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/retry/retry_test.go.tmpl - // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/exporters/otlp/otlptrace/internal/tracetransform/attribute.go b/exporters/otlp/otlptrace/internal/tracetransform/attribute.go index ff5e1016ee9..ec74f1aad75 100644 --- a/exporters/otlp/otlptrace/internal/tracetransform/attribute.go +++ b/exporters/otlp/otlptrace/internal/tracetransform/attribute.go @@ -1,6 +1,3 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/tracetransform/attribute.go.tmpl - // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/exporters/otlp/otlptrace/internal/tracetransform/attribute_test.go b/exporters/otlp/otlptrace/internal/tracetransform/attribute_test.go index bdba00a833d..3f335f12392 100644 --- a/exporters/otlp/otlptrace/internal/tracetransform/attribute_test.go +++ b/exporters/otlp/otlptrace/internal/tracetransform/attribute_test.go @@ -1,6 +1,3 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/tracetransform/attribute_test.go.tmpl - // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/exporters/otlp/otlptrace/internal/tracetransform/instrumentation.go b/exporters/otlp/otlptrace/internal/tracetransform/instrumentation.go index 9bc6faa2f3e..7aaec38d22a 100644 --- a/exporters/otlp/otlptrace/internal/tracetransform/instrumentation.go +++ b/exporters/otlp/otlptrace/internal/tracetransform/instrumentation.go @@ -1,6 +1,3 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/tracetransform/instrumentation.go.tmpl - // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/exporters/otlp/otlptrace/internal/tracetransform/resource.go b/exporters/otlp/otlptrace/internal/tracetransform/resource.go index 7414e2ba93f..05a1f78adbc 100644 --- a/exporters/otlp/otlptrace/internal/tracetransform/resource.go +++ b/exporters/otlp/otlptrace/internal/tracetransform/resource.go @@ -1,6 +1,3 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/tracetransform/resource.go.tmpl - // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/exporters/otlp/otlptrace/internal/tracetransform/resource_test.go b/exporters/otlp/otlptrace/internal/tracetransform/resource_test.go index 13628d63b2d..f214cd6f891 100644 --- a/exporters/otlp/otlptrace/internal/tracetransform/resource_test.go +++ b/exporters/otlp/otlptrace/internal/tracetransform/resource_test.go @@ -1,6 +1,3 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/tracetransform/resource_test.go.tmpl - // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/exporters/otlp/otlptrace/internal/tracetransform/span.go b/exporters/otlp/otlptrace/internal/tracetransform/span.go index 02ce59e3eab..b83cbd72478 100644 --- a/exporters/otlp/otlptrace/internal/tracetransform/span.go +++ b/exporters/otlp/otlptrace/internal/tracetransform/span.go @@ -1,6 +1,3 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/tracetransform/span.go.tmpl - // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/exporters/otlp/otlptrace/internal/tracetransform/span_test.go b/exporters/otlp/otlptrace/internal/tracetransform/span_test.go index 227711a9e34..7e0be6cabb7 100644 --- a/exporters/otlp/otlptrace/internal/tracetransform/span_test.go +++ b/exporters/otlp/otlptrace/internal/tracetransform/span_test.go @@ -1,6 +1,3 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/tracetransform/span_test.go.tmpl - // Copyright The OpenTelemetry Authors // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/internal/shared/otlp/otlptrace/tracetransform/attribute.go.tmpl b/internal/shared/otlp/otlptrace/tracetransform/attribute.go.tmpl deleted file mode 100644 index 507e520d679..00000000000 --- a/internal/shared/otlp/otlptrace/tracetransform/attribute.go.tmpl +++ /dev/null @@ -1,161 +0,0 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/tracetransform/attribute.go.tmpl - -// 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 tracetransform - -import ( - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/sdk/resource" - commonpb "go.opentelemetry.io/proto/otlp/common/v1" -) - -// KeyValues transforms a slice of attribute KeyValues into OTLP key-values. -func KeyValues(attrs []attribute.KeyValue) []*commonpb.KeyValue { - if len(attrs) == 0 { - return nil - } - - out := make([]*commonpb.KeyValue, 0, len(attrs)) - for _, kv := range attrs { - out = append(out, KeyValue(kv)) - } - return out -} - -// Iterator transforms an attribute iterator into OTLP key-values. -func Iterator(iter attribute.Iterator) []*commonpb.KeyValue { - l := iter.Len() - if l == 0 { - return nil - } - - out := make([]*commonpb.KeyValue, 0, l) - for iter.Next() { - out = append(out, KeyValue(iter.Attribute())) - } - return out -} - -// ResourceAttributes transforms a Resource OTLP key-values. -func ResourceAttributes(res *resource.Resource) []*commonpb.KeyValue { - return Iterator(res.Iter()) -} - -// KeyValue transforms an attribute KeyValue into an OTLP key-value. -func KeyValue(kv attribute.KeyValue) *commonpb.KeyValue { - return &commonpb.KeyValue{Key: string(kv.Key), Value: Value(kv.Value)} -} - -// Value transforms an attribute Value into an OTLP AnyValue. -func Value(v attribute.Value) *commonpb.AnyValue { - av := new(commonpb.AnyValue) - switch v.Type() { - case attribute.BOOL: - av.Value = &commonpb.AnyValue_BoolValue{ - BoolValue: v.AsBool(), - } - case attribute.BOOLSLICE: - av.Value = &commonpb.AnyValue_ArrayValue{ - ArrayValue: &commonpb.ArrayValue{ - Values: boolSliceValues(v.AsBoolSlice()), - }, - } - case attribute.INT64: - av.Value = &commonpb.AnyValue_IntValue{ - IntValue: v.AsInt64(), - } - case attribute.INT64SLICE: - av.Value = &commonpb.AnyValue_ArrayValue{ - ArrayValue: &commonpb.ArrayValue{ - Values: int64SliceValues(v.AsInt64Slice()), - }, - } - case attribute.FLOAT64: - av.Value = &commonpb.AnyValue_DoubleValue{ - DoubleValue: v.AsFloat64(), - } - case attribute.FLOAT64SLICE: - av.Value = &commonpb.AnyValue_ArrayValue{ - ArrayValue: &commonpb.ArrayValue{ - Values: float64SliceValues(v.AsFloat64Slice()), - }, - } - case attribute.STRING: - av.Value = &commonpb.AnyValue_StringValue{ - StringValue: v.AsString(), - } - case attribute.STRINGSLICE: - av.Value = &commonpb.AnyValue_ArrayValue{ - ArrayValue: &commonpb.ArrayValue{ - Values: stringSliceValues(v.AsStringSlice()), - }, - } - default: - av.Value = &commonpb.AnyValue_StringValue{ - StringValue: "INVALID", - } - } - return av -} - -func boolSliceValues(vals []bool) []*commonpb.AnyValue { - converted := make([]*commonpb.AnyValue, len(vals)) - for i, v := range vals { - converted[i] = &commonpb.AnyValue{ - Value: &commonpb.AnyValue_BoolValue{ - BoolValue: v, - }, - } - } - return converted -} - -func int64SliceValues(vals []int64) []*commonpb.AnyValue { - converted := make([]*commonpb.AnyValue, len(vals)) - for i, v := range vals { - converted[i] = &commonpb.AnyValue{ - Value: &commonpb.AnyValue_IntValue{ - IntValue: v, - }, - } - } - return converted -} - -func float64SliceValues(vals []float64) []*commonpb.AnyValue { - converted := make([]*commonpb.AnyValue, len(vals)) - for i, v := range vals { - converted[i] = &commonpb.AnyValue{ - Value: &commonpb.AnyValue_DoubleValue{ - DoubleValue: v, - }, - } - } - return converted -} - -func stringSliceValues(vals []string) []*commonpb.AnyValue { - converted := make([]*commonpb.AnyValue, len(vals)) - for i, v := range vals { - converted[i] = &commonpb.AnyValue{ - Value: &commonpb.AnyValue_StringValue{ - StringValue: v, - }, - } - } - return converted -} diff --git a/internal/shared/otlp/otlptrace/tracetransform/attribute_test.go.tmpl b/internal/shared/otlp/otlptrace/tracetransform/attribute_test.go.tmpl deleted file mode 100644 index bdba00a833d..00000000000 --- a/internal/shared/otlp/otlptrace/tracetransform/attribute_test.go.tmpl +++ /dev/null @@ -1,261 +0,0 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/tracetransform/attribute_test.go.tmpl - -// 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 tracetransform - -import ( - "testing" - - "github.com/stretchr/testify/assert" - - "go.opentelemetry.io/otel/attribute" - commonpb "go.opentelemetry.io/proto/otlp/common/v1" -) - -type attributeTest struct { - attrs []attribute.KeyValue - expected []*commonpb.KeyValue -} - -func TestAttributes(t *testing.T) { - for _, test := range []attributeTest{ - {nil, nil}, - { - []attribute.KeyValue{ - attribute.Int("int to int", 123), - attribute.Int64("int64 to int64", 1234567), - attribute.Float64("float64 to double", 1.61), - attribute.String("string to string", "string"), - attribute.Bool("bool to bool", true), - }, - []*commonpb.KeyValue{ - { - Key: "int to int", - Value: &commonpb.AnyValue{ - Value: &commonpb.AnyValue_IntValue{ - IntValue: 123, - }, - }, - }, - { - Key: "int64 to int64", - Value: &commonpb.AnyValue{ - Value: &commonpb.AnyValue_IntValue{ - IntValue: 1234567, - }, - }, - }, - { - Key: "float64 to double", - Value: &commonpb.AnyValue{ - Value: &commonpb.AnyValue_DoubleValue{ - DoubleValue: 1.61, - }, - }, - }, - { - Key: "string to string", - Value: &commonpb.AnyValue{ - Value: &commonpb.AnyValue_StringValue{ - StringValue: "string", - }, - }, - }, - { - Key: "bool to bool", - Value: &commonpb.AnyValue{ - Value: &commonpb.AnyValue_BoolValue{ - BoolValue: true, - }, - }, - }, - }, - }, - } { - got := KeyValues(test.attrs) - if !assert.Len(t, got, len(test.expected)) { - continue - } - for i, actual := range got { - if a, ok := actual.Value.Value.(*commonpb.AnyValue_DoubleValue); ok { - e, ok := test.expected[i].Value.Value.(*commonpb.AnyValue_DoubleValue) - if !ok { - t.Errorf("expected AnyValue_DoubleValue, got %T", test.expected[i].Value.Value) - continue - } - if !assert.InDelta(t, e.DoubleValue, a.DoubleValue, 0.01) { - continue - } - e.DoubleValue = a.DoubleValue - } - assert.Equal(t, test.expected[i], actual) - } - } -} - -func TestArrayAttributes(t *testing.T) { - // Array KeyValue supports only arrays of primitive types: - // "bool", "int", "int64", - // "float64", "string", - for _, test := range []attributeTest{ - {nil, nil}, - { - []attribute.KeyValue{ - { - Key: attribute.Key("invalid"), - Value: attribute.Value{}, - }, - }, - []*commonpb.KeyValue{ - { - Key: "invalid", - Value: &commonpb.AnyValue{ - Value: &commonpb.AnyValue_StringValue{ - StringValue: "INVALID", - }, - }, - }, - }, - }, - { - []attribute.KeyValue{ - attribute.BoolSlice("bool slice to bool array", []bool{true, false}), - attribute.IntSlice("int slice to int64 array", []int{1, 2, 3}), - attribute.Int64Slice("int64 slice to int64 array", []int64{1, 2, 3}), - attribute.Float64Slice("float64 slice to double array", []float64{1.11, 2.22, 3.33}), - attribute.StringSlice("string slice to string array", []string{"foo", "bar", "baz"}), - }, - []*commonpb.KeyValue{ - newOTelBoolArray("bool slice to bool array", []bool{true, false}), - newOTelIntArray("int slice to int64 array", []int64{1, 2, 3}), - newOTelIntArray("int64 slice to int64 array", []int64{1, 2, 3}), - newOTelDoubleArray("float64 slice to double array", []float64{1.11, 2.22, 3.33}), - newOTelStringArray("string slice to string array", []string{"foo", "bar", "baz"}), - }, - }, - } { - actualArrayAttributes := KeyValues(test.attrs) - expectedArrayAttributes := test.expected - if !assert.Len(t, actualArrayAttributes, len(expectedArrayAttributes)) { - continue - } - - for i, actualArrayAttr := range actualArrayAttributes { - expectedArrayAttr := expectedArrayAttributes[i] - expectedKey, actualKey := expectedArrayAttr.Key, actualArrayAttr.Key - if !assert.Equal(t, expectedKey, actualKey) { - continue - } - - expected := expectedArrayAttr.Value.GetArrayValue() - actual := actualArrayAttr.Value.GetArrayValue() - if expected == nil { - assert.Nil(t, actual) - continue - } - if assert.NotNil(t, actual, "expected not nil for %s", actualKey) { - assertExpectedArrayValues(t, expected.Values, actual.Values) - } - } - } -} - -func assertExpectedArrayValues(t *testing.T, expectedValues, actualValues []*commonpb.AnyValue) { - for i, actual := range actualValues { - expected := expectedValues[i] - if a, ok := actual.Value.(*commonpb.AnyValue_DoubleValue); ok { - e, ok := expected.Value.(*commonpb.AnyValue_DoubleValue) - if !ok { - t.Errorf("expected AnyValue_DoubleValue, got %T", expected.Value) - continue - } - if !assert.InDelta(t, e.DoubleValue, a.DoubleValue, 0.01) { - continue - } - e.DoubleValue = a.DoubleValue - } - assert.Equal(t, expected, actual) - } -} - -func newOTelBoolArray(key string, values []bool) *commonpb.KeyValue { - arrayValues := []*commonpb.AnyValue{} - for _, b := range values { - arrayValues = append(arrayValues, &commonpb.AnyValue{ - Value: &commonpb.AnyValue_BoolValue{ - BoolValue: b, - }, - }) - } - - return newOTelArray(key, arrayValues) -} - -func newOTelIntArray(key string, values []int64) *commonpb.KeyValue { - arrayValues := []*commonpb.AnyValue{} - - for _, i := range values { - arrayValues = append(arrayValues, &commonpb.AnyValue{ - Value: &commonpb.AnyValue_IntValue{ - IntValue: i, - }, - }) - } - - return newOTelArray(key, arrayValues) -} - -func newOTelDoubleArray(key string, values []float64) *commonpb.KeyValue { - arrayValues := []*commonpb.AnyValue{} - - for _, d := range values { - arrayValues = append(arrayValues, &commonpb.AnyValue{ - Value: &commonpb.AnyValue_DoubleValue{ - DoubleValue: d, - }, - }) - } - - return newOTelArray(key, arrayValues) -} - -func newOTelStringArray(key string, values []string) *commonpb.KeyValue { - arrayValues := []*commonpb.AnyValue{} - - for _, s := range values { - arrayValues = append(arrayValues, &commonpb.AnyValue{ - Value: &commonpb.AnyValue_StringValue{ - StringValue: s, - }, - }) - } - - return newOTelArray(key, arrayValues) -} - -func newOTelArray(key string, arrayValues []*commonpb.AnyValue) *commonpb.KeyValue { - return &commonpb.KeyValue{ - Key: key, - Value: &commonpb.AnyValue{ - Value: &commonpb.AnyValue_ArrayValue{ - ArrayValue: &commonpb.ArrayValue{ - Values: arrayValues, - }, - }, - }, - } -} diff --git a/internal/shared/otlp/otlptrace/tracetransform/resource_test.go.tmpl b/internal/shared/otlp/otlptrace/tracetransform/resource_test.go.tmpl deleted file mode 100644 index 13628d63b2d..00000000000 --- a/internal/shared/otlp/otlptrace/tracetransform/resource_test.go.tmpl +++ /dev/null @@ -1,51 +0,0 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/tracetransform/resource_test.go.tmpl - -// 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 tracetransform - -import ( - "testing" - - "github.com/stretchr/testify/assert" - - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/sdk/resource" -) - -func TestNilResource(t *testing.T) { - assert.Empty(t, Resource(nil)) -} - -func TestEmptyResource(t *testing.T) { - assert.Empty(t, Resource(&resource.Resource{})) -} - -/* -* This does not include any testing on the ordering of Resource Attributes. -* They are stored as a map internally to the Resource and their order is not -* guaranteed. - */ - -func TestResourceAttributes(t *testing.T) { - attrs := []attribute.KeyValue{attribute.Int("one", 1), attribute.Int("two", 2)} - - got := Resource(resource.NewSchemaless(attrs...)).GetAttributes() - if !assert.Len(t, attrs, 2) { - return - } - assert.ElementsMatch(t, KeyValues(attrs), got) -} diff --git a/internal/shared/otlp/otlptrace/tracetransform/span.go.tmpl b/internal/shared/otlp/otlptrace/tracetransform/span.go.tmpl deleted file mode 100644 index 4204b11a59a..00000000000 --- a/internal/shared/otlp/otlptrace/tracetransform/span.go.tmpl +++ /dev/null @@ -1,208 +0,0 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/tracetransform/span.go.tmpl - -// 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 tracetransform - -import ( - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/codes" - "go.opentelemetry.io/otel/sdk/instrumentation" - tracesdk "go.opentelemetry.io/otel/sdk/trace" - "go.opentelemetry.io/otel/trace" - tracepb "go.opentelemetry.io/proto/otlp/trace/v1" -) - -// Spans transforms a slice of OpenTelemetry spans into a slice of OTLP -// ResourceSpans. -func Spans(sdl []tracesdk.ReadOnlySpan) []*tracepb.ResourceSpans { - if len(sdl) == 0 { - return nil - } - - rsm := make(map[attribute.Distinct]*tracepb.ResourceSpans) - - type key struct { - r attribute.Distinct - is instrumentation.Scope - } - ssm := make(map[key]*tracepb.ScopeSpans) - - var resources int - for _, sd := range sdl { - if sd == nil { - continue - } - - rKey := sd.Resource().Equivalent() - k := key{ - r: rKey, - is: sd.InstrumentationScope(), - } - scopeSpan, iOk := ssm[k] - if !iOk { - // Either the resource or instrumentation scope were unknown. - scopeSpan = &tracepb.ScopeSpans{ - Scope: InstrumentationScope(sd.InstrumentationScope()), - Spans: []*tracepb.Span{}, - SchemaUrl: sd.InstrumentationScope().SchemaURL, - } - } - scopeSpan.Spans = append(scopeSpan.Spans, span(sd)) - ssm[k] = scopeSpan - - rs, rOk := rsm[rKey] - if !rOk { - resources++ - // The resource was unknown. - rs = &tracepb.ResourceSpans{ - Resource: Resource(sd.Resource()), - ScopeSpans: []*tracepb.ScopeSpans{scopeSpan}, - SchemaUrl: sd.Resource().SchemaURL(), - } - rsm[rKey] = rs - continue - } - - // The resource has been seen before. Check if the instrumentation - // library lookup was unknown because if so we need to add it to the - // ResourceSpans. Otherwise, the instrumentation library has already - // been seen and the append we did above will be included it in the - // ScopeSpans reference. - if !iOk { - rs.ScopeSpans = append(rs.ScopeSpans, scopeSpan) - } - } - - // Transform the categorized map into a slice - rss := make([]*tracepb.ResourceSpans, 0, resources) - for _, rs := range rsm { - rss = append(rss, rs) - } - return rss -} - -// span transforms a Span into an OTLP span. -func span(sd tracesdk.ReadOnlySpan) *tracepb.Span { - if sd == nil { - return nil - } - - tid := sd.SpanContext().TraceID() - sid := sd.SpanContext().SpanID() - - s := &tracepb.Span{ - TraceId: tid[:], - SpanId: sid[:], - TraceState: sd.SpanContext().TraceState().String(), - Status: status(sd.Status().Code, sd.Status().Description), - StartTimeUnixNano: uint64(sd.StartTime().UnixNano()), - EndTimeUnixNano: uint64(sd.EndTime().UnixNano()), - Links: links(sd.Links()), - Kind: spanKind(sd.SpanKind()), - Name: sd.Name(), - Attributes: KeyValues(sd.Attributes()), - Events: spanEvents(sd.Events()), - DroppedAttributesCount: uint32(sd.DroppedAttributes()), - DroppedEventsCount: uint32(sd.DroppedEvents()), - DroppedLinksCount: uint32(sd.DroppedLinks()), - } - - if psid := sd.Parent().SpanID(); psid.IsValid() { - s.ParentSpanId = psid[:] - } - - return s -} - -// status transform a span code and message into an OTLP span status. -func status(status codes.Code, message string) *tracepb.Status { - var c tracepb.Status_StatusCode - switch status { - case codes.Ok: - c = tracepb.Status_STATUS_CODE_OK - case codes.Error: - c = tracepb.Status_STATUS_CODE_ERROR - default: - c = tracepb.Status_STATUS_CODE_UNSET - } - return &tracepb.Status{ - Code: c, - Message: message, - } -} - -// links transforms span Links to OTLP span links. -func links(links []tracesdk.Link) []*tracepb.Span_Link { - if len(links) == 0 { - return nil - } - - sl := make([]*tracepb.Span_Link, 0, len(links)) - for _, otLink := range links { - // This redefinition is necessary to prevent otLink.*ID[:] copies - // being reused -- in short we need a new otLink per iteration. - otLink := otLink - - tid := otLink.SpanContext.TraceID() - sid := otLink.SpanContext.SpanID() - - sl = append(sl, &tracepb.Span_Link{ - TraceId: tid[:], - SpanId: sid[:], - Attributes: KeyValues(otLink.Attributes), - DroppedAttributesCount: uint32(otLink.DroppedAttributeCount), - }) - } - return sl -} - -// spanEvents transforms span Events to an OTLP span events. -func spanEvents(es []tracesdk.Event) []*tracepb.Span_Event { - if len(es) == 0 { - return nil - } - - events := make([]*tracepb.Span_Event, len(es)) - // Transform message events - for i := 0; i < len(es); i++ { - events[i] = &tracepb.Span_Event{ - Name: es[i].Name, - TimeUnixNano: uint64(es[i].Time.UnixNano()), - Attributes: KeyValues(es[i].Attributes), - DroppedAttributesCount: uint32(es[i].DroppedAttributeCount), - } - } - return events -} - -// spanKind transforms a SpanKind to an OTLP span kind. -func spanKind(kind trace.SpanKind) tracepb.Span_SpanKind { - switch kind { - case trace.SpanKindInternal: - return tracepb.Span_SPAN_KIND_INTERNAL - case trace.SpanKindClient: - return tracepb.Span_SPAN_KIND_CLIENT - case trace.SpanKindServer: - return tracepb.Span_SPAN_KIND_SERVER - case trace.SpanKindProducer: - return tracepb.Span_SPAN_KIND_PRODUCER - case trace.SpanKindConsumer: - return tracepb.Span_SPAN_KIND_CONSUMER - default: - return tracepb.Span_SPAN_KIND_UNSPECIFIED - } -} diff --git a/internal/shared/otlp/otlptrace/tracetransform/span_test.go.tmpl b/internal/shared/otlp/otlptrace/tracetransform/span_test.go.tmpl deleted file mode 100644 index 227711a9e34..00000000000 --- a/internal/shared/otlp/otlptrace/tracetransform/span_test.go.tmpl +++ /dev/null @@ -1,336 +0,0 @@ -// Code created by gotmpl. DO NOT MODIFY. -// source: internal/shared/otlp/otlptrace/tracetransform/span_test.go.tmpl - -// 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 tracetransform - -import ( - "testing" - "time" - - "github.com/google/go-cmp/cmp" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "google.golang.org/protobuf/proto" - - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/codes" - "go.opentelemetry.io/otel/sdk/instrumentation" - "go.opentelemetry.io/otel/sdk/resource" - tracesdk "go.opentelemetry.io/otel/sdk/trace" - "go.opentelemetry.io/otel/sdk/trace/tracetest" - semconv "go.opentelemetry.io/otel/semconv/v1.21.0" - "go.opentelemetry.io/otel/trace" - tracepb "go.opentelemetry.io/proto/otlp/trace/v1" -) - -func TestSpanKind(t *testing.T) { - for _, test := range []struct { - kind trace.SpanKind - expected tracepb.Span_SpanKind - }{ - { - trace.SpanKindInternal, - tracepb.Span_SPAN_KIND_INTERNAL, - }, - { - trace.SpanKindClient, - tracepb.Span_SPAN_KIND_CLIENT, - }, - { - trace.SpanKindServer, - tracepb.Span_SPAN_KIND_SERVER, - }, - { - trace.SpanKindProducer, - tracepb.Span_SPAN_KIND_PRODUCER, - }, - { - trace.SpanKindConsumer, - tracepb.Span_SPAN_KIND_CONSUMER, - }, - { - trace.SpanKind(-1), - tracepb.Span_SPAN_KIND_UNSPECIFIED, - }, - } { - assert.Equal(t, test.expected, spanKind(test.kind)) - } -} - -func TestNilSpanEvent(t *testing.T) { - assert.Nil(t, spanEvents(nil)) -} - -func TestEmptySpanEvent(t *testing.T) { - assert.Nil(t, spanEvents([]tracesdk.Event{})) -} - -func TestSpanEvent(t *testing.T) { - attrs := []attribute.KeyValue{attribute.Int("one", 1), attribute.Int("two", 2)} - eventTime := time.Date(2020, 5, 20, 0, 0, 0, 0, time.UTC) - got := spanEvents([]tracesdk.Event{ - { - Name: "test 1", - Attributes: []attribute.KeyValue{}, - Time: eventTime, - }, - { - Name: "test 2", - Attributes: attrs, - Time: eventTime, - DroppedAttributeCount: 2, - }, - }) - if !assert.Len(t, got, 2) { - return - } - eventTimestamp := uint64(1589932800 * 1e9) - assert.Equal(t, &tracepb.Span_Event{Name: "test 1", Attributes: nil, TimeUnixNano: eventTimestamp}, got[0]) - // Do not test Attributes directly, just that the return value goes to the correct field. - assert.Equal(t, &tracepb.Span_Event{Name: "test 2", Attributes: KeyValues(attrs), TimeUnixNano: eventTimestamp, DroppedAttributesCount: 2}, got[1]) -} - -func TestNilLinks(t *testing.T) { - assert.Nil(t, links(nil)) -} - -func TestEmptyLinks(t *testing.T) { - assert.Nil(t, links([]tracesdk.Link{})) -} - -func TestLinks(t *testing.T) { - attrs := []attribute.KeyValue{attribute.Int("one", 1), attribute.Int("two", 2)} - l := []tracesdk.Link{ - { - DroppedAttributeCount: 3, - }, - { - SpanContext: trace.SpanContext{}, - Attributes: attrs, - DroppedAttributeCount: 3, - }, - } - got := links(l) - - // Make sure we get the same number back first. - if !assert.Len(t, got, 2) { - return - } - - // Empty should be empty. - expected := &tracepb.Span_Link{ - TraceId: []uint8{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, - SpanId: []uint8{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, - DroppedAttributesCount: 3, - } - assert.Equal(t, expected, got[0]) - - // Do not test Attributes directly, just that the return value goes to the correct field. - expected.Attributes = KeyValues(attrs) - assert.Equal(t, expected, got[1]) - - // Changes to our links should not change the produced links. - l[1].SpanContext = l[1].SpanContext.WithTraceID(trace.TraceID{}) - assert.Equal(t, expected, got[1]) - assert.Equal(t, l[1].DroppedAttributeCount, int(got[1].DroppedAttributesCount)) -} - -func TestStatus(t *testing.T) { - for _, test := range []struct { - code codes.Code - message string - otlpStatus tracepb.Status_StatusCode - }{ - { - codes.Ok, - "test Ok", - tracepb.Status_STATUS_CODE_OK, - }, - { - codes.Unset, - "test Unset", - tracepb.Status_STATUS_CODE_UNSET, - }, - { - message: "default code is unset", - otlpStatus: tracepb.Status_STATUS_CODE_UNSET, - }, - { - codes.Error, - "test Error", - tracepb.Status_STATUS_CODE_ERROR, - }, - } { - expected := &tracepb.Status{Code: test.otlpStatus, Message: test.message} - assert.Equal(t, expected, status(test.code, test.message)) - } -} - -func TestNilSpan(t *testing.T) { - assert.Nil(t, span(nil)) -} - -func TestNilSpanData(t *testing.T) { - assert.Nil(t, Spans(nil)) -} - -func TestEmptySpanData(t *testing.T) { - assert.Nil(t, Spans(nil)) -} - -func TestSpanData(t *testing.T) { - // Full test of span data - - // March 31, 2020 5:01:26 1234nanos (UTC) - startTime := time.Unix(1585674086, 1234) - endTime := startTime.Add(10 * time.Second) - traceState, _ := trace.ParseTraceState("key1=val1,key2=val2") - spanData := tracetest.SpanStub{ - SpanContext: trace.NewSpanContext(trace.SpanContextConfig{ - TraceID: trace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, - SpanID: trace.SpanID{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, - TraceState: traceState, - }), - Parent: trace.NewSpanContext(trace.SpanContextConfig{ - TraceID: trace.TraceID{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, - SpanID: trace.SpanID{0xEF, 0xEE, 0xED, 0xEC, 0xEB, 0xEA, 0xE9, 0xE8}, - TraceState: traceState, - Remote: true, - }), - SpanKind: trace.SpanKindServer, - Name: "span data to span data", - StartTime: startTime, - EndTime: endTime, - Events: []tracesdk.Event{ - {Time: startTime, - Attributes: []attribute.KeyValue{ - attribute.Int64("CompressedByteSize", 512), - }, - }, - {Time: endTime, - Attributes: []attribute.KeyValue{ - attribute.String("EventType", "Recv"), - }, - }, - }, - Links: []tracesdk.Link{ - { - SpanContext: trace.NewSpanContext(trace.SpanContextConfig{ - TraceID: trace.TraceID{0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF}, - SpanID: trace.SpanID{0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7}, - TraceFlags: 0, - }), - Attributes: []attribute.KeyValue{ - attribute.String("LinkType", "Parent"), - }, - DroppedAttributeCount: 0, - }, - { - SpanContext: trace.NewSpanContext(trace.SpanContextConfig{ - TraceID: trace.TraceID{0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF}, - SpanID: trace.SpanID{0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7}, - TraceFlags: 0, - }), - Attributes: []attribute.KeyValue{ - attribute.String("LinkType", "Child"), - }, - DroppedAttributeCount: 0, - }, - }, - Status: tracesdk.Status{ - Code: codes.Error, - Description: "utterly unrecognized", - }, - Attributes: []attribute.KeyValue{ - attribute.Int64("timeout_ns", 12e9), - }, - DroppedAttributes: 1, - DroppedEvents: 2, - DroppedLinks: 3, - Resource: resource.NewWithAttributes( - "http://example.com/custom-resource-schema", - attribute.String("rk1", "rv1"), - attribute.Int64("rk2", 5), - attribute.StringSlice("rk3", []string{"sv1", "sv2"}), - ), - InstrumentationLibrary: instrumentation.Scope{ - Name: "go.opentelemetry.io/test/otel", - Version: "v0.0.1", - SchemaURL: semconv.SchemaURL, - }, - } - - // Not checking resource as the underlying map of our Resource makes - // ordering impossible to guarantee on the output. The Resource - // transform function has unit tests that should suffice. - expectedSpan := &tracepb.Span{ - TraceId: []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}, - SpanId: []byte{0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8}, - ParentSpanId: []byte{0xEF, 0xEE, 0xED, 0xEC, 0xEB, 0xEA, 0xE9, 0xE8}, - TraceState: "key1=val1,key2=val2", - Name: spanData.Name, - Kind: tracepb.Span_SPAN_KIND_SERVER, - StartTimeUnixNano: uint64(startTime.UnixNano()), - EndTimeUnixNano: uint64(endTime.UnixNano()), - Status: status(spanData.Status.Code, spanData.Status.Description), - Events: spanEvents(spanData.Events), - Links: links(spanData.Links), - Attributes: KeyValues(spanData.Attributes), - DroppedAttributesCount: 1, - DroppedEventsCount: 2, - DroppedLinksCount: 3, - } - - got := Spans(tracetest.SpanStubs{spanData}.Snapshots()) - require.Len(t, got, 1) - - assert.Equal(t, got[0].GetResource(), Resource(spanData.Resource)) - assert.Equal(t, got[0].SchemaUrl, spanData.Resource.SchemaURL()) - scopeSpans := got[0].GetScopeSpans() - require.Len(t, scopeSpans, 1) - assert.Equal(t, scopeSpans[0].SchemaUrl, spanData.InstrumentationLibrary.SchemaURL) - assert.Equal(t, scopeSpans[0].GetScope(), InstrumentationScope(spanData.InstrumentationLibrary)) - require.Len(t, scopeSpans[0].Spans, 1) - actualSpan := scopeSpans[0].Spans[0] - - if diff := cmp.Diff(expectedSpan, actualSpan, cmp.Comparer(proto.Equal)); diff != "" { - t.Fatalf("transformed span differs %v\n", diff) - } -} - -// Empty parent span ID should be treated as root span. -func TestRootSpanData(t *testing.T) { - sd := Spans(tracetest.SpanStubs{ - {}, - }.Snapshots()) - require.Len(t, sd, 1) - rs := sd[0] - scopeSpans := rs.GetScopeSpans() - require.Len(t, scopeSpans, 1) - got := scopeSpans[0].GetSpans()[0].GetParentSpanId() - - // Empty means root span. - assert.Nil(t, got, "incorrect transform of root parent span ID") -} - -func TestSpanDataNilResource(t *testing.T) { - assert.NotPanics(t, func() { - Spans(tracetest.SpanStubs{ - {}, - }.Snapshots()) - }) -}