Skip to content

Commit

Permalink
exporters/zipkin: Add use new scope attributes (#5108)
Browse files Browse the repository at this point in the history
Co-authored-by: Robert Pająk <pellared@hotmail.com>
  • Loading branch information
Kielek and pellared committed Mar 27, 2024
1 parent edb788b commit 9e34895
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
27 changes: 14 additions & 13 deletions exporters/zipkin/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ import (
)

const (
keyInstrumentationLibraryName = "otel.library.name"
keyInstrumentationLibraryVersion = "otel.library.version"

keyPeerHostname attribute.Key = "peer.hostname"
keyPeerAddress attribute.Key = "peer.address"
)
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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
}
}

Expand Down
3 changes: 3 additions & 0 deletions exporters/zipkin/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,7 @@ func TestTagsTransformation(t *testing.T) {
},
},
want: map[string]string{
"otel.scope.name": instrLibName,
"otel.library.name": instrLibName,
},
},
Expand All @@ -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,
},
Expand Down

0 comments on commit 9e34895

Please sign in to comment.