Skip to content

Commit

Permalink
Replace custom opencensus sematic conventions with otel semantic conv…
Browse files Browse the repository at this point in the history
…entions

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed Mar 2, 2021
1 parent 3e138d7 commit d91f657
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 44 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## 🛑 Breaking changes 🛑

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

## v0.21.0 Beta

Expand Down
43 changes: 23 additions & 20 deletions internal/goldendataset/span_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,33 +476,36 @@ func calculateListSize(listCnt PICTInputSpanChild) int {

func generateSpanEvent(index int) *otlptrace.Span_Event {
t := time.Now().Add(-75 * time.Microsecond)
name, attributes := generateEventNameAndAttributes(index)
return &otlptrace.Span_Event{
TimeUnixNano: uint64(t.UnixNano()),
Name: "message",
Attributes: generateEventAttributes(index),
Name: name,
Attributes: attributes,
DroppedAttributesCount: 0,
}
}

func generateEventAttributes(index int) []otlpcommon.KeyValue {
if index%4 == 2 {
return nil
}
attrMap := make(map[string]interface{})
if index%2 == 0 {
attrMap[conventions.AttributeMessageType] = "SENT"
} else {
attrMap[conventions.AttributeMessageType] = "RECEIVED"
}
attrMap[conventions.AttributeMessageID] = int64(index)
attrMap[conventions.AttributeMessageCompressedSize] = int64(17 * index)
attrMap[conventions.AttributeMessageUncompressedSize] = int64(24 * index)
if index%4 == 1 {
attrMap["app.inretry"] = true
attrMap["app.progress"] = 0.6
attrMap["app.statemap"] = "14|5|202"
func generateEventNameAndAttributes(index int) (string, []otlpcommon.KeyValue) {
switch index % 4 {
case 0, 3:
attrMap := make(map[string]interface{})
if index%2 == 0 {
attrMap[conventions.AttributeMessageType] = "SENT"
} else {
attrMap[conventions.AttributeMessageType] = "RECEIVED"
}
attrMap[conventions.AttributeMessageID] = int64(index / 4)
attrMap[conventions.AttributeMessageCompressedSize] = int64(17 * index)
attrMap[conventions.AttributeMessageUncompressedSize] = int64(24 * index)
return "message", convertMapToAttributeKeyValues(attrMap)
case 1:
return "custom", convertMapToAttributeKeyValues(map[string]interface{}{
"app.inretry": true,
"app.progress": 0.6,
"app.statemap": "14|5|202"})
default:
return "annotation", nil
}
return convertMapToAttributeKeyValues(attrMap)
}

func generateSpanLink(random io.Reader, index int) *otlptrace.Span_Link {
Expand Down
6 changes: 0 additions & 6 deletions translator/conventions/opencensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,9 @@ package conventions

// OTLP attributes to map certain OpenCensus proto fields. These fields don't have
// corresponding fields in OTLP, nor are defined in OTLP semantic conventions.
// TODO: decide if any of these must be in OTLP semantic conventions.
const (
OCAttributeProcessStartTime = "opencensus.starttime"
OCAttributeProcessID = "opencensus.pid"
OCAttributeExporterVersion = "opencensus.exporterversion"
OCAttributeResourceType = "opencensus.resourcetype"
OCAttributeSameProcessAsParentSpan = "opencensus.same_process_as_parent_span"
OCTimeEventMessageEventType = "opencensus.timeevent.messageevent.type"
OCTimeEventMessageEventID = "opencensus.timeevent.messageevent.id"
OCTimeEventMessageEventUSize = "opencensus.timeevent.messageevent.usize"
OCTimeEventMessageEventCSize = "opencensus.timeevent.messageevent.csize"
)
2 changes: 1 addition & 1 deletion translator/internaldata/metrics_to_oc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestMetricsToOC(t *testing.T) {
sampleMetricData := testdata.GeneratMetricsAllTypesWithSampleDatapoints()
attrs := sampleMetricData.ResourceMetrics().At(0).Resource().Attributes()
attrs.Upsert(conventions.AttributeHostName, pdata.NewAttributeValueString("host1"))
attrs.Upsert(conventions.OCAttributeProcessID, pdata.NewAttributeValueInt(123))
attrs.Upsert(conventions.AttributeProcessID, pdata.NewAttributeValueInt(123))
attrs.Upsert(conventions.OCAttributeProcessStartTime, pdata.NewAttributeValueString("2020-02-11T20:26:00Z"))
attrs.Upsert(conventions.AttributeTelemetrySDKLanguage, pdata.NewAttributeValueString("cpp"))
attrs.Upsert(conventions.AttributeTelemetrySDKVersion, pdata.NewAttributeValueString("v2.0.1"))
Expand Down
2 changes: 1 addition & 1 deletion translator/internaldata/oc_testdata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ func generateResourceWithOcNodeAndResource() pdata.Resource {
resource.Attributes().InitFromMap(map[string]pdata.AttributeValue{
conventions.OCAttributeProcessStartTime: pdata.NewAttributeValueString("2020-02-11T20:26:00Z"),
conventions.AttributeHostName: pdata.NewAttributeValueString("host1"),
conventions.OCAttributeProcessID: pdata.NewAttributeValueInt(123),
conventions.AttributeProcessID: pdata.NewAttributeValueInt(123),
conventions.AttributeTelemetrySDKVersion: pdata.NewAttributeValueString("v2.0.1"),
conventions.OCAttributeExporterVersion: pdata.NewAttributeValueString("v1.2.0"),
conventions.AttributeTelemetrySDKLanguage: pdata.NewAttributeValueString("cpp"),
Expand Down
2 changes: 1 addition & 1 deletion translator/internaldata/oc_to_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func ocNodeResourceToInternal(ocNode *occommon.Node, ocResource *ocresource.Reso
attrs.UpsertString(conventions.AttributeHostName, ocNode.Identifier.HostName)
}
if ocNode.Identifier.Pid != 0 {
attrs.UpsertInt(conventions.OCAttributeProcessID, int64(ocNode.Identifier.Pid))
attrs.UpsertInt(conventions.AttributeProcessID, int64(ocNode.Identifier.Pid))
}
}
if ocNode.LibraryInfo != nil {
Expand Down
9 changes: 5 additions & 4 deletions translator/internaldata/oc_to_traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ func ocEventsToInternal(ocEvents *octrace.Span_TimeEvents, dest pdata.Span) {
}

case *octrace.Span_TimeEvent_MessageEvent_:
event.SetName("message")
ocMessageEventToInternalAttrs(teValue.MessageEvent, event.Attributes())
// No dropped attributes for this case.
event.SetDroppedAttributesCount(0)
Expand Down Expand Up @@ -380,10 +381,10 @@ func ocMessageEventToInternalAttrs(msgEvent *octrace.Span_TimeEvent_MessageEvent
return
}

dest.UpsertString(conventions.OCTimeEventMessageEventType, msgEvent.Type.String())
dest.UpsertInt(conventions.OCTimeEventMessageEventID, int64(msgEvent.Id))
dest.UpsertInt(conventions.OCTimeEventMessageEventUSize, int64(msgEvent.UncompressedSize))
dest.UpsertInt(conventions.OCTimeEventMessageEventCSize, int64(msgEvent.CompressedSize))
dest.UpsertString(conventions.AttributeMessageType, msgEvent.Type.String())
dest.UpsertInt(conventions.AttributeMessageID, int64(msgEvent.Id))
dest.UpsertInt(conventions.AttributeMessageUncompressedSize, int64(msgEvent.UncompressedSize))
dest.UpsertInt(conventions.AttributeMessageCompressedSize, int64(msgEvent.CompressedSize))
}

func ocSameProcessAsParentSpanToInternal(spaps *wrapperspb.BoolValue, dest pdata.Span) {
Expand Down
2 changes: 1 addition & 1 deletion translator/internaldata/resource_to_oc.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func internalResourceToOC(resource pdata.Resource) (*occommon.Node, *ocresource.
getProcessIdentifier(ocNode).StartTimestamp = ts
case conventions.AttributeHostName:
getProcessIdentifier(ocNode).HostName = val
case conventions.OCAttributeProcessID:
case conventions.AttributeProcessID:
pid, err := strconv.Atoi(val)
if err != nil {
pid = defaultProcessID
Expand Down
7 changes: 6 additions & 1 deletion translator/internaldata/resource_to_oc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,12 @@ func TestResourceToOCAndBack(t *testing.T) {
assert.True(t, ok)
switch v.Type() {
case pdata.AttributeValueINT:
assert.Equal(t, strconv.FormatInt(v.IntVal(), 10), a.StringVal())
// conventions.AttributeProcessID is special because we preserve the type for this.
if k == conventions.AttributeProcessID {
assert.Equal(t, v.IntVal(), a.IntVal())
} else {
assert.Equal(t, strconv.FormatInt(v.IntVal(), 10), a.StringVal())
}
case pdata.AttributeValueMAP, pdata.AttributeValueARRAY:
assert.Equal(t, a, a)
default:
Expand Down
16 changes: 8 additions & 8 deletions translator/internaldata/traces_to_oc.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ func eventToOC(event pdata.SpanEvent) *octrace.Span_TimeEvent {

// Consider TimeEvent to be of MessageEvent type if all and only relevant attributes are set
ocMessageEventAttrs := []string{
conventions.OCTimeEventMessageEventType,
conventions.OCTimeEventMessageEventID,
conventions.OCTimeEventMessageEventUSize,
conventions.OCTimeEventMessageEventCSize,
conventions.AttributeMessageType,
conventions.AttributeMessageID,
conventions.AttributeMessageUncompressedSize,
conventions.AttributeMessageCompressedSize,
}
// TODO: Find a better way to check for message_event. Maybe use the event.Name.
if attrs.Len() == len(ocMessageEventAttrs) {
Expand All @@ -292,16 +292,16 @@ func eventToOC(event pdata.SpanEvent) *octrace.Span_TimeEvent {
ocMessageEventAttrValues[attr] = akv
}
if ocMessageEventAttrFound {
ocMessageEventType := ocMessageEventAttrValues[conventions.OCTimeEventMessageEventType]
ocMessageEventType := ocMessageEventAttrValues[conventions.AttributeMessageType]
ocMessageEventTypeVal := octrace.Span_TimeEvent_MessageEvent_Type_value[ocMessageEventType.StringVal()]
return &octrace.Span_TimeEvent{
Time: timestampAsTimestampPb(event.Timestamp()),
Value: &octrace.Span_TimeEvent_MessageEvent_{
MessageEvent: &octrace.Span_TimeEvent_MessageEvent{
Type: octrace.Span_TimeEvent_MessageEvent_Type(ocMessageEventTypeVal),
Id: uint64(ocMessageEventAttrValues[conventions.OCTimeEventMessageEventID].IntVal()),
UncompressedSize: uint64(ocMessageEventAttrValues[conventions.OCTimeEventMessageEventUSize].IntVal()),
CompressedSize: uint64(ocMessageEventAttrValues[conventions.OCTimeEventMessageEventCSize].IntVal()),
Id: uint64(ocMessageEventAttrValues[conventions.AttributeMessageID].IntVal()),
UncompressedSize: uint64(ocMessageEventAttrValues[conventions.AttributeMessageUncompressedSize].IntVal()),
CompressedSize: uint64(ocMessageEventAttrValues[conventions.AttributeMessageCompressedSize].IntVal()),
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion translator/trace/zipkin/zipkinv2_to_traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func getNonSpanAttributes() map[string]struct{} {
attrs[tracetranslator.TagInstrumentationVersion] = struct{}{}
attrs[conventions.OCAttributeProcessStartTime] = struct{}{}
attrs[conventions.OCAttributeExporterVersion] = struct{}{}
attrs[conventions.OCAttributeProcessID] = struct{}{}
attrs[conventions.AttributeProcessID] = struct{}{}
attrs[conventions.OCAttributeResourceType] = struct{}{}
return attrs
}
Expand Down

0 comments on commit d91f657

Please sign in to comment.