Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

translate otel messaging.* to ecs #5334

Merged
merged 15 commits into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelogs/head.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ https://github.com/elastic/apm-server/compare/7.13\...master[View commits]
* Support setting agent configuration from apm-server.yml {pull}5177[5177]
* Add metric_type and unit to field metadata of system metrics {pull}5230[5230]
* Upgrade Go to 1.15.12 {pull}[]
* Translate otel messaging.* semantic conventions to ECS {pull}5334[5334]
* Add support for dynamic histogram metrics {pull}5239[5239]

[float]
Expand Down
34 changes: 26 additions & 8 deletions processor/otel/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,8 @@ func translateTransaction(
case conventions.AttributeNetHostName:
netHostName = stringval

// messaging
//
// TODO(axw) translate OpenTelemtry messaging conventions.
case "message_bus.destination":
// messaging.*
case "message_bus.destination", conventions.AttributeMessagingDestination:
message.QueueName = stringval
isMessaging = true

Expand Down Expand Up @@ -425,6 +423,11 @@ func translateSpan(span pdata.Span, metadata model.Metadata, event *model.Span)
httpScheme string = "http"
)

var (
messageSystem string
messageOperation string
)

var http model.HTTP
var message model.Message
var db model.DB
Expand Down Expand Up @@ -517,12 +520,21 @@ func translateSpan(span pdata.Span, metadata model.Metadata, event *model.Span)
netPeerName = stringval
}

// messaging
//
// TODO(axw) translate OpenTelemtry messaging conventions.
case "message_bus.destination":
// messaging.*
case "message_bus.destination", conventions.AttributeMessagingDestination:
message.QueueName = stringval
isMessagingSpan = true
case conventions.AttributeMessagingOperation:
if stringval == "" && span.Kind() == pdata.SpanKindPRODUCER {
stuartnelson3 marked this conversation as resolved.
Show resolved Hide resolved
stringval = "send"
}
messageOperation = stringval
stuartnelson3 marked this conversation as resolved.
Show resolved Hide resolved
isMessagingSpan = true
case conventions.AttributeMessagingSystem:
messageSystem = stringval
destinationService.Resource = stringval
destinationService.Name = stringval
isMessagingSpan = true

// rpc.*
//
Expand Down Expand Up @@ -650,6 +662,12 @@ func translateSpan(span pdata.Span, metadata model.Metadata, event *model.Span)
event.DB = &db
case isMessagingSpan:
event.Type = "messaging"
event.Subtype = messageSystem
event.Action = messageOperation

if destinationService.Resource != "" && message.QueueName != "" {
destinationService.Resource += "/" + message.QueueName
}
event.Message = &message
case isRPCSpan:
event.Type = "external"
Expand Down
41 changes: 40 additions & 1 deletion processor/otel/consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,42 @@ func TestRPCSpan(t *testing.T) {
}, span.DestinationService)
}

func TestMessagingTransaction(t *testing.T) {
tx := transformTransactionWithAttributes(t, map[string]pdata.AttributeValue{
"messaging.destination": pdata.NewAttributeValueString("myQueue"),
})
assert.Equal(t, "messaging", tx.Type)
assert.Empty(t, tx.Labels)
assert.Equal(t, &model.Message{
QueueName: "myQueue",
}, tx.Message)
}

func TestMessagingSpan(t *testing.T) {
span := transformSpanWithAttributes(t, map[string]pdata.AttributeValue{
"messaging.system": pdata.NewAttributeValueString("kafka"),
"messaging.operation": pdata.NewAttributeValueString(""),
stuartnelson3 marked this conversation as resolved.
Show resolved Hide resolved
"messaging.destination": pdata.NewAttributeValueString("myTopic"),
"net.peer.ip": pdata.NewAttributeValueString("10.20.30.40"),
"net.peer.port": pdata.NewAttributeValueInt(123),
}, func(s pdata.Span) {
s.SetKind(pdata.SpanKindPRODUCER)
})
assert.Equal(t, "messaging", span.Type)
assert.Equal(t, "kafka", span.Subtype)
assert.Equal(t, "send", span.Action)
assert.Empty(t, span.Labels)
assert.Equal(t, &model.Destination{
Address: "10.20.30.40",
Port: 123,
}, span.Destination)
assert.Equal(t, &model.DestinationService{
Type: "messaging",
Name: "kafka",
Resource: "kafka/myTopic",
}, span.DestinationService)
}

func TestArrayLabels(t *testing.T) {
stringArray := pdata.NewAttributeValueArray()
stringArray.ArrayVal().Append(pdata.NewAttributeValueString("string1"))
Expand Down Expand Up @@ -1066,12 +1102,15 @@ func transformTransactionWithAttributes(t *testing.T, attrs map[string]pdata.Att
return events.Transactions[0]
}

func transformSpanWithAttributes(t *testing.T, attrs map[string]pdata.AttributeValue) *model.Span {
func transformSpanWithAttributes(t *testing.T, attrs map[string]pdata.AttributeValue, configFns ...func(pdata.Span)) *model.Span {
traces, spans := newTracesSpans()
otelSpan := pdata.NewSpan()
otelSpan.SetTraceID(pdata.NewTraceID([16]byte{1}))
otelSpan.SetSpanID(pdata.NewSpanID([8]byte{2}))
otelSpan.SetParentSpanID(pdata.NewSpanID([8]byte{3}))
for _, fn := range configFns {
fn(otelSpan)
}
otelSpan.Attributes().InitFromMap(attrs)
spans.Spans().Append(otelSpan)
events := transformTraces(t, traces)
Expand Down