From 3def749edba2df55722e7deaba60e0d0521c3821 Mon Sep 17 00:00:00 2001 From: Greg Kalapos Date: Mon, 9 Dec 2024 19:25:56 +0100 Subject: [PATCH] Set both `transaction` and `span` on root exit root spans --- enrichments/trace/internal/elastic/span.go | 10 ++++-- .../trace/internal/elastic/span_test.go | 33 ++++++++++++++----- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/enrichments/trace/internal/elastic/span.go b/enrichments/trace/internal/elastic/span.go index 87966fb..6fc340f 100644 --- a/enrichments/trace/internal/elastic/span.go +++ b/enrichments/trace/internal/elastic/span.go @@ -277,8 +277,14 @@ func (s *spanEnrichmentContext) enrichSpan( if cfg.Span.InferredSpans.Enabled { s.setInferredSpans(span) } - if cfg.Span.ProcessorEvent.Enabled && !isExitRootSpan { - span.Attributes().PutStr(AttributeProcessorEvent, "span") + if cfg.Span.ProcessorEvent.Enabled { + if isExitRootSpan { + attrSlice := span.Attributes().PutEmptySlice(AttributeProcessorEvent) + attrSlice.AppendEmpty().SetStr("transaction") + attrSlice.AppendEmpty().SetStr("span") + } else { + span.Attributes().PutStr(AttributeProcessorEvent, "span") + } } if isExitRootSpan && cfg.Transaction.Type.Enabled { diff --git a/enrichments/trace/internal/elastic/span_test.go b/enrichments/trace/internal/elastic/span_test.go index 0bfa68b..cf63367 100644 --- a/enrichments/trace/internal/elastic/span_test.go +++ b/enrichments/trace/internal/elastic/span_test.go @@ -410,9 +410,14 @@ func TestRootSpanAsDependencyEnrich(t *testing.T) { }(), config: config.Enabled(), enrichedAttrs: map[string]any{ - AttributeTimestampUs: int64(0), - AttributeTransactionName: "rootClientSpan", - AttributeProcessorEvent: "transaction", + AttributeTimestampUs: int64(0), + AttributeTransactionName: "rootClientSpan", + AttributeProcessorEvent: func() pcommon.Slice { + p := pcommon.NewSlice() + p.AppendEmpty().SetStr("transaction") + p.AppendEmpty().SetStr("span") + return p + }().AsRaw(), AttributeSpanType: "external", AttributeSpanSubtype: "http", AttributeSpanDestinationServiceResource: "localhost:8080", @@ -448,9 +453,14 @@ func TestRootSpanAsDependencyEnrich(t *testing.T) { }(), config: config.Enabled(), enrichedAttrs: map[string]any{ - AttributeTimestampUs: int64(0), - AttributeTransactionName: "rootClientSpan", - AttributeProcessorEvent: "transaction", + AttributeTimestampUs: int64(0), + AttributeTransactionName: "rootClientSpan", + AttributeProcessorEvent: func() pcommon.Slice { + p := pcommon.NewSlice() + p.AppendEmpty().SetStr("transaction") + p.AppendEmpty().SetStr("span") + return p + }().AsRaw(), AttributeSpanType: "db", AttributeSpanSubtype: "mssql", AttributeSpanDestinationServiceResource: "mssql", @@ -488,9 +498,14 @@ func TestRootSpanAsDependencyEnrich(t *testing.T) { }(), config: config.Enabled(), enrichedAttrs: map[string]any{ - AttributeTimestampUs: int64(0), - AttributeTransactionName: "rootClientSpan", - AttributeProcessorEvent: "transaction", + AttributeTimestampUs: int64(0), + AttributeTransactionName: "rootClientSpan", + AttributeProcessorEvent: func() pcommon.Slice { + p := pcommon.NewSlice() + p.AppendEmpty().SetStr("transaction") + p.AppendEmpty().SetStr("span") + return p + }().AsRaw(), AttributeSpanType: "messaging", AttributeSpanSubtype: "rabbitmq", AttributeSpanDestinationServiceResource: "rabbitmq/T",