1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2024-12-28 21:09:17 +02:00

exporters/zipkin: Add use new scope attributes (#5108)

Co-authored-by: Robert Pająk <pellared@hotmail.com>
This commit is contained in:
Piotr Kiełkowicz 2024-03-27 08:02:52 +01:00 committed by GitHub
parent edb788bf49
commit 9e34895a3e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 13 deletions

View File

@ -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

View File

@ -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
}
}

View File

@ -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,
},