Skip to content

Commit

Permalink
Add semantic conventions for instrumentation library, switch to use t…
Browse files Browse the repository at this point in the history
…his new one (#2602)

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Mar 3, 2021
1 parent 2a743aa commit bf8b945
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 31 deletions.
23 changes: 23 additions & 0 deletions translator/conventions/trace_exporters.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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 conventions

// OpenTelemetry Semantic Convention values for standard exporters.
// See: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk_exporters/jaeger.md
// See: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk_exporters/zipkin.md
const (
InstrumentationLibraryName = "otel.library.name"
InstrumentationLibraryVersion = "otel.library.version"
)
8 changes: 4 additions & 4 deletions translator/trace/jaeger/jaegerproto_to_traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,12 @@ func jSpanToInternal(span *model.Span) (pdata.Span, instrumentationLibrary) {
}

il := instrumentationLibrary{}
if libraryName, ok := attrs.Get(tracetranslator.TagInstrumentationName); ok {
if libraryName, ok := attrs.Get(conventions.InstrumentationLibraryName); ok {
il.name = libraryName.StringVal()
attrs.Delete(tracetranslator.TagInstrumentationName)
if libraryVersion, ok := attrs.Get(tracetranslator.TagInstrumentationVersion); ok {
attrs.Delete(conventions.InstrumentationLibraryName)
if libraryVersion, ok := attrs.Get(conventions.InstrumentationLibraryVersion); ok {
il.version = libraryVersion.StringVal()
attrs.Delete(tracetranslator.TagInstrumentationVersion)
attrs.Delete(conventions.InstrumentationLibraryVersion)
}
}

Expand Down
12 changes: 6 additions & 6 deletions translator/trace/jaeger/jaegerproto_to_traces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,11 @@ func TestProtoBatchToInternalTracesWithTwoLibraries(t *testing.T) {
OperationName: "operation2",
Tags: []model.KeyValue{
{
Key: tracetranslator.TagInstrumentationName,
Key: conventions.InstrumentationLibraryName,
VType: model.ValueType_STRING,
VStr: "library2",
}, {
Key: tracetranslator.TagInstrumentationVersion,
Key: conventions.InstrumentationLibraryVersion,
VType: model.ValueType_STRING,
VStr: "0.42.0",
},
Expand All @@ -291,11 +291,11 @@ func TestProtoBatchToInternalTracesWithTwoLibraries(t *testing.T) {
OperationName: "operation1",
Tags: []model.KeyValue{
{
Key: tracetranslator.TagInstrumentationName,
Key: conventions.InstrumentationLibraryName,
VType: model.ValueType_STRING,
VStr: "library1",
}, {
Key: tracetranslator.TagInstrumentationVersion,
Key: conventions.InstrumentationLibraryVersion,
VType: model.ValueType_STRING,
VStr: "0.42.0",
},
Expand Down Expand Up @@ -627,11 +627,11 @@ func generateProtoSpanWithLibraryInfo(libraryName string) *model.Span {
span := generateProtoSpan()
span.Tags = append([]model.KeyValue{
{
Key: tracetranslator.TagInstrumentationName,
Key: conventions.InstrumentationLibraryName,
VType: model.ValueType_STRING,
VStr: libraryName,
}, {
Key: tracetranslator.TagInstrumentationVersion,
Key: conventions.InstrumentationLibraryVersion,
VType: model.ValueType_STRING,
VStr: "0.42.0",
},
Expand Down
4 changes: 2 additions & 2 deletions translator/trace/jaeger/traces_to_jaegerproto.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,15 +427,15 @@ func getTagsFromInstrumentationLibrary(il pdata.InstrumentationLibrary) ([]model
keyValues := make([]model.KeyValue, 0)
if ilName := il.Name(); ilName != "" {
kv := model.KeyValue{
Key: tracetranslator.TagInstrumentationName,
Key: conventions.InstrumentationLibraryName,
VStr: ilName,
VType: model.ValueType_STRING,
}
keyValues = append(keyValues, kv)
}
if ilVersion := il.Version(); ilVersion != "" {
kv := model.KeyValue{
Key: tracetranslator.TagInstrumentationVersion,
Key: conventions.InstrumentationLibraryVersion,
VStr: ilVersion,
VType: model.ValueType_STRING,
}
Expand Down
6 changes: 2 additions & 4 deletions translator/trace/protospan_translation.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ const (
TagZipkinCensusMsg = "census.status_description"
TagZipkinOpenCensusMsg = "opencensus.status_description"

TagW3CTraceState = "w3c.tracestate"
TagServiceNameSource = "otlp.service.name.source"
TagInstrumentationName = "otlp.instrumentation.library.name"
TagInstrumentationVersion = "otlp.instrumentation.library.version"
TagW3CTraceState = "w3c.tracestate"
TagServiceNameSource = "otlp.service.name.source"
)

// Constants used for signifying batch-level attribute values where not supplied by OTLP data but required
Expand Down
4 changes: 2 additions & 2 deletions translator/trace/zipkin/traces_to_zipkinv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ func resourceSpansToZipkinSpans(rs pdata.ResourceSpans, estSpanCount int) ([]*zi

func extractInstrumentationLibraryTags(il pdata.InstrumentationLibrary, zTags map[string]string) {
if ilName := il.Name(); ilName != "" {
zTags[tracetranslator.TagInstrumentationName] = ilName
zTags[conventions.InstrumentationLibraryName] = ilName
}
if ilVer := il.Version(); ilVer != "" {
zTags[tracetranslator.TagInstrumentationVersion] = ilVer
zTags[conventions.InstrumentationLibraryVersion] = ilVer
}
}

Expand Down
24 changes: 11 additions & 13 deletions translator/trace/zipkin/zipkinv2_to_traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,20 @@ import (
tracetranslator "go.opentelemetry.io/collector/translator/trace"
)

var nonSpanAttributes = getNonSpanAttributes()

func getNonSpanAttributes() map[string]struct{} {
var nonSpanAttributes = func() map[string]struct{} {
attrs := make(map[string]struct{})
for _, key := range conventions.GetResourceSemanticConventionAttributeNames() {
attrs[key] = struct{}{}
}
attrs[tracetranslator.TagServiceNameSource] = struct{}{}
attrs[tracetranslator.TagInstrumentationName] = struct{}{}
attrs[tracetranslator.TagInstrumentationVersion] = struct{}{}
attrs[conventions.InstrumentationLibraryName] = struct{}{}
attrs[conventions.InstrumentationLibraryVersion] = struct{}{}
attrs[conventions.OCAttributeProcessStartTime] = struct{}{}
attrs[conventions.OCAttributeExporterVersion] = struct{}{}
attrs[conventions.AttributeProcessID] = struct{}{}
attrs[conventions.OCAttributeResourceType] = struct{}{}
return attrs
}
}()

// Custom Sort on
type byOTLPTypes []*zipkinmodel.SpanModel
Expand Down Expand Up @@ -384,8 +382,8 @@ func populateResourceFromZipkinSpan(tags map[string]string, localServiceName str
}
delete(tags, tracetranslator.TagServiceNameSource)

for key := range getNonSpanAttributes() {
if key == tracetranslator.TagInstrumentationName || key == tracetranslator.TagInstrumentationVersion {
for key := range nonSpanAttributes {
if key == conventions.InstrumentationLibraryName || key == conventions.InstrumentationLibraryVersion {
continue
}
if value, ok := tags[key]; ok {
Expand All @@ -399,13 +397,13 @@ func populateILFromZipkinSpan(tags map[string]string, instrLibName string, libra
if instrLibName == "" {
return
}
if value, ok := tags[tracetranslator.TagInstrumentationName]; ok {
if value, ok := tags[conventions.InstrumentationLibraryName]; ok {
library.SetName(value)
delete(tags, tracetranslator.TagInstrumentationName)
delete(tags, conventions.InstrumentationLibraryName)
}
if value, ok := tags[tracetranslator.TagInstrumentationVersion]; ok {
if value, ok := tags[conventions.InstrumentationLibraryVersion]; ok {
library.SetVersion(value)
delete(tags, tracetranslator.TagInstrumentationVersion)
delete(tags, conventions.InstrumentationLibraryVersion)
}
}

Expand All @@ -428,5 +426,5 @@ func extractInstrumentationLibrary(zspan *zipkinmodel.SpanModel) string {
if zspan == nil || len(zspan.Tags) == 0 {
return ""
}
return zspan.Tags[tracetranslator.TagInstrumentationName]
return zspan.Tags[conventions.InstrumentationLibraryName]
}

0 comments on commit bf8b945

Please sign in to comment.