Skip to content

Commit

Permalink
[receiver/solacereceiver]: Updates to Solace Receiver to use latest s…
Browse files Browse the repository at this point in the history
…emantic conventions - v1.25.0 (#33499)

**Description:** Updated the relevant attribute keys to match the latest
semantic conventions (v1.25.0).

**Testing:** Updated unit tests to accommodate renamed attribute keys
  • Loading branch information
oodigie committed Jun 19, 2024
1 parent 10a3f5a commit 3bd16df
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 68 deletions.
27 changes: 27 additions & 0 deletions .chloggen/solacereceiver_update_attribute_names.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: solacereceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Renamed some SemConv fields to support latest semantic conventions for messaging spans (version `1.25.0`)"

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [33499]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
28 changes: 15 additions & 13 deletions receiver/solacereceiver/unmarshaller.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,13 @@ const (

// span keys
const (
protocolAttrKey = "messaging.protocol"
protocolVersionAttrKey = "messaging.protocol_version"
messageIDAttrKey = "messaging.message_id"
conversationIDAttrKey = "messaging.conversation_id"
payloadSizeBytesAttrKey = "messaging.message_payload_size_bytes"
destinationAttrKey = "messaging.destination"
protocolAttrKey = "network.protocol.name"
protocolVersionAttrKey = "network.protocol.version"
messageIDAttrKey = "messaging.message.id"
conversationIDAttrKey = "messaging.message.conversation_id"
messageBodySizeBytesAttrKey = "messaging.message.body.size"
messageEnvelopeSizeBytesAttrKey = "messaging.message.envelope.size"
destinationNameAttrKey = "messaging.destination.name"
clientUsernameAttrKey = "messaging.solace.client_username"
clientNameAttrKey = "messaging.solace.client_name"
replicationGroupMessageIDAttrKey = "messaging.solace.replication_group_message_id"
Expand All @@ -131,17 +132,18 @@ const (
receiveTimeAttrKey = "messaging.solace.broker_receive_time_unix_nano"
droppedUserPropertiesAttrKey = "messaging.solace.dropped_application_message_properties"
deliveryModeAttrKey = "messaging.solace.delivery_mode"
hostIPAttrKey = "net.host.ip"
hostPortAttrKey = "net.host.port"
peerIPAttrKey = "net.peer.ip"
peerPortAttrKey = "net.peer.port"
hostIPAttrKey = "server.address"
hostPortAttrKey = "server.port"
peerIPAttrKey = "network.peer.address"
peerPortAttrKey = "network.peer.port"
)

// constant attributes
const (
systemAttrKey = "messaging.system"
systemAttrValue = "SolacePubSub+"
operationAttrKey = "messaging.operation"
systemAttrKey = "messaging.system"
systemAttrValue = "SolacePubSub+"
operationNameAttrKey = "messaging.operation.name"
operationTypeAttrKey = "messaging.operation.type"
)

func setResourceSpanAttributes(attrMap pcommon.Map, routerName, version string, messageVpnName *string) {
Expand Down
12 changes: 7 additions & 5 deletions receiver/solacereceiver/unmarshaller_egress.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,19 @@ func (u *brokerTraceEgressUnmarshallerV1) mapSendSpan(sendSpan *egress_v1.SpanDa
outcomeKey = "messaging.solace.send.outcome"
)
const (
sendSpanOperation = "send"
sendNameSuffix = " send"
unknownSendName = "(unknown)"
anonymousSendName = "(anonymous)"
sendSpanOperationName = "send"
sendSpanOperationType = "publish"
sendNameSuffix = " send"
unknownSendName = "(unknown)"
anonymousSendName = "(anonymous)"
)
// hard coded to producer span
span.SetKind(ptrace.SpanKindProducer)

attributes := span.Attributes()
attributes.PutStr(systemAttrKey, systemAttrValue)
attributes.PutStr(operationAttrKey, sendSpanOperation)
attributes.PutStr(operationNameAttrKey, sendSpanOperationName)
attributes.PutStr(operationTypeAttrKey, sendSpanOperationType)
attributes.PutStr(protocolAttrKey, sendSpan.Protocol)
if sendSpan.ProtocolVersion != nil {
attributes.PutStr(protocolVersionAttrKey, *sendSpan.ProtocolVersion)
Expand Down
28 changes: 16 additions & 12 deletions receiver/solacereceiver/unmarshaller_egress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ var validEgressSpans = []struct {
span.SetKind(4)
spanAttrs := span.Attributes()
spanAttrs.PutStr("messaging.system", "SolacePubSub+")
spanAttrs.PutStr("messaging.operation", "send")
spanAttrs.PutStr("messaging.protocol", "SMF")
spanAttrs.PutStr("messaging.protocol_version", "3.0")
spanAttrs.PutStr("messaging.operation.name", "send") // Operation name
spanAttrs.PutStr("messaging.operation.type", "publish") // Operation type
spanAttrs.PutStr("network.protocol.name", "SMF")
spanAttrs.PutStr("network.protocol.version", "3.0")
spanAttrs.PutStr("messaging.source.name", "someQueue")
spanAttrs.PutStr("messaging.source.kind", "queue")
spanAttrs.PutStr("messaging.solace.client_username", "clientUsername")
Expand Down Expand Up @@ -174,9 +175,10 @@ var validEgressSpans = []struct {
span.Status().SetMessage("someErrorOccurred")
spanAttrs := span.Attributes()
spanAttrs.PutStr("messaging.system", "SolacePubSub+")
spanAttrs.PutStr("messaging.operation", "send")
spanAttrs.PutStr("messaging.protocol", "MQTT")
spanAttrs.PutStr("messaging.protocol_version", "5.0")
spanAttrs.PutStr("messaging.operation.name", "send")
spanAttrs.PutStr("messaging.operation.type", "publish")
spanAttrs.PutStr("network.protocol.name", "MQTT")
spanAttrs.PutStr("network.protocol.version", "5.0")
spanAttrs.PutStr("messaging.source.name", "queueName")
spanAttrs.PutStr("messaging.source.kind", "queue")
spanAttrs.PutStr("messaging.solace.client_username", "someClientUsername")
Expand Down Expand Up @@ -239,9 +241,10 @@ var validEgressSpans = []struct {
span.SetKind(4)
spanAttrs := span.Attributes()
spanAttrs.PutStr("messaging.system", "SolacePubSub+")
spanAttrs.PutStr("messaging.operation", "send")
spanAttrs.PutStr("messaging.protocol", "AMQP")
spanAttrs.PutStr("messaging.protocol_version", "1.0")
spanAttrs.PutStr("messaging.operation.name", "send")
spanAttrs.PutStr("messaging.operation.type", "publish")
spanAttrs.PutStr("network.protocol.name", "AMQP")
spanAttrs.PutStr("network.protocol.version", "1.0")
spanAttrs.PutStr("messaging.source.name", "topicEndpointName")
spanAttrs.PutStr("messaging.source.kind", "topic-endpoint")
spanAttrs.PutStr("messaging.solace.client_username", "someOtherClientUsername")
Expand Down Expand Up @@ -314,9 +317,10 @@ func TestEgressUnmarshallerSendSpanAttributes(t *testing.T) {
getSpan := func(attributes map[string]any, name string) ptrace.Span {
base := map[string]any{
"messaging.system": "SolacePubSub+",
"messaging.operation": "send",
"messaging.protocol": "MQTT",
"messaging.protocol_version": "5.0",
"messaging.operation.name": "send",
"messaging.operation.type": "publish",
"network.protocol.name": "MQTT",
"network.protocol.version": "5.0",
"messaging.solace.client_username": "someUser",
"messaging.solace.client_name": "someName",
"messaging.solace.message_replayed": false,
Expand Down
10 changes: 6 additions & 4 deletions receiver/solacereceiver/unmarshaller_receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ func (u *brokerTraceReceiveUnmarshallerV1) mapClientSpanData(spanData *receive_v
// Will also copy any user properties stored in the SpanData with a best effort approach.
func (u *brokerTraceReceiveUnmarshallerV1) mapClientSpanAttributes(spanData *receive_v1.SpanData, attrMap pcommon.Map) {
// receive operation
const operationAttrValue = "receive"
const operationTypeAttrValue = "receive"
attrMap.PutStr(systemAttrKey, systemAttrValue)
attrMap.PutStr(operationAttrKey, operationAttrValue)
attrMap.PutStr(operationNameAttrKey, operationTypeAttrValue)
attrMap.PutStr(operationTypeAttrKey, operationTypeAttrValue)

attrMap.PutStr(protocolAttrKey, spanData.Protocol)
if spanData.ProtocolVersion != nil {
Expand All @@ -125,11 +126,12 @@ func (u *brokerTraceReceiveUnmarshallerV1) mapClientSpanAttributes(spanData *rec
if spanData.CorrelationId != nil {
attrMap.PutStr(conversationIDAttrKey, *spanData.CorrelationId)
}
attrMap.PutInt(payloadSizeBytesAttrKey, int64(spanData.BinaryAttachmentSize+spanData.XmlAttachmentSize+spanData.MetadataSize))
attrMap.PutInt(messageBodySizeBytesAttrKey, int64(spanData.BinaryAttachmentSize+spanData.XmlAttachmentSize)) // only message payload
attrMap.PutInt(messageEnvelopeSizeBytesAttrKey, int64(spanData.BinaryAttachmentSize+spanData.XmlAttachmentSize+spanData.MetadataSize)) // payload with metadata
attrMap.PutStr(clientUsernameAttrKey, spanData.ClientUsername)
attrMap.PutStr(clientNameAttrKey, spanData.ClientName)
attrMap.PutInt(receiveTimeAttrKey, spanData.BrokerReceiveTimeUnixNano)
attrMap.PutStr(destinationAttrKey, spanData.Topic)
attrMap.PutStr(destinationNameAttrKey, spanData.Topic)

var deliveryMode string
switch spanData.DeliveryMode {
Expand Down
52 changes: 29 additions & 23 deletions receiver/solacereceiver/unmarshaller_receive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,15 @@ func TestReceiveUnmarshallerMapClientSpanAttributes(t *testing.T) {
},
want: map[string]any{
"messaging.system": "SolacePubSub+",
"messaging.operation": "receive",
"messaging.protocol": "MQTT",
"messaging.protocol_version": "5.0",
"messaging.message_id": "someMessageID",
"messaging.conversation_id": "someConversationID",
"messaging.message_payload_size_bytes": int64(1234),
"messaging.destination": "someTopic",
"messaging.operation.name": "receive",
"messaging.operation.type": "receive",
"network.protocol.name": "MQTT",
"network.protocol.version": "5.0",
"messaging.message.id": "someMessageID",
"messaging.message.conversation_id": "someConversationID", // message correlation ID
"messaging.message.body.size": int64(1200), // payload (binary + xml attachments)
"messaging.message.envelope.size": int64(1234), // payload with metadata
"messaging.destination.name": "someTopic",
"messaging.solace.client_username": "someClientUsername",
"messaging.solace.client_name": "someClient1234",
"messaging.solace.replication_group_message_id": "rmid1:00010-40910192431-40516479-90a9c4e1",
Expand All @@ -202,10 +204,10 @@ func TestReceiveUnmarshallerMapClientSpanAttributes(t *testing.T) {
"messaging.solace.dropped_enqueue_events_failed": int64(24),
"messaging.solace.reply_to_topic": "someReplyToTopic",
"messaging.solace.delivery_mode": "persistent",
"net.host.ip": "1.2.3.4",
"net.host.port": int64(55555),
"net.peer.ip": "2345:425:2ca1::567:5673:23b5",
"net.peer.port": int64(12345),
"server.address": "1.2.3.4",
"server.port": int64(55555),
"network.peer.address": "2345:425:2ca1::567:5673:23b5",
"network.peer.port": int64(12345),
"messaging.solace.user_properties.special_key": true,
"messaging.solace.broker_receive_time_unix_nano": int64(1357924680),
"messaging.solace.dropped_application_message_properties": false,
Expand Down Expand Up @@ -241,20 +243,22 @@ func TestReceiveUnmarshallerMapClientSpanAttributes(t *testing.T) {
},
want: map[string]any{
"messaging.system": "SolacePubSub+",
"messaging.operation": "receive",
"messaging.protocol": "MQTT",
"messaging.message_payload_size_bytes": int64(1234),
"messaging.destination": "someTopic",
"messaging.operation.name": "receive",
"messaging.operation.type": "receive",
"network.protocol.name": "MQTT",
"messaging.message.body.size": int64(1200), // payload (binary + xml attachments)
"messaging.message.envelope.size": int64(1234), // payload with metadata
"messaging.destination.name": "someTopic",
"messaging.solace.client_username": "someClientUsername",
"messaging.solace.client_name": "someClient1234",
"messaging.solace.dmq_eligible": true,
"messaging.solace.delivery_mode": "non_persistent",
"messaging.solace.dropped_enqueue_events_success": int64(42),
"messaging.solace.dropped_enqueue_events_failed": int64(24),
"net.host.ip": "1.2.3.4",
"net.host.port": int64(55555),
"net.peer.ip": "2345:425:2ca1::567:5673:23b5",
"net.peer.port": int64(12345),
"server.address": "1.2.3.4",
"server.port": int64(55555),
"network.peer.address": "2345:425:2ca1::567:5673:23b5",
"network.peer.port": int64(12345),
"messaging.solace.broker_receive_time_unix_nano": int64(1357924680),
"messaging.solace.dropped_application_message_properties": true,
},
Expand Down Expand Up @@ -285,10 +289,12 @@ func TestReceiveUnmarshallerMapClientSpanAttributes(t *testing.T) {
// we no longer expect the port when the IP is not present
want: map[string]any{
"messaging.system": "SolacePubSub+",
"messaging.operation": "receive",
"messaging.protocol": "MQTT",
"messaging.message_payload_size_bytes": int64(1234),
"messaging.destination": "someTopic",
"messaging.operation.name": "receive",
"messaging.operation.type": "receive",
"network.protocol.name": "MQTT",
"messaging.message.body.size": int64(1200), // payload (binary + xml attachments)
"messaging.message.envelope.size": int64(1234), // payload with metadata
"messaging.destination.name": "someTopic",
"messaging.solace.client_username": "someClientUsername",
"messaging.solace.client_name": "someClient1234",
"messaging.solace.dmq_eligible": true,
Expand Down
24 changes: 13 additions & 11 deletions receiver/solacereceiver/unmarshaller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,15 @@ func TestSolaceMessageUnmarshallerUnmarshal(t *testing.T) {
spanAttrs := span.Attributes()
populateAttributes(t, spanAttrs, map[string]any{
"messaging.system": "SolacePubSub+",
"messaging.operation": "receive",
"messaging.protocol": "MQTT",
"messaging.protocol_version": "5.0",
"messaging.message_id": "someMessageID",
"messaging.conversation_id": "someConversationID",
"messaging.message_payload_size_bytes": int64(1234),
"messaging.destination": "someTopic",
"messaging.operation.name": "receive",
"messaging.operation.type": "receive",
"network.protocol.name": "MQTT",
"network.protocol.version": "5.0",
"messaging.message.id": "someMessageID",
"messaging.message.conversation_id": "someConversationID", // message correlation ID
"messaging.message.body.size": int64(1200), // payload (binary + xml attachments)
"messaging.message.envelope.size": int64(1234), // payload with metadata
"messaging.destination.name": "someTopic",
"messaging.solace.client_username": "someClientUsername",
"messaging.solace.client_name": "someClient1234",
"messaging.solace.replication_group_message_id": "rmid1:00010-40910192431-40516479-90a9c4e1",
Expand All @@ -241,10 +243,10 @@ func TestSolaceMessageUnmarshallerUnmarshal(t *testing.T) {
"messaging.solace.broker_receive_time_unix_nano": int64(1357924680),
"messaging.solace.dropped_application_message_properties": false,
"messaging.solace.delivery_mode": "direct",
"net.host.ip": "1.2.3.4",
"net.host.port": int64(55555),
"net.peer.ip": "2345:425:2ca1::567:5673:23b5",
"net.peer.port": int64(12345),
"server.address": "1.2.3.4",
"server.port": int64(55555),
"network.peer.address": "2345:425:2ca1::567:5673:23b5",
"network.peer.port": int64(12345),
"messaging.solace.user_properties.special_key": true,
})
populateEvent(t, span, "somequeue enqueue", 123456789, map[string]any{
Expand Down

0 comments on commit 3bd16df

Please sign in to comment.