From 61bf74db1bd92adad64f0c74ad947f6860836c1a Mon Sep 17 00:00:00 2001 From: Andrew Wilkins Date: Thu, 15 Jul 2021 13:48:40 +0800 Subject: [PATCH] processor/otel: handle net.host span attributes (#5719) 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. --- processor/otel/consumer.go | 29 +++++++++++++++++++++++++++++ processor/otel/consumer_test.go | 24 ++++++++++++++++++++++++ processor/otel/metadata.go | 21 --------------------- processor/otel/metadata_test.go | 23 ----------------------- 4 files changed, 53 insertions(+), 44 deletions(-) diff --git a/processor/otel/consumer.go b/processor/otel/consumer.go index 85e2c1e892e..dc2d3ecfbb0 100644 --- a/processor/otel/consumer.go +++ b/processor/otel/consumer.go @@ -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 @@ -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: @@ -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: diff --git a/processor/otel/consumer_test.go b/processor/otel/consumer_test.go index f52d0b2e9c1..20c11339d7b 100644 --- a/processor/otel/consumer_test.go +++ b/processor/otel/consumer_test.go @@ -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")) diff --git a/processor/otel/metadata.go b/processor/otel/metadata.go index 427ef5f9b33..c905318c9cd 100644 --- a/processor/otel/metadata.go +++ b/processor/otel/metadata.go @@ -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 ( @@ -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()) diff --git a/processor/otel/metadata_test.go b/processor/otel/metadata_test.go index 78c3e8a0f1c..606c6dc16fa 100644 --- a/processor/otel/metadata_test.go +++ b/processor/otel/metadata_test.go @@ -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)