Skip to content

Commit

Permalink
processor/otel: handle net.host span attributes (#5719)
Browse files Browse the repository at this point in the history
We were mistakenly handling the new net.host
attributes as resource attributes, whereas they
should be span attributes; these fields describe
a network connection, which will be specific to
an operation (span), and not the service (resource)
performing that operation.

`net.host.connection_type` has been updated to
`net.host.connection.type`, per the spec change.
  • Loading branch information
axw authored Jul 15, 2021
1 parent a63733b commit 61bf74d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 44 deletions.
29 changes: 29 additions & 0 deletions processor/otel/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ const (
outcomeSuccess = "success"
outcomeFailure = "failure"
outcomeUnknown = "unknown"

// TODO: handle net.host.connection.subtype, which will
// require adding a new field to the model as well.

AttributeNetworkType = "net.host.connection.type"
AttributeNetworkMCC = "net.host.carrier.mcc"
AttributeNetworkMNC = "net.host.carrier.mnc"
AttributeNetworkCarrierName = "net.host.carrier.name"
AttributeNetworkICC = "net.host.carrier.icc"
)

// Consumer transforms open-telemetry data to be compatible with elastic APM data
Expand Down Expand Up @@ -335,6 +344,16 @@ func translateTransaction(
netPeerName = stringval
case conventions.AttributeNetHostName:
netHostName = stringval
case AttributeNetworkType:
tx.Metadata.System.Network.ConnectionType = stringval
case AttributeNetworkMCC:
tx.Metadata.System.Network.Carrier.MCC = stringval
case AttributeNetworkMNC:
tx.Metadata.System.Network.Carrier.MNC = stringval
case AttributeNetworkCarrierName:
tx.Metadata.System.Network.Carrier.Name = stringval
case AttributeNetworkICC:
tx.Metadata.System.Network.Carrier.ICC = stringval

// messaging.*
case "message_bus.destination", conventions.AttributeMessagingDestination:
Expand Down Expand Up @@ -545,6 +564,16 @@ func translateSpan(span pdata.Span, metadata model.Metadata, event *model.Span)
// values containing colons, except for IPv6.
netPeerName = stringval
}
case AttributeNetworkType:
event.Metadata.System.Network.ConnectionType = stringval
case AttributeNetworkMCC:
event.Metadata.System.Network.Carrier.MCC = stringval
case AttributeNetworkMNC:
event.Metadata.System.Network.Carrier.MNC = stringval
case AttributeNetworkCarrierName:
event.Metadata.System.Network.Carrier.Name = stringval
case AttributeNetworkICC:
event.Metadata.System.Network.Carrier.ICC = stringval

// messaging.*
case "message_bus.destination", conventions.AttributeMessagingDestination:
Expand Down
24 changes: 24 additions & 0 deletions processor/otel/consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,30 @@ func TestMessagingSpan(t *testing.T) {
}, span.DestinationService)
}

func TestSpanNetworkAttributes(t *testing.T) {
networkAttributes := map[string]pdata.AttributeValue{
"net.host.connection.type": pdata.NewAttributeValueString("5G"),
"net.host.carrier.name": pdata.NewAttributeValueString("Vodafone"),
"net.host.carrier.mnc": pdata.NewAttributeValueString("01"),
"net.host.carrier.mcc": pdata.NewAttributeValueString("101"),
"net.host.carrier.icc": pdata.NewAttributeValueString("UK"),
}
tx := transformTransactionWithAttributes(t, networkAttributes)
span := transformSpanWithAttributes(t, networkAttributes)

expected := model.Network{
ConnectionType: "5G",
Carrier: model.Carrier{
Name: "Vodafone",
MNC: "01",
MCC: "101",
ICC: "UK",
},
}
assert.Equal(t, expected, tx.Metadata.System.Network)
assert.Equal(t, expected, span.Metadata.System.Network)
}

func TestArrayLabels(t *testing.T) {
stringArray := pdata.NewAttributeValueArray()
stringArray.ArrayVal().Append(pdata.NewAttributeValueString("string1"))
Expand Down
21 changes: 0 additions & 21 deletions processor/otel/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ import (

const (
AgentNameJaeger = "Jaeger"

// Network attributes are pending approval in the OTel spec, and subject to change:
// https://github.com/open-telemetry/opentelemetry-specification/issues/1647

AttributeNetworkType = "net.host.connection_type"
AttributeNetworkMCC = "net.host.carrier.mcc"
AttributeNetworkMNC = "net.host.carrier.mnc"
AttributeNetworkCarrierName = "net.host.carrier.name"
AttributeNetworkICC = "net.host.carrier.icc"
)

var (
Expand Down Expand Up @@ -105,18 +96,6 @@ func translateResourceMetadata(resource pdata.Resource, out *model.Metadata) {
case conventions.AttributeK8sPodUID:
out.System.Kubernetes.PodUID = truncate(v.StringVal())

// network.*
case AttributeNetworkType:
out.System.Network.ConnectionType = truncate(v.StringVal())
case AttributeNetworkCarrierName:
out.System.Network.Carrier.Name = truncate(v.StringVal())
case AttributeNetworkMCC:
out.System.Network.Carrier.MCC = truncate(v.StringVal())
case AttributeNetworkMNC:
out.System.Network.Carrier.MNC = truncate(v.StringVal())
case AttributeNetworkICC:
out.System.Network.Carrier.ICC = truncate(v.StringVal())

// host.*
case conventions.AttributeHostName:
out.System.DetectedHostname = truncate(v.StringVal())
Expand Down
23 changes: 0 additions & 23 deletions processor/otel/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,29 +194,6 @@ func TestResourceConventions(t *testing.T) {
},
},
},
"network": {
attrs: map[string]pdata.AttributeValue{
"net.host.connection_type": pdata.NewAttributeValueString("5G"),
"net.host.carrier.name": pdata.NewAttributeValueString("Vodafone"),
"net.host.carrier.mnc": pdata.NewAttributeValueString("01"),
"net.host.carrier.mcc": pdata.NewAttributeValueString("101"),
"net.host.carrier.icc": pdata.NewAttributeValueString("UK"),
},
expected: model.Metadata{
Service: defaultService,
System: model.System{
Network: model.Network{
ConnectionType: "5G",
Carrier: model.Carrier{
Name: "Vodafone",
MNC: "01",
MCC: "101",
ICC: "UK",
},
},
},
},
},
} {
t.Run(name, func(t *testing.T) {
meta := transformResourceMetadata(t, test.attrs)
Expand Down

0 comments on commit 61bf74d

Please sign in to comment.