Skip to content

Commit d010c4f

Browse files
committed
Add semantic conventions for instrumentation library, switch to use this new one
Signed-off-by: Bogdan Drutu <[email protected]>
1 parent 2a743aa commit d010c4f

File tree

7 files changed

+50
-31
lines changed

7 files changed

+50
-31
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package conventions
16+
17+
// OpenTelemetry Semantic Convention values for standard exporters.
18+
// See: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk_exporters/jaeger.md
19+
// See: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/sdk_exporters/zipkin.md
20+
const (
21+
InstrumentationLibraryName = "otel.library.name"
22+
InstrumentationLibraryVersion = "otel.library.version"
23+
)

translator/trace/jaeger/jaegerproto_to_traces.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,12 @@ func jSpanToInternal(span *model.Span) (pdata.Span, instrumentationLibrary) {
185185
}
186186

187187
il := instrumentationLibrary{}
188-
if libraryName, ok := attrs.Get(tracetranslator.TagInstrumentationName); ok {
188+
if libraryName, ok := attrs.Get(conventions.InstrumentationLibraryName); ok {
189189
il.name = libraryName.StringVal()
190-
attrs.Delete(tracetranslator.TagInstrumentationName)
191-
if libraryVersion, ok := attrs.Get(tracetranslator.TagInstrumentationVersion); ok {
190+
attrs.Delete(conventions.InstrumentationLibraryName)
191+
if libraryVersion, ok := attrs.Get(conventions.InstrumentationLibraryVersion); ok {
192192
il.version = libraryVersion.StringVal()
193-
attrs.Delete(tracetranslator.TagInstrumentationVersion)
193+
attrs.Delete(conventions.InstrumentationLibraryVersion)
194194
}
195195
}
196196

translator/trace/jaeger/jaegerproto_to_traces_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,11 @@ func TestProtoBatchToInternalTracesWithTwoLibraries(t *testing.T) {
274274
OperationName: "operation2",
275275
Tags: []model.KeyValue{
276276
{
277-
Key: tracetranslator.TagInstrumentationName,
277+
Key: conventions.InstrumentationLibraryName,
278278
VType: model.ValueType_STRING,
279279
VStr: "library2",
280280
}, {
281-
Key: tracetranslator.TagInstrumentationVersion,
281+
Key: conventions.InstrumentationLibraryVersion,
282282
VType: model.ValueType_STRING,
283283
VStr: "0.42.0",
284284
},
@@ -291,11 +291,11 @@ func TestProtoBatchToInternalTracesWithTwoLibraries(t *testing.T) {
291291
OperationName: "operation1",
292292
Tags: []model.KeyValue{
293293
{
294-
Key: tracetranslator.TagInstrumentationName,
294+
Key: conventions.InstrumentationLibraryName,
295295
VType: model.ValueType_STRING,
296296
VStr: "library1",
297297
}, {
298-
Key: tracetranslator.TagInstrumentationVersion,
298+
Key: conventions.InstrumentationLibraryVersion,
299299
VType: model.ValueType_STRING,
300300
VStr: "0.42.0",
301301
},
@@ -627,11 +627,11 @@ func generateProtoSpanWithLibraryInfo(libraryName string) *model.Span {
627627
span := generateProtoSpan()
628628
span.Tags = append([]model.KeyValue{
629629
{
630-
Key: tracetranslator.TagInstrumentationName,
630+
Key: conventions.InstrumentationLibraryName,
631631
VType: model.ValueType_STRING,
632632
VStr: libraryName,
633633
}, {
634-
Key: tracetranslator.TagInstrumentationVersion,
634+
Key: conventions.InstrumentationLibraryVersion,
635635
VType: model.ValueType_STRING,
636636
VStr: "0.42.0",
637637
},

translator/trace/jaeger/traces_to_jaegerproto.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,15 +427,15 @@ func getTagsFromInstrumentationLibrary(il pdata.InstrumentationLibrary) ([]model
427427
keyValues := make([]model.KeyValue, 0)
428428
if ilName := il.Name(); ilName != "" {
429429
kv := model.KeyValue{
430-
Key: tracetranslator.TagInstrumentationName,
430+
Key: conventions.InstrumentationLibraryName,
431431
VStr: ilName,
432432
VType: model.ValueType_STRING,
433433
}
434434
keyValues = append(keyValues, kv)
435435
}
436436
if ilVersion := il.Version(); ilVersion != "" {
437437
kv := model.KeyValue{
438-
Key: tracetranslator.TagInstrumentationVersion,
438+
Key: conventions.InstrumentationLibraryVersion,
439439
VStr: ilVersion,
440440
VType: model.ValueType_STRING,
441441
}

translator/trace/protospan_translation.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ const (
3939
TagZipkinCensusMsg = "census.status_description"
4040
TagZipkinOpenCensusMsg = "opencensus.status_description"
4141

42-
TagW3CTraceState = "w3c.tracestate"
43-
TagServiceNameSource = "otlp.service.name.source"
44-
TagInstrumentationName = "otlp.instrumentation.library.name"
45-
TagInstrumentationVersion = "otlp.instrumentation.library.version"
42+
TagW3CTraceState = "w3c.tracestate"
43+
TagServiceNameSource = "otlp.service.name.source"
4644
)
4745

4846
// Constants used for signifying batch-level attribute values where not supplied by OTLP data but required

translator/trace/zipkin/traces_to_zipkinv2.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ func resourceSpansToZipkinSpans(rs pdata.ResourceSpans, estSpanCount int) ([]*zi
8484

8585
func extractInstrumentationLibraryTags(il pdata.InstrumentationLibrary, zTags map[string]string) {
8686
if ilName := il.Name(); ilName != "" {
87-
zTags[tracetranslator.TagInstrumentationName] = ilName
87+
zTags[conventions.InstrumentationLibraryName] = ilName
8888
}
8989
if ilVer := il.Version(); ilVer != "" {
90-
zTags[tracetranslator.TagInstrumentationVersion] = ilVer
90+
zTags[conventions.InstrumentationLibraryVersion] = ilVer
9191
}
9292
}
9393

translator/trace/zipkin/zipkinv2_to_traces.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,20 @@ import (
3131
tracetranslator "go.opentelemetry.io/collector/translator/trace"
3232
)
3333

34-
var nonSpanAttributes = getNonSpanAttributes()
35-
36-
func getNonSpanAttributes() map[string]struct{} {
34+
var nonSpanAttributes = func() map[string]struct{} {
3735
attrs := make(map[string]struct{})
3836
for _, key := range conventions.GetResourceSemanticConventionAttributeNames() {
3937
attrs[key] = struct{}{}
4038
}
4139
attrs[tracetranslator.TagServiceNameSource] = struct{}{}
42-
attrs[tracetranslator.TagInstrumentationName] = struct{}{}
43-
attrs[tracetranslator.TagInstrumentationVersion] = struct{}{}
40+
attrs[conventions.InstrumentationLibraryName] = struct{}{}
41+
attrs[conventions.InstrumentationLibraryVersion] = struct{}{}
4442
attrs[conventions.OCAttributeProcessStartTime] = struct{}{}
4543
attrs[conventions.OCAttributeExporterVersion] = struct{}{}
4644
attrs[conventions.AttributeProcessID] = struct{}{}
4745
attrs[conventions.OCAttributeResourceType] = struct{}{}
4846
return attrs
49-
}
47+
}()
5048

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

387-
for key := range getNonSpanAttributes() {
388-
if key == tracetranslator.TagInstrumentationName || key == tracetranslator.TagInstrumentationVersion {
385+
for key := range nonSpanAttributes {
386+
if key == conventions.InstrumentationLibraryName || key == conventions.InstrumentationLibraryVersion {
389387
continue
390388
}
391389
if value, ok := tags[key]; ok {
@@ -399,13 +397,13 @@ func populateILFromZipkinSpan(tags map[string]string, instrLibName string, libra
399397
if instrLibName == "" {
400398
return
401399
}
402-
if value, ok := tags[tracetranslator.TagInstrumentationName]; ok {
400+
if value, ok := tags[conventions.InstrumentationLibraryName]; ok {
403401
library.SetName(value)
404-
delete(tags, tracetranslator.TagInstrumentationName)
402+
delete(tags, conventions.InstrumentationLibraryName)
405403
}
406-
if value, ok := tags[tracetranslator.TagInstrumentationVersion]; ok {
404+
if value, ok := tags[conventions.InstrumentationLibraryVersion]; ok {
407405
library.SetVersion(value)
408-
delete(tags, tracetranslator.TagInstrumentationVersion)
406+
delete(tags, conventions.InstrumentationLibraryVersion)
409407
}
410408
}
411409

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

0 commit comments

Comments
 (0)