Skip to content

Commit 426c75b

Browse files
authored
Fix handling of non root span that represent a dependency (#180)
1 parent cd0e3ef commit 426c75b

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

enrichments/trace/internal/elastic/span.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func (s *spanEnrichmentContext) enrich(span ptrace.Span, cfg config.Config) {
220220
// In OTel, a local root span can represent an outgoing call or a producer span.
221221
// In such cases, the span is still mapped into a transaction, but enriched
222222
// with additional attributes that are specific to the outgoing call or producer span.
223-
isExitRootSpan := s.isTransaction && span.Kind() == ptrace.SpanKindClient || span.Kind() == ptrace.SpanKindProducer
223+
isExitRootSpan := s.isTransaction && (span.Kind() == ptrace.SpanKindClient || span.Kind() == ptrace.SpanKindProducer)
224224

225225
if s.isTransaction {
226226
s.enrichTransaction(span, cfg.Transaction)

enrichments/trace/internal/elastic/span_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,41 @@ func TestRootSpanAsDependencyEnrich(t *testing.T) {
570570
elasticattr.SpanRepresentativeCount: float64(1),
571571
},
572572
},
573+
// This one is a non root span representing a dependency. The test asserts that such spans are not
574+
// accidentally mapped into a transaction.
575+
{
576+
name: "producer_messaging_non_root_span",
577+
input: func() ptrace.Span {
578+
span := ptrace.NewSpan()
579+
span.SetName("rootClientSpan")
580+
span.SetSpanID([8]byte{1})
581+
span.SetKind(ptrace.SpanKindProducer)
582+
// Adding parent id to make sure this is not a root span.
583+
span.SetParentSpanID([8]byte{1, 2, 3, 4, 5, 6, 7, 8})
584+
span.Attributes().PutStr(semconv25.AttributeServerAddress, "myServer")
585+
span.Attributes().PutStr(semconv25.AttributeServerPort, "1234")
586+
span.Attributes().PutStr(semconv25.AttributeMessagingSystem, "rabbitmq")
587+
span.Attributes().PutStr(semconv25.AttributeMessagingDestinationName, "T")
588+
span.Attributes().PutStr(semconv25.AttributeMessagingOperation, "publish")
589+
span.Attributes().PutStr(semconv25.AttributeMessagingClientID, "a")
590+
return span
591+
}(),
592+
config: config.Enabled(),
593+
enrichedAttrs: map[string]any{
594+
elasticattr.TimestampUs: int64(0),
595+
elasticattr.ProcessorEvent: "span",
596+
elasticattr.SpanType: "messaging",
597+
elasticattr.SpanSubtype: "rabbitmq",
598+
elasticattr.SpanDestinationServiceResource: "rabbitmq/T",
599+
elasticattr.SpanName: "rootClientSpan",
600+
elasticattr.EventOutcome: "success",
601+
elasticattr.SuccessCount: int64(1),
602+
elasticattr.ServiceTargetName: "T",
603+
elasticattr.ServiceTargetType: "rabbitmq",
604+
elasticattr.SpanDurationUs: int64(0),
605+
elasticattr.SpanRepresentativeCount: float64(1),
606+
},
607+
},
573608
} {
574609
t.Run(tc.name, func(t *testing.T) {
575610
expectedSpan := ptrace.NewSpan()

0 commit comments

Comments
 (0)