Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion enrichments/trace/internal/elastic/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (s *spanEnrichmentContext) enrich(span ptrace.Span, cfg config.Config) {
// In OTel, a local root span can represent an outgoing call or a producer span.
// In such cases, the span is still mapped into a transaction, but enriched
// with additional attributes that are specific to the outgoing call or producer span.
isExitRootSpan := s.isTransaction && span.Kind() == ptrace.SpanKindClient || span.Kind() == ptrace.SpanKindProducer
isExitRootSpan := s.isTransaction && (span.Kind() == ptrace.SpanKindClient || span.Kind() == ptrace.SpanKindProducer)
Copy link
Contributor

@lahsivjar lahsivjar Apr 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for finding and fixing this.


if s.isTransaction {
s.enrichTransaction(span, cfg.Transaction)
Expand Down
35 changes: 35 additions & 0 deletions enrichments/trace/internal/elastic/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,41 @@ func TestRootSpanAsDependencyEnrich(t *testing.T) {
elasticattr.SpanRepresentativeCount: float64(1),
},
},
// This one is a non root span representing a dependency. The test asserts that such spans are not
// accidentally mapped into a transaction.
{
name: "producer_messaging_non_root_span",
input: func() ptrace.Span {
span := ptrace.NewSpan()
span.SetName("rootClientSpan")
span.SetSpanID([8]byte{1})
span.SetKind(ptrace.SpanKindProducer)
// Adding parent id to make sure this is not a root span.
span.SetParentSpanID([8]byte{1, 2, 3, 4, 5, 6, 7, 8})
span.Attributes().PutStr(semconv25.AttributeServerAddress, "myServer")
span.Attributes().PutStr(semconv25.AttributeServerPort, "1234")
span.Attributes().PutStr(semconv25.AttributeMessagingSystem, "rabbitmq")
span.Attributes().PutStr(semconv25.AttributeMessagingDestinationName, "T")
span.Attributes().PutStr(semconv25.AttributeMessagingOperation, "publish")
span.Attributes().PutStr(semconv25.AttributeMessagingClientID, "a")
return span
}(),
config: config.Enabled(),
enrichedAttrs: map[string]any{
elasticattr.TimestampUs: int64(0),
elasticattr.ProcessorEvent: "span",
elasticattr.SpanType: "messaging",
elasticattr.SpanSubtype: "rabbitmq",
elasticattr.SpanDestinationServiceResource: "rabbitmq/T",
elasticattr.SpanName: "rootClientSpan",
elasticattr.EventOutcome: "success",
elasticattr.SuccessCount: int64(1),
elasticattr.ServiceTargetName: "T",
elasticattr.ServiceTargetType: "rabbitmq",
elasticattr.SpanDurationUs: int64(0),
elasticattr.SpanRepresentativeCount: float64(1),
},
},
} {
t.Run(tc.name, func(t *testing.T) {
expectedSpan := ptrace.NewSpan()
Expand Down