Skip to content

Commit d91f657

Browse files
committed
Replace custom opencensus sematic conventions with otel semantic conventions
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
1 parent 3e138d7 commit d91f657

File tree

11 files changed

+48
-44
lines changed

11 files changed

+48
-44
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
## 🛑 Breaking changes 🛑
66

77
- Remove `consumerdata.TraceData` (#2551)
8+
- Remove custom OpenCensus sematic conventions that have equivalent in otel (#2552)
89

910
## v0.21.0 Beta
1011

internal/goldendataset/span_generator.go

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -476,33 +476,36 @@ func calculateListSize(listCnt PICTInputSpanChild) int {
476476

477477
func generateSpanEvent(index int) *otlptrace.Span_Event {
478478
t := time.Now().Add(-75 * time.Microsecond)
479+
name, attributes := generateEventNameAndAttributes(index)
479480
return &otlptrace.Span_Event{
480481
TimeUnixNano: uint64(t.UnixNano()),
481-
Name: "message",
482-
Attributes: generateEventAttributes(index),
482+
Name: name,
483+
Attributes: attributes,
483484
DroppedAttributesCount: 0,
484485
}
485486
}
486487

487-
func generateEventAttributes(index int) []otlpcommon.KeyValue {
488-
if index%4 == 2 {
489-
return nil
490-
}
491-
attrMap := make(map[string]interface{})
492-
if index%2 == 0 {
493-
attrMap[conventions.AttributeMessageType] = "SENT"
494-
} else {
495-
attrMap[conventions.AttributeMessageType] = "RECEIVED"
496-
}
497-
attrMap[conventions.AttributeMessageID] = int64(index)
498-
attrMap[conventions.AttributeMessageCompressedSize] = int64(17 * index)
499-
attrMap[conventions.AttributeMessageUncompressedSize] = int64(24 * index)
500-
if index%4 == 1 {
501-
attrMap["app.inretry"] = true
502-
attrMap["app.progress"] = 0.6
503-
attrMap["app.statemap"] = "14|5|202"
488+
func generateEventNameAndAttributes(index int) (string, []otlpcommon.KeyValue) {
489+
switch index % 4 {
490+
case 0, 3:
491+
attrMap := make(map[string]interface{})
492+
if index%2 == 0 {
493+
attrMap[conventions.AttributeMessageType] = "SENT"
494+
} else {
495+
attrMap[conventions.AttributeMessageType] = "RECEIVED"
496+
}
497+
attrMap[conventions.AttributeMessageID] = int64(index / 4)
498+
attrMap[conventions.AttributeMessageCompressedSize] = int64(17 * index)
499+
attrMap[conventions.AttributeMessageUncompressedSize] = int64(24 * index)
500+
return "message", convertMapToAttributeKeyValues(attrMap)
501+
case 1:
502+
return "custom", convertMapToAttributeKeyValues(map[string]interface{}{
503+
"app.inretry": true,
504+
"app.progress": 0.6,
505+
"app.statemap": "14|5|202"})
506+
default:
507+
return "annotation", nil
504508
}
505-
return convertMapToAttributeKeyValues(attrMap)
506509
}
507510

508511
func generateSpanLink(random io.Reader, index int) *otlptrace.Span_Link {

translator/conventions/opencensus.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,9 @@ package conventions
1616

1717
// OTLP attributes to map certain OpenCensus proto fields. These fields don't have
1818
// corresponding fields in OTLP, nor are defined in OTLP semantic conventions.
19-
// TODO: decide if any of these must be in OTLP semantic conventions.
2019
const (
2120
OCAttributeProcessStartTime = "opencensus.starttime"
22-
OCAttributeProcessID = "opencensus.pid"
2321
OCAttributeExporterVersion = "opencensus.exporterversion"
2422
OCAttributeResourceType = "opencensus.resourcetype"
2523
OCAttributeSameProcessAsParentSpan = "opencensus.same_process_as_parent_span"
26-
OCTimeEventMessageEventType = "opencensus.timeevent.messageevent.type"
27-
OCTimeEventMessageEventID = "opencensus.timeevent.messageevent.id"
28-
OCTimeEventMessageEventUSize = "opencensus.timeevent.messageevent.usize"
29-
OCTimeEventMessageEventCSize = "opencensus.timeevent.messageevent.csize"
3024
)

translator/internaldata/metrics_to_oc_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestMetricsToOC(t *testing.T) {
3434
sampleMetricData := testdata.GeneratMetricsAllTypesWithSampleDatapoints()
3535
attrs := sampleMetricData.ResourceMetrics().At(0).Resource().Attributes()
3636
attrs.Upsert(conventions.AttributeHostName, pdata.NewAttributeValueString("host1"))
37-
attrs.Upsert(conventions.OCAttributeProcessID, pdata.NewAttributeValueInt(123))
37+
attrs.Upsert(conventions.AttributeProcessID, pdata.NewAttributeValueInt(123))
3838
attrs.Upsert(conventions.OCAttributeProcessStartTime, pdata.NewAttributeValueString("2020-02-11T20:26:00Z"))
3939
attrs.Upsert(conventions.AttributeTelemetrySDKLanguage, pdata.NewAttributeValueString("cpp"))
4040
attrs.Upsert(conventions.AttributeTelemetrySDKVersion, pdata.NewAttributeValueString("v2.0.1"))

translator/internaldata/oc_testdata_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ func generateResourceWithOcNodeAndResource() pdata.Resource {
499499
resource.Attributes().InitFromMap(map[string]pdata.AttributeValue{
500500
conventions.OCAttributeProcessStartTime: pdata.NewAttributeValueString("2020-02-11T20:26:00Z"),
501501
conventions.AttributeHostName: pdata.NewAttributeValueString("host1"),
502-
conventions.OCAttributeProcessID: pdata.NewAttributeValueInt(123),
502+
conventions.AttributeProcessID: pdata.NewAttributeValueInt(123),
503503
conventions.AttributeTelemetrySDKVersion: pdata.NewAttributeValueString("v2.0.1"),
504504
conventions.OCAttributeExporterVersion: pdata.NewAttributeValueString("v1.2.0"),
505505
conventions.AttributeTelemetrySDKLanguage: pdata.NewAttributeValueString("cpp"),

translator/internaldata/oc_to_resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func ocNodeResourceToInternal(ocNode *occommon.Node, ocResource *ocresource.Reso
101101
attrs.UpsertString(conventions.AttributeHostName, ocNode.Identifier.HostName)
102102
}
103103
if ocNode.Identifier.Pid != 0 {
104-
attrs.UpsertInt(conventions.OCAttributeProcessID, int64(ocNode.Identifier.Pid))
104+
attrs.UpsertInt(conventions.AttributeProcessID, int64(ocNode.Identifier.Pid))
105105
}
106106
}
107107
if ocNode.LibraryInfo != nil {

translator/internaldata/oc_to_traces.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ func ocEventsToInternal(ocEvents *octrace.Span_TimeEvents, dest pdata.Span) {
328328
}
329329

330330
case *octrace.Span_TimeEvent_MessageEvent_:
331+
event.SetName("message")
331332
ocMessageEventToInternalAttrs(teValue.MessageEvent, event.Attributes())
332333
// No dropped attributes for this case.
333334
event.SetDroppedAttributesCount(0)
@@ -380,10 +381,10 @@ func ocMessageEventToInternalAttrs(msgEvent *octrace.Span_TimeEvent_MessageEvent
380381
return
381382
}
382383

383-
dest.UpsertString(conventions.OCTimeEventMessageEventType, msgEvent.Type.String())
384-
dest.UpsertInt(conventions.OCTimeEventMessageEventID, int64(msgEvent.Id))
385-
dest.UpsertInt(conventions.OCTimeEventMessageEventUSize, int64(msgEvent.UncompressedSize))
386-
dest.UpsertInt(conventions.OCTimeEventMessageEventCSize, int64(msgEvent.CompressedSize))
384+
dest.UpsertString(conventions.AttributeMessageType, msgEvent.Type.String())
385+
dest.UpsertInt(conventions.AttributeMessageID, int64(msgEvent.Id))
386+
dest.UpsertInt(conventions.AttributeMessageUncompressedSize, int64(msgEvent.UncompressedSize))
387+
dest.UpsertInt(conventions.AttributeMessageCompressedSize, int64(msgEvent.CompressedSize))
387388
}
388389

389390
func ocSameProcessAsParentSpanToInternal(spaps *wrapperspb.BoolValue, dest pdata.Span) {

translator/internaldata/resource_to_oc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func internalResourceToOC(resource pdata.Resource) (*occommon.Node, *ocresource.
104104
getProcessIdentifier(ocNode).StartTimestamp = ts
105105
case conventions.AttributeHostName:
106106
getProcessIdentifier(ocNode).HostName = val
107-
case conventions.OCAttributeProcessID:
107+
case conventions.AttributeProcessID:
108108
pid, err := strconv.Atoi(val)
109109
if err != nil {
110110
pid = defaultProcessID

translator/internaldata/resource_to_oc_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,12 @@ func TestResourceToOCAndBack(t *testing.T) {
249249
assert.True(t, ok)
250250
switch v.Type() {
251251
case pdata.AttributeValueINT:
252-
assert.Equal(t, strconv.FormatInt(v.IntVal(), 10), a.StringVal())
252+
// conventions.AttributeProcessID is special because we preserve the type for this.
253+
if k == conventions.AttributeProcessID {
254+
assert.Equal(t, v.IntVal(), a.IntVal())
255+
} else {
256+
assert.Equal(t, strconv.FormatInt(v.IntVal(), 10), a.StringVal())
257+
}
253258
case pdata.AttributeValueMAP, pdata.AttributeValueARRAY:
254259
assert.Equal(t, a, a)
255260
default:

translator/internaldata/traces_to_oc.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,10 @@ func eventToOC(event pdata.SpanEvent) *octrace.Span_TimeEvent {
275275

276276
// Consider TimeEvent to be of MessageEvent type if all and only relevant attributes are set
277277
ocMessageEventAttrs := []string{
278-
conventions.OCTimeEventMessageEventType,
279-
conventions.OCTimeEventMessageEventID,
280-
conventions.OCTimeEventMessageEventUSize,
281-
conventions.OCTimeEventMessageEventCSize,
278+
conventions.AttributeMessageType,
279+
conventions.AttributeMessageID,
280+
conventions.AttributeMessageUncompressedSize,
281+
conventions.AttributeMessageCompressedSize,
282282
}
283283
// TODO: Find a better way to check for message_event. Maybe use the event.Name.
284284
if attrs.Len() == len(ocMessageEventAttrs) {
@@ -292,16 +292,16 @@ func eventToOC(event pdata.SpanEvent) *octrace.Span_TimeEvent {
292292
ocMessageEventAttrValues[attr] = akv
293293
}
294294
if ocMessageEventAttrFound {
295-
ocMessageEventType := ocMessageEventAttrValues[conventions.OCTimeEventMessageEventType]
295+
ocMessageEventType := ocMessageEventAttrValues[conventions.AttributeMessageType]
296296
ocMessageEventTypeVal := octrace.Span_TimeEvent_MessageEvent_Type_value[ocMessageEventType.StringVal()]
297297
return &octrace.Span_TimeEvent{
298298
Time: timestampAsTimestampPb(event.Timestamp()),
299299
Value: &octrace.Span_TimeEvent_MessageEvent_{
300300
MessageEvent: &octrace.Span_TimeEvent_MessageEvent{
301301
Type: octrace.Span_TimeEvent_MessageEvent_Type(ocMessageEventTypeVal),
302-
Id: uint64(ocMessageEventAttrValues[conventions.OCTimeEventMessageEventID].IntVal()),
303-
UncompressedSize: uint64(ocMessageEventAttrValues[conventions.OCTimeEventMessageEventUSize].IntVal()),
304-
CompressedSize: uint64(ocMessageEventAttrValues[conventions.OCTimeEventMessageEventCSize].IntVal()),
302+
Id: uint64(ocMessageEventAttrValues[conventions.AttributeMessageID].IntVal()),
303+
UncompressedSize: uint64(ocMessageEventAttrValues[conventions.AttributeMessageUncompressedSize].IntVal()),
304+
CompressedSize: uint64(ocMessageEventAttrValues[conventions.AttributeMessageCompressedSize].IntVal()),
305305
},
306306
},
307307
}

0 commit comments

Comments
 (0)