From bf8b945cfdf16452cd4b9a69f47c17e55be52a8c Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Wed, 3 Mar 2021 15:01:36 -0800 Subject: [PATCH] Add semantic conventions for instrumentation library, switch to use this new one (#2602) Signed-off-by: Bogdan Drutu --- translator/conventions/trace_exporters.go | 23 ++++++++++++++++++ .../trace/jaeger/jaegerproto_to_traces.go | 8 +++---- .../jaeger/jaegerproto_to_traces_test.go | 12 +++++----- .../trace/jaeger/traces_to_jaegerproto.go | 4 ++-- translator/trace/protospan_translation.go | 6 ++--- translator/trace/zipkin/traces_to_zipkinv2.go | 4 ++-- translator/trace/zipkin/zipkinv2_to_traces.go | 24 +++++++++---------- 7 files changed, 50 insertions(+), 31 deletions(-) create mode 100644 translator/conventions/trace_exporters.go diff --git a/translator/conventions/trace_exporters.go b/translator/conventions/trace_exporters.go new file mode 100644 index 00000000000..ef69ad81f8d --- /dev/null +++ b/translator/conventions/trace_exporters.go @@ -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" +) diff --git a/translator/trace/jaeger/jaegerproto_to_traces.go b/translator/trace/jaeger/jaegerproto_to_traces.go index 69bc15b39be..0bbc555be03 100644 --- a/translator/trace/jaeger/jaegerproto_to_traces.go +++ b/translator/trace/jaeger/jaegerproto_to_traces.go @@ -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) } } diff --git a/translator/trace/jaeger/jaegerproto_to_traces_test.go b/translator/trace/jaeger/jaegerproto_to_traces_test.go index b96bb1a100b..96ba7b3ef8d 100644 --- a/translator/trace/jaeger/jaegerproto_to_traces_test.go +++ b/translator/trace/jaeger/jaegerproto_to_traces_test.go @@ -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", }, @@ -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", }, @@ -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", }, diff --git a/translator/trace/jaeger/traces_to_jaegerproto.go b/translator/trace/jaeger/traces_to_jaegerproto.go index 48b7a792d23..5bd370cec8b 100644 --- a/translator/trace/jaeger/traces_to_jaegerproto.go +++ b/translator/trace/jaeger/traces_to_jaegerproto.go @@ -427,7 +427,7 @@ 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, } @@ -435,7 +435,7 @@ func getTagsFromInstrumentationLibrary(il pdata.InstrumentationLibrary) ([]model } if ilVersion := il.Version(); ilVersion != "" { kv := model.KeyValue{ - Key: tracetranslator.TagInstrumentationVersion, + Key: conventions.InstrumentationLibraryVersion, VStr: ilVersion, VType: model.ValueType_STRING, } diff --git a/translator/trace/protospan_translation.go b/translator/trace/protospan_translation.go index 903967b30cc..5dba6dc1f86 100644 --- a/translator/trace/protospan_translation.go +++ b/translator/trace/protospan_translation.go @@ -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 diff --git a/translator/trace/zipkin/traces_to_zipkinv2.go b/translator/trace/zipkin/traces_to_zipkinv2.go index 6f909ca7fe9..ff2bf16b547 100644 --- a/translator/trace/zipkin/traces_to_zipkinv2.go +++ b/translator/trace/zipkin/traces_to_zipkinv2.go @@ -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 } } diff --git a/translator/trace/zipkin/zipkinv2_to_traces.go b/translator/trace/zipkin/zipkinv2_to_traces.go index 37efca1037b..a9341d01b19 100644 --- a/translator/trace/zipkin/zipkinv2_to_traces.go +++ b/translator/trace/zipkin/zipkinv2_to_traces.go @@ -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 @@ -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 { @@ -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) } } @@ -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] }