From 9e34895a3e917727167073a9719a16d862cddf9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Kie=C5=82kowicz?= Date: Wed, 27 Mar 2024 08:02:52 +0100 Subject: [PATCH] exporters/zipkin: Add use new scope attributes (#5108) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Robert PajÄ…k --- CHANGELOG.md | 1 + exporters/zipkin/model.go | 27 ++++++++++++++------------- exporters/zipkin/model_test.go | 3 +++ 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e50cd0623a9..14a4f446ac1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm This package is provided with the anticipation that all functionality will be migrate to `go.opentelemetry.io/otel` when `go.opentelemetry.io/otel/log` stabilizes. At which point, users will be required to migrage their code, and this package will be deprecated then removed. (#5085) - Add support for `Summary` metrics in the `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp` and `go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc` exporters. (#5100) +- Add `otel.scope.name` and `otel.scope.version` tags to spans exported by `go.opentelemetry.io/otel/exporters/zipkin`. (#5108) ### Changed diff --git a/exporters/zipkin/model.go b/exporters/zipkin/model.go index 059ad7e38c3..6cc77119c13 100644 --- a/exporters/zipkin/model.go +++ b/exporters/zipkin/model.go @@ -24,9 +24,6 @@ import ( ) const ( - keyInstrumentationLibraryName = "otel.library.name" - keyInstrumentationLibraryVersion = "otel.library.version" - keyPeerHostname attribute.Key = "peer.hostname" keyPeerAddress attribute.Key = "peer.address" ) @@ -180,17 +177,19 @@ func attributeToStringPair(kv attribute.KeyValue) (string, string) { } } -// extraZipkinTags are those that may be added to every outgoing span. -var extraZipkinTags = []string{ - "otel.status_code", - keyInstrumentationLibraryName, - keyInstrumentationLibraryVersion, -} +// extraZipkinTagsLen is a count of tags that may be added to every outgoing span. +var extraZipkinTagsLen = len([]attribute.Key{ + semconv.OTelStatusCodeKey, + semconv.OTelScopeNameKey, + semconv.OTelScopeVersionKey, + semconv.OTelLibraryNameKey, + semconv.OTelLibraryVersionKey, +}) func toZipkinTags(data tracesdk.ReadOnlySpan) map[string]string { attr := data.Attributes() resourceAttr := data.Resource().Attributes() - m := make(map[string]string, len(attr)+len(resourceAttr)+len(extraZipkinTags)) + m := make(map[string]string, len(attr)+len(resourceAttr)+extraZipkinTagsLen) for _, kv := range attr { k, v := attributeToStringPair(kv) m[k] = v @@ -203,7 +202,7 @@ func toZipkinTags(data tracesdk.ReadOnlySpan) map[string]string { if data.Status().Code != codes.Unset { // Zipkin expect to receive uppercase status values // rather than default capitalized ones. - m["otel.status_code"] = strings.ToUpper(data.Status().Code.String()) + m[string(semconv.OTelStatusCodeKey)] = strings.ToUpper(data.Status().Code.String()) } if data.Status().Code == codes.Error { @@ -213,9 +212,11 @@ func toZipkinTags(data tracesdk.ReadOnlySpan) map[string]string { } if is := data.InstrumentationScope(); is.Name != "" { - m[keyInstrumentationLibraryName] = is.Name + m[string(semconv.OTelScopeNameKey)] = is.Name + m[string(semconv.OTelLibraryNameKey)] = is.Name if is.Version != "" { - m[keyInstrumentationLibraryVersion] = is.Version + m[string(semconv.OTelScopeVersionKey)] = is.Version + m[string(semconv.OTelLibraryVersionKey)] = is.Version } } diff --git a/exporters/zipkin/model_test.go b/exporters/zipkin/model_test.go index 117267b1bf2..fd4192588ff 100644 --- a/exporters/zipkin/model_test.go +++ b/exporters/zipkin/model_test.go @@ -1027,6 +1027,7 @@ func TestTagsTransformation(t *testing.T) { }, }, want: map[string]string{ + "otel.scope.name": instrLibName, "otel.library.name": instrLibName, }, }, @@ -1040,6 +1041,8 @@ func TestTagsTransformation(t *testing.T) { }, }, want: map[string]string{ + "otel.scope.name": instrLibName, + "otel.scope.version": instrLibVersion, "otel.library.name": instrLibName, "otel.library.version": instrLibVersion, },