From 491a09f3dd9c87898c2ffb84fe1f0bc969ee16ca Mon Sep 17 00:00:00 2001 From: Vishal Raj Date: Fri, 9 Aug 2024 15:16:34 +0100 Subject: [PATCH 1/4] Add transaction.id enrichment --- enrichments/trace/config/config.go | 2 ++ .../trace/internal/elastic/attributes.go | 1 + enrichments/trace/internal/elastic/span.go | 3 +++ enrichments/trace/internal/elastic/span_test.go | 17 +++++++++++++++++ 4 files changed, 23 insertions(+) diff --git a/enrichments/trace/config/config.go b/enrichments/trace/config/config.go index 6e7e22c..248acb1 100644 --- a/enrichments/trace/config/config.go +++ b/enrichments/trace/config/config.go @@ -40,6 +40,7 @@ type ScopeConfig struct { // ElasticTransactionConfig configures the enrichment attributes for the // spans which are identified as elastic transaction. type ElasticTransactionConfig struct { + ID AttributeConfig `mapstructure:"id"` Root AttributeConfig `mapstructure:"root"` Name AttributeConfig `mapstructure:"name"` Type AttributeConfig `mapstructure:"type"` @@ -73,6 +74,7 @@ func Enabled() Config { ServiceFrameworkVersion: AttributeConfig{Enabled: true}, }, Transaction: ElasticTransactionConfig{ + ID: AttributeConfig{Enabled: true}, Root: AttributeConfig{Enabled: true}, Name: AttributeConfig{Enabled: true}, Type: AttributeConfig{Enabled: true}, diff --git a/enrichments/trace/internal/elastic/attributes.go b/enrichments/trace/internal/elastic/attributes.go index 890df26..ef7bd7b 100644 --- a/enrichments/trace/internal/elastic/attributes.go +++ b/enrichments/trace/internal/elastic/attributes.go @@ -27,6 +27,7 @@ const ( AttributeServiceFrameworkVersion = "service.framework.version" // span attributes + AttributeTransactionID = "transaction.id" AttributeTransactionRoot = "transaction.root" AttributeTransactionName = "transaction.name" AttributeTransactionType = "transaction.type" diff --git a/enrichments/trace/internal/elastic/span.go b/enrichments/trace/internal/elastic/span.go index efdaea8..bcd9eb4 100644 --- a/enrichments/trace/internal/elastic/span.go +++ b/enrichments/trace/internal/elastic/span.go @@ -161,6 +161,9 @@ func (s *spanEnrichmentContext) enrichTransaction( span ptrace.Span, cfg config.ElasticTransactionConfig, ) { + if cfg.ID.Enabled { + span.Attributes().PutStr(AttributeTransactionID, span.SpanID().String()) + } if cfg.Root.Enabled { span.Attributes().PutBool(AttributeTransactionRoot, isTraceRoot(span)) } diff --git a/enrichments/trace/internal/elastic/span_test.go b/enrichments/trace/internal/elastic/span_test.go index 27fecd9..a0baabc 100644 --- a/enrichments/trace/internal/elastic/span_test.go +++ b/enrichments/trace/internal/elastic/span_test.go @@ -44,6 +44,7 @@ func TestElasticTransactionEnrich(t *testing.T) { config: config.Enabled().Transaction, enrichedAttrs: map[string]any{ AttributeTransactionRoot: true, + AttributeTransactionID: "", AttributeTransactionName: "", AttributeEventOutcome: "success", AttributeTransactionResult: "Success", @@ -60,12 +61,14 @@ func TestElasticTransactionEnrich(t *testing.T) { input: func() ptrace.Span { span := ptrace.NewSpan() span.SetName("testtxn") + span.SetSpanID([8]byte{1}) span.Attributes().PutInt(semconv.AttributeHTTPStatusCode, http.StatusOK) return span }(), config: config.Enabled().Transaction, enrichedAttrs: map[string]any{ AttributeTransactionRoot: true, + AttributeTransactionID: "0100000000000000", AttributeTransactionName: "testtxn", AttributeEventOutcome: "success", AttributeTransactionResult: "HTTP 2xx", @@ -77,6 +80,7 @@ func TestElasticTransactionEnrich(t *testing.T) { input: func() ptrace.Span { span := ptrace.NewSpan() span.SetName("testtxn") + span.SetSpanID([8]byte{1}) // attributes should be preferred over span status for txn result span.Status().SetCode(ptrace.StatusCodeOk) span.Attributes().PutInt( @@ -88,6 +92,7 @@ func TestElasticTransactionEnrich(t *testing.T) { config: config.Enabled().Transaction, enrichedAttrs: map[string]any{ AttributeTransactionRoot: true, + AttributeTransactionID: "0100000000000000", AttributeTransactionName: "testtxn", AttributeEventOutcome: "success", AttributeTransactionResult: "HTTP 1xx", @@ -99,6 +104,7 @@ func TestElasticTransactionEnrich(t *testing.T) { input: func() ptrace.Span { span := ptrace.NewSpan() span.SetName("testtxn") + span.SetSpanID([8]byte{1}) // span status code should take precedence over http status attributes // for setting event.outcome span.Status().SetCode(ptrace.StatusCodeOk) @@ -109,6 +115,7 @@ func TestElasticTransactionEnrich(t *testing.T) { config: config.Enabled().Transaction, enrichedAttrs: map[string]any{ AttributeTransactionRoot: true, + AttributeTransactionID: "0100000000000000", AttributeTransactionName: "testtxn", AttributeEventOutcome: "success", AttributeTransactionResult: "HTTP 5xx", @@ -120,6 +127,7 @@ func TestElasticTransactionEnrich(t *testing.T) { input: func() ptrace.Span { span := ptrace.NewSpan() span.SetName("testtxn") + span.SetSpanID([8]byte{1}) // attributes should be preferred over span status for txn result span.Status().SetCode(ptrace.StatusCodeOk) span.Attributes().PutInt( @@ -131,6 +139,7 @@ func TestElasticTransactionEnrich(t *testing.T) { config: config.Enabled().Transaction, enrichedAttrs: map[string]any{ AttributeTransactionRoot: true, + AttributeTransactionID: "0100000000000000", AttributeTransactionName: "testtxn", AttributeEventOutcome: "success", AttributeTransactionResult: "OK", @@ -142,6 +151,7 @@ func TestElasticTransactionEnrich(t *testing.T) { input: func() ptrace.Span { span := ptrace.NewSpan() span.SetName("testtxn") + span.SetSpanID([8]byte{1}) // attributes should be preferred over span status for txn result span.Status().SetCode(ptrace.StatusCodeOk) span.Attributes().PutInt( @@ -153,6 +163,7 @@ func TestElasticTransactionEnrich(t *testing.T) { config: config.Enabled().Transaction, enrichedAttrs: map[string]any{ AttributeTransactionRoot: true, + AttributeTransactionID: "0100000000000000", AttributeTransactionName: "testtxn", AttributeEventOutcome: "success", AttributeTransactionResult: "Internal", @@ -164,12 +175,14 @@ func TestElasticTransactionEnrich(t *testing.T) { input: func() ptrace.Span { span := ptrace.NewSpan() span.SetName("testtxn") + span.SetSpanID([8]byte{1}) span.Status().SetCode(ptrace.StatusCodeOk) return span }(), config: config.Enabled().Transaction, enrichedAttrs: map[string]any{ AttributeTransactionRoot: true, + AttributeTransactionID: "0100000000000000", AttributeTransactionName: "testtxn", AttributeEventOutcome: "success", AttributeTransactionResult: "Success", @@ -181,12 +194,14 @@ func TestElasticTransactionEnrich(t *testing.T) { input: func() ptrace.Span { span := ptrace.NewSpan() span.SetName("testtxn") + span.SetSpanID([8]byte{1}) span.Status().SetCode(ptrace.StatusCodeError) return span }(), config: config.Enabled().Transaction, enrichedAttrs: map[string]any{ AttributeTransactionRoot: true, + AttributeTransactionID: "0100000000000000", AttributeTransactionName: "testtxn", AttributeEventOutcome: "failure", AttributeTransactionResult: "Error", @@ -198,12 +213,14 @@ func TestElasticTransactionEnrich(t *testing.T) { input: func() ptrace.Span { span := ptrace.NewSpan() span.SetName("testtxn") + span.SetSpanID([8]byte{1}) span.Attributes().PutStr(semconv.AttributeMessagingSystem, "kafka") return span }(), config: config.Enabled().Transaction, enrichedAttrs: map[string]any{ AttributeTransactionRoot: true, + AttributeTransactionID: "0100000000000000", AttributeTransactionName: "testtxn", AttributeEventOutcome: "success", AttributeTransactionResult: "Success", From a857c4ed3ff1b49b5ebdce129fb4fe1c5b1e199e Mon Sep 17 00:00:00 2001 From: Vishal Raj Date: Fri, 9 Aug 2024 16:33:15 +0100 Subject: [PATCH 2/4] Add processor.event enrichment --- enrichments/trace/config/config.go | 28 +++++++++++-------- .../trace/internal/elastic/attributes.go | 1 + enrichments/trace/internal/elastic/span.go | 6 ++++ .../trace/internal/elastic/span_test.go | 26 +++++++++++++++-- 4 files changed, 47 insertions(+), 14 deletions(-) diff --git a/enrichments/trace/config/config.go b/enrichments/trace/config/config.go index 248acb1..6b3064e 100644 --- a/enrichments/trace/config/config.go +++ b/enrichments/trace/config/config.go @@ -40,18 +40,20 @@ type ScopeConfig struct { // ElasticTransactionConfig configures the enrichment attributes for the // spans which are identified as elastic transaction. type ElasticTransactionConfig struct { - ID AttributeConfig `mapstructure:"id"` - Root AttributeConfig `mapstructure:"root"` - Name AttributeConfig `mapstructure:"name"` - Type AttributeConfig `mapstructure:"type"` - Result AttributeConfig `mapstructure:"result"` - EventOutcome AttributeConfig `mapstructure:"event_outcome"` + ID AttributeConfig `mapstructure:"id"` + Root AttributeConfig `mapstructure:"root"` + Name AttributeConfig `mapstructure:"name"` + ProcessorEvent AttributeConfig `mapstructure:"processor_event"` + Type AttributeConfig `mapstructure:"type"` + Result AttributeConfig `mapstructure:"result"` + EventOutcome AttributeConfig `mapstructure:"event_outcome"` } // ElasticSpanConfig configures the enrichment attributes for the spans // which are NOT identified as elastic transaction. type ElasticSpanConfig struct { Name AttributeConfig `mapstructure:"name"` + ProcessorEvent AttributeConfig `mapstructure:"processor_event"` EventOutcome AttributeConfig `mapstructure:"event_outcome"` ServiceTarget AttributeConfig `mapstructure:"service_target"` DestinationService AttributeConfig `mapstructure:"destination_service"` @@ -74,15 +76,17 @@ func Enabled() Config { ServiceFrameworkVersion: AttributeConfig{Enabled: true}, }, Transaction: ElasticTransactionConfig{ - ID: AttributeConfig{Enabled: true}, - Root: AttributeConfig{Enabled: true}, - Name: AttributeConfig{Enabled: true}, - Type: AttributeConfig{Enabled: true}, - Result: AttributeConfig{Enabled: true}, - EventOutcome: AttributeConfig{Enabled: true}, + ID: AttributeConfig{Enabled: true}, + Root: AttributeConfig{Enabled: true}, + Name: AttributeConfig{Enabled: true}, + ProcessorEvent: AttributeConfig{Enabled: true}, + Type: AttributeConfig{Enabled: true}, + Result: AttributeConfig{Enabled: true}, + EventOutcome: AttributeConfig{Enabled: true}, }, Span: ElasticSpanConfig{ Name: AttributeConfig{Enabled: true}, + ProcessorEvent: AttributeConfig{Enabled: true}, EventOutcome: AttributeConfig{Enabled: true}, ServiceTarget: AttributeConfig{Enabled: true}, DestinationService: AttributeConfig{Enabled: true}, diff --git a/enrichments/trace/internal/elastic/attributes.go b/enrichments/trace/internal/elastic/attributes.go index ef7bd7b..4bc6dd0 100644 --- a/enrichments/trace/internal/elastic/attributes.go +++ b/enrichments/trace/internal/elastic/attributes.go @@ -30,6 +30,7 @@ const ( AttributeTransactionID = "transaction.id" AttributeTransactionRoot = "transaction.root" AttributeTransactionName = "transaction.name" + AttributeProcessorEvent = "processor.event" AttributeTransactionType = "transaction.type" AttributeTransactionResult = "transaction.result" AttributeSpanName = "span.name" diff --git a/enrichments/trace/internal/elastic/span.go b/enrichments/trace/internal/elastic/span.go index bcd9eb4..f161a24 100644 --- a/enrichments/trace/internal/elastic/span.go +++ b/enrichments/trace/internal/elastic/span.go @@ -170,6 +170,9 @@ func (s *spanEnrichmentContext) enrichTransaction( if cfg.Name.Enabled { span.Attributes().PutStr(AttributeTransactionName, span.Name()) } + if cfg.ProcessorEvent.Enabled { + span.Attributes().PutStr(AttributeProcessorEvent, "transaction") + } if cfg.Type.Enabled { s.setTxnType(span) } @@ -188,6 +191,9 @@ func (s *spanEnrichmentContext) enrichSpan( if cfg.Name.Enabled { span.Attributes().PutStr(AttributeSpanName, span.Name()) } + if cfg.ProcessorEvent.Enabled { + span.Attributes().PutStr(AttributeProcessorEvent, "span") + } if cfg.EventOutcome.Enabled { s.setEventOutcome(span) } diff --git a/enrichments/trace/internal/elastic/span_test.go b/enrichments/trace/internal/elastic/span_test.go index a0baabc..6362e38 100644 --- a/enrichments/trace/internal/elastic/span_test.go +++ b/enrichments/trace/internal/elastic/span_test.go @@ -46,6 +46,7 @@ func TestElasticTransactionEnrich(t *testing.T) { AttributeTransactionRoot: true, AttributeTransactionID: "", AttributeTransactionName: "", + AttributeProcessorEvent: "transaction", AttributeEventOutcome: "success", AttributeTransactionResult: "Success", AttributeTransactionType: "unknown", @@ -70,6 +71,7 @@ func TestElasticTransactionEnrich(t *testing.T) { AttributeTransactionRoot: true, AttributeTransactionID: "0100000000000000", AttributeTransactionName: "testtxn", + AttributeProcessorEvent: "transaction", AttributeEventOutcome: "success", AttributeTransactionResult: "HTTP 2xx", AttributeTransactionType: "request", @@ -94,6 +96,7 @@ func TestElasticTransactionEnrich(t *testing.T) { AttributeTransactionRoot: true, AttributeTransactionID: "0100000000000000", AttributeTransactionName: "testtxn", + AttributeProcessorEvent: "transaction", AttributeEventOutcome: "success", AttributeTransactionResult: "HTTP 1xx", AttributeTransactionType: "request", @@ -117,6 +120,7 @@ func TestElasticTransactionEnrich(t *testing.T) { AttributeTransactionRoot: true, AttributeTransactionID: "0100000000000000", AttributeTransactionName: "testtxn", + AttributeProcessorEvent: "transaction", AttributeEventOutcome: "success", AttributeTransactionResult: "HTTP 5xx", AttributeTransactionType: "request", @@ -141,6 +145,7 @@ func TestElasticTransactionEnrich(t *testing.T) { AttributeTransactionRoot: true, AttributeTransactionID: "0100000000000000", AttributeTransactionName: "testtxn", + AttributeProcessorEvent: "transaction", AttributeEventOutcome: "success", AttributeTransactionResult: "OK", AttributeTransactionType: "request", @@ -165,6 +170,7 @@ func TestElasticTransactionEnrich(t *testing.T) { AttributeTransactionRoot: true, AttributeTransactionID: "0100000000000000", AttributeTransactionName: "testtxn", + AttributeProcessorEvent: "transaction", AttributeEventOutcome: "success", AttributeTransactionResult: "Internal", AttributeTransactionType: "request", @@ -184,6 +190,7 @@ func TestElasticTransactionEnrich(t *testing.T) { AttributeTransactionRoot: true, AttributeTransactionID: "0100000000000000", AttributeTransactionName: "testtxn", + AttributeProcessorEvent: "transaction", AttributeEventOutcome: "success", AttributeTransactionResult: "Success", AttributeTransactionType: "unknown", @@ -203,6 +210,7 @@ func TestElasticTransactionEnrich(t *testing.T) { AttributeTransactionRoot: true, AttributeTransactionID: "0100000000000000", AttributeTransactionName: "testtxn", + AttributeProcessorEvent: "transaction", AttributeEventOutcome: "failure", AttributeTransactionResult: "Error", AttributeTransactionType: "unknown", @@ -222,6 +230,7 @@ func TestElasticTransactionEnrich(t *testing.T) { AttributeTransactionRoot: true, AttributeTransactionID: "0100000000000000", AttributeTransactionName: "testtxn", + AttributeProcessorEvent: "transaction", AttributeEventOutcome: "success", AttributeTransactionResult: "Success", AttributeTransactionType: "messaging", @@ -263,8 +272,9 @@ func TestElasticSpanEnrich(t *testing.T) { input: getElasticSpan(), config: config.Enabled().Span, enrichedAttrs: map[string]any{ - AttributeSpanName: "", - AttributeEventOutcome: "success", + AttributeSpanName: "", + AttributeProcessorEvent: "span", + AttributeEventOutcome: "success", }, }, { @@ -283,6 +293,7 @@ func TestElasticSpanEnrich(t *testing.T) { config: config.Enabled().Span, enrichedAttrs: map[string]any{ AttributeSpanName: "testspan", + AttributeProcessorEvent: "span", AttributeEventOutcome: "success", AttributeServiceTargetName: "testsvc", AttributeServiceTargetType: "", @@ -304,6 +315,7 @@ func TestElasticSpanEnrich(t *testing.T) { config: config.Enabled().Span, enrichedAttrs: map[string]any{ AttributeSpanName: "testspan", + AttributeProcessorEvent: "span", AttributeEventOutcome: "success", AttributeServiceTargetType: "http", AttributeServiceTargetName: "testsvc", @@ -331,6 +343,7 @@ func TestElasticSpanEnrich(t *testing.T) { config: config.Enabled().Span, enrichedAttrs: map[string]any{ AttributeSpanName: "testspan", + AttributeProcessorEvent: "span", AttributeEventOutcome: "success", AttributeServiceTargetType: "http", AttributeServiceTargetName: "www.foo.bar:443", @@ -356,6 +369,7 @@ func TestElasticSpanEnrich(t *testing.T) { config: config.Enabled().Span, enrichedAttrs: map[string]any{ AttributeSpanName: "testspan", + AttributeProcessorEvent: "span", AttributeEventOutcome: "success", AttributeServiceTargetType: "http", AttributeServiceTargetName: "www.foo.bar:443", @@ -377,6 +391,7 @@ func TestElasticSpanEnrich(t *testing.T) { config: config.Enabled().Span, enrichedAttrs: map[string]any{ AttributeSpanName: "testspan", + AttributeProcessorEvent: "span", AttributeEventOutcome: "success", AttributeServiceTargetType: "grpc", AttributeServiceTargetName: "testsvc", @@ -395,6 +410,7 @@ func TestElasticSpanEnrich(t *testing.T) { config: config.Enabled().Span, enrichedAttrs: map[string]any{ AttributeSpanName: "testspan", + AttributeProcessorEvent: "span", AttributeEventOutcome: "success", AttributeServiceTargetType: "xmlrpc", AttributeServiceTargetName: "testsvc", @@ -415,6 +431,7 @@ func TestElasticSpanEnrich(t *testing.T) { config: config.Enabled().Span, enrichedAttrs: map[string]any{ AttributeSpanName: "testspan", + AttributeProcessorEvent: "span", AttributeEventOutcome: "success", AttributeServiceTargetType: "external", AttributeServiceTargetName: "service.Test", @@ -433,6 +450,7 @@ func TestElasticSpanEnrich(t *testing.T) { config: config.Enabled().Span, enrichedAttrs: map[string]any{ AttributeSpanName: "testspan", + AttributeProcessorEvent: "span", AttributeEventOutcome: "success", AttributeServiceTargetType: "kafka", AttributeServiceTargetName: "testsvc", @@ -451,6 +469,7 @@ func TestElasticSpanEnrich(t *testing.T) { config: config.Enabled().Span, enrichedAttrs: map[string]any{ AttributeSpanName: "testspan", + AttributeProcessorEvent: "span", AttributeEventOutcome: "success", AttributeServiceTargetType: "messaging", AttributeServiceTargetName: "t1", @@ -470,6 +489,7 @@ func TestElasticSpanEnrich(t *testing.T) { config: config.Enabled().Span, enrichedAttrs: map[string]any{ AttributeSpanName: "testspan", + AttributeProcessorEvent: "span", AttributeEventOutcome: "success", AttributeServiceTargetType: "messaging", AttributeServiceTargetName: "testsvc", @@ -495,6 +515,7 @@ func TestElasticSpanEnrich(t *testing.T) { config: config.Enabled().Span, enrichedAttrs: map[string]any{ AttributeSpanName: "testspan", + AttributeProcessorEvent: "span", AttributeEventOutcome: "success", AttributeServiceTargetType: "elasticsearch", AttributeServiceTargetName: "testsvc", @@ -525,6 +546,7 @@ func TestElasticSpanEnrich(t *testing.T) { config: config.Enabled().Span, enrichedAttrs: map[string]any{ AttributeSpanName: "testspan", + AttributeProcessorEvent: "span", AttributeEventOutcome: "success", AttributeServiceTargetType: "cassandra", AttributeServiceTargetName: "testsvc", From 5b06d57719bb36318a2152c70d1d1fc6130e4972 Mon Sep 17 00:00:00 2001 From: Vishal Raj Date: Fri, 9 Aug 2024 17:18:29 +0100 Subject: [PATCH 3/4] Add event.success_count enrichment --- .../trace/internal/elastic/attributes.go | 1 + enrichments/trace/internal/elastic/span.go | 4 ++++ .../trace/internal/elastic/span_test.go | 22 +++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/enrichments/trace/internal/elastic/attributes.go b/enrichments/trace/internal/elastic/attributes.go index 4bc6dd0..a3a872c 100644 --- a/enrichments/trace/internal/elastic/attributes.go +++ b/enrichments/trace/internal/elastic/attributes.go @@ -35,6 +35,7 @@ const ( AttributeTransactionResult = "transaction.result" AttributeSpanName = "span.name" AttributeEventOutcome = "event.outcome" + AttributeSuccessCount = "event.success_count" AttributeServiceTargetType = "service.target.type" AttributeServiceTargetName = "service.target.name" AttributeSpanDestinationServiceResource = "span.destination.service.resource" diff --git a/enrichments/trace/internal/elastic/span.go b/enrichments/trace/internal/elastic/span.go index f161a24..2d973a8 100644 --- a/enrichments/trace/internal/elastic/span.go +++ b/enrichments/trace/internal/elastic/span.go @@ -254,17 +254,21 @@ func (s *spanEnrichmentContext) setTxnResult(span ptrace.Span) { func (s *spanEnrichmentContext) setEventOutcome(span ptrace.Span) { // default to success outcome outcome := "success" + successCount := 1 switch { case s.spanStatusCode == ptrace.StatusCodeError: outcome = "failure" + successCount = 0 case s.spanStatusCode == ptrace.StatusCodeOk: // keep the default success outcome case s.httpStatusCode >= http.StatusInternalServerError: // TODO (lahsivjar): Handle GRPC status code? - not handled in apm-data // TODO (lahsivjar): Move to HTTPResponseStatusCode? Backward compatibility? outcome = "failure" + successCount = 0 } span.Attributes().PutStr(AttributeEventOutcome, outcome) + span.Attributes().PutInt(AttributeSuccessCount, int64(successCount)) } func (s *spanEnrichmentContext) setServiceTarget(span ptrace.Span) { diff --git a/enrichments/trace/internal/elastic/span_test.go b/enrichments/trace/internal/elastic/span_test.go index 6362e38..d1199d2 100644 --- a/enrichments/trace/internal/elastic/span_test.go +++ b/enrichments/trace/internal/elastic/span_test.go @@ -48,6 +48,7 @@ func TestElasticTransactionEnrich(t *testing.T) { AttributeTransactionName: "", AttributeProcessorEvent: "transaction", AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), AttributeTransactionResult: "Success", AttributeTransactionType: "unknown", }, @@ -73,6 +74,7 @@ func TestElasticTransactionEnrich(t *testing.T) { AttributeTransactionName: "testtxn", AttributeProcessorEvent: "transaction", AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), AttributeTransactionResult: "HTTP 2xx", AttributeTransactionType: "request", }, @@ -98,6 +100,7 @@ func TestElasticTransactionEnrich(t *testing.T) { AttributeTransactionName: "testtxn", AttributeProcessorEvent: "transaction", AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), AttributeTransactionResult: "HTTP 1xx", AttributeTransactionType: "request", }, @@ -122,6 +125,7 @@ func TestElasticTransactionEnrich(t *testing.T) { AttributeTransactionName: "testtxn", AttributeProcessorEvent: "transaction", AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), AttributeTransactionResult: "HTTP 5xx", AttributeTransactionType: "request", }, @@ -147,6 +151,7 @@ func TestElasticTransactionEnrich(t *testing.T) { AttributeTransactionName: "testtxn", AttributeProcessorEvent: "transaction", AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), AttributeTransactionResult: "OK", AttributeTransactionType: "request", }, @@ -172,6 +177,7 @@ func TestElasticTransactionEnrich(t *testing.T) { AttributeTransactionName: "testtxn", AttributeProcessorEvent: "transaction", AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), AttributeTransactionResult: "Internal", AttributeTransactionType: "request", }, @@ -192,6 +198,7 @@ func TestElasticTransactionEnrich(t *testing.T) { AttributeTransactionName: "testtxn", AttributeProcessorEvent: "transaction", AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), AttributeTransactionResult: "Success", AttributeTransactionType: "unknown", }, @@ -212,6 +219,7 @@ func TestElasticTransactionEnrich(t *testing.T) { AttributeTransactionName: "testtxn", AttributeProcessorEvent: "transaction", AttributeEventOutcome: "failure", + AttributeSuccessCount: int64(0), AttributeTransactionResult: "Error", AttributeTransactionType: "unknown", }, @@ -232,6 +240,7 @@ func TestElasticTransactionEnrich(t *testing.T) { AttributeTransactionName: "testtxn", AttributeProcessorEvent: "transaction", AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), AttributeTransactionResult: "Success", AttributeTransactionType: "messaging", }, @@ -275,6 +284,7 @@ func TestElasticSpanEnrich(t *testing.T) { AttributeSpanName: "", AttributeProcessorEvent: "span", AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), }, }, { @@ -295,6 +305,7 @@ func TestElasticSpanEnrich(t *testing.T) { AttributeSpanName: "testspan", AttributeProcessorEvent: "span", AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), AttributeServiceTargetName: "testsvc", AttributeServiceTargetType: "", AttributeSpanDestinationServiceResource: "testsvc", @@ -317,6 +328,7 @@ func TestElasticSpanEnrich(t *testing.T) { AttributeSpanName: "testspan", AttributeProcessorEvent: "span", AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), AttributeServiceTargetType: "http", AttributeServiceTargetName: "testsvc", AttributeSpanDestinationServiceResource: "testsvc", @@ -345,6 +357,7 @@ func TestElasticSpanEnrich(t *testing.T) { AttributeSpanName: "testspan", AttributeProcessorEvent: "span", AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), AttributeServiceTargetType: "http", AttributeServiceTargetName: "www.foo.bar:443", AttributeSpanDestinationServiceResource: "testsvc", @@ -371,6 +384,7 @@ func TestElasticSpanEnrich(t *testing.T) { AttributeSpanName: "testspan", AttributeProcessorEvent: "span", AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), AttributeServiceTargetType: "http", AttributeServiceTargetName: "www.foo.bar:443", AttributeSpanDestinationServiceResource: "testsvc", @@ -393,6 +407,7 @@ func TestElasticSpanEnrich(t *testing.T) { AttributeSpanName: "testspan", AttributeProcessorEvent: "span", AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), AttributeServiceTargetType: "grpc", AttributeServiceTargetName: "testsvc", AttributeSpanDestinationServiceResource: "testsvc", @@ -412,6 +427,7 @@ func TestElasticSpanEnrich(t *testing.T) { AttributeSpanName: "testspan", AttributeProcessorEvent: "span", AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), AttributeServiceTargetType: "xmlrpc", AttributeServiceTargetName: "testsvc", AttributeSpanDestinationServiceResource: "testsvc", @@ -433,6 +449,7 @@ func TestElasticSpanEnrich(t *testing.T) { AttributeSpanName: "testspan", AttributeProcessorEvent: "span", AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), AttributeServiceTargetType: "external", AttributeServiceTargetName: "service.Test", AttributeSpanDestinationServiceResource: "testsvc", @@ -452,6 +469,7 @@ func TestElasticSpanEnrich(t *testing.T) { AttributeSpanName: "testspan", AttributeProcessorEvent: "span", AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), AttributeServiceTargetType: "kafka", AttributeServiceTargetName: "testsvc", AttributeSpanDestinationServiceResource: "testsvc", @@ -471,6 +489,7 @@ func TestElasticSpanEnrich(t *testing.T) { AttributeSpanName: "testspan", AttributeProcessorEvent: "span", AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), AttributeServiceTargetType: "messaging", AttributeServiceTargetName: "t1", AttributeSpanDestinationServiceResource: "testsvc/t1", @@ -491,6 +510,7 @@ func TestElasticSpanEnrich(t *testing.T) { AttributeSpanName: "testspan", AttributeProcessorEvent: "span", AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), AttributeServiceTargetType: "messaging", AttributeServiceTargetName: "testsvc", AttributeSpanDestinationServiceResource: "testsvc/t1", @@ -517,6 +537,7 @@ func TestElasticSpanEnrich(t *testing.T) { AttributeSpanName: "testspan", AttributeProcessorEvent: "span", AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), AttributeServiceTargetType: "elasticsearch", AttributeServiceTargetName: "testsvc", AttributeSpanDestinationServiceResource: "testsvc", @@ -548,6 +569,7 @@ func TestElasticSpanEnrich(t *testing.T) { AttributeSpanName: "testspan", AttributeProcessorEvent: "span", AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), AttributeServiceTargetType: "cassandra", AttributeServiceTargetName: "testsvc", AttributeSpanDestinationServiceResource: "testsvc", From e67a5453246e21814d60a9dc3f63e9ff1a5ee5c1 Mon Sep 17 00:00:00 2001 From: Vishal Raj Date: Fri, 9 Aug 2024 17:45:31 +0100 Subject: [PATCH 4/4] Add {transaction, span}.duration.us enrichment --- enrichments/trace/config/config.go | 4 + .../trace/internal/elastic/attributes.go | 4 +- enrichments/trace/internal/elastic/span.go | 10 + .../trace/internal/elastic/span_test.go | 214 +++++++++++------- 4 files changed, 147 insertions(+), 85 deletions(-) diff --git a/enrichments/trace/config/config.go b/enrichments/trace/config/config.go index 6b3064e..568651e 100644 --- a/enrichments/trace/config/config.go +++ b/enrichments/trace/config/config.go @@ -44,6 +44,7 @@ type ElasticTransactionConfig struct { Root AttributeConfig `mapstructure:"root"` Name AttributeConfig `mapstructure:"name"` ProcessorEvent AttributeConfig `mapstructure:"processor_event"` + DurationUs AttributeConfig `mapstructure:"duration_us"` Type AttributeConfig `mapstructure:"type"` Result AttributeConfig `mapstructure:"result"` EventOutcome AttributeConfig `mapstructure:"event_outcome"` @@ -54,6 +55,7 @@ type ElasticTransactionConfig struct { type ElasticSpanConfig struct { Name AttributeConfig `mapstructure:"name"` ProcessorEvent AttributeConfig `mapstructure:"processor_event"` + DurationUs AttributeConfig `mapstructure:"duration_us"` EventOutcome AttributeConfig `mapstructure:"event_outcome"` ServiceTarget AttributeConfig `mapstructure:"service_target"` DestinationService AttributeConfig `mapstructure:"destination_service"` @@ -80,6 +82,7 @@ func Enabled() Config { Root: AttributeConfig{Enabled: true}, Name: AttributeConfig{Enabled: true}, ProcessorEvent: AttributeConfig{Enabled: true}, + DurationUs: AttributeConfig{Enabled: true}, Type: AttributeConfig{Enabled: true}, Result: AttributeConfig{Enabled: true}, EventOutcome: AttributeConfig{Enabled: true}, @@ -87,6 +90,7 @@ func Enabled() Config { Span: ElasticSpanConfig{ Name: AttributeConfig{Enabled: true}, ProcessorEvent: AttributeConfig{Enabled: true}, + DurationUs: AttributeConfig{Enabled: true}, EventOutcome: AttributeConfig{Enabled: true}, ServiceTarget: AttributeConfig{Enabled: true}, DestinationService: AttributeConfig{Enabled: true}, diff --git a/enrichments/trace/internal/elastic/attributes.go b/enrichments/trace/internal/elastic/attributes.go index a3a872c..d72316e 100644 --- a/enrichments/trace/internal/elastic/attributes.go +++ b/enrichments/trace/internal/elastic/attributes.go @@ -27,11 +27,12 @@ const ( AttributeServiceFrameworkVersion = "service.framework.version" // span attributes + AttributeProcessorEvent = "processor.event" AttributeTransactionID = "transaction.id" AttributeTransactionRoot = "transaction.root" AttributeTransactionName = "transaction.name" - AttributeProcessorEvent = "processor.event" AttributeTransactionType = "transaction.type" + AttributeTransactionDurationUs = "transaction.duration.us" AttributeTransactionResult = "transaction.result" AttributeSpanName = "span.name" AttributeEventOutcome = "event.outcome" @@ -39,4 +40,5 @@ const ( AttributeServiceTargetType = "service.target.type" AttributeServiceTargetName = "service.target.name" AttributeSpanDestinationServiceResource = "span.destination.service.resource" + AttributeSpanDurationUs = "span.duration.us" ) diff --git a/enrichments/trace/internal/elastic/span.go b/enrichments/trace/internal/elastic/span.go index 2d973a8..d304f6e 100644 --- a/enrichments/trace/internal/elastic/span.go +++ b/enrichments/trace/internal/elastic/span.go @@ -173,6 +173,9 @@ func (s *spanEnrichmentContext) enrichTransaction( if cfg.ProcessorEvent.Enabled { span.Attributes().PutStr(AttributeProcessorEvent, "transaction") } + if cfg.DurationUs.Enabled { + span.Attributes().PutInt(AttributeTransactionDurationUs, getDurationUs(span)) + } if cfg.Type.Enabled { s.setTxnType(span) } @@ -197,6 +200,9 @@ func (s *spanEnrichmentContext) enrichSpan( if cfg.EventOutcome.Enabled { s.setEventOutcome(span) } + if cfg.DurationUs.Enabled { + span.Attributes().PutInt(AttributeSpanDurationUs, getDurationUs(span)) + } if cfg.ServiceTarget.Enabled { s.setServiceTarget(span) } @@ -350,6 +356,10 @@ func (s *spanEnrichmentContext) setDestinationService(span ptrace.Span) { } } +func getDurationUs(span ptrace.Span) int64 { + return int64(span.EndTimestamp()-span.StartTimestamp()) / 1000 +} + func isTraceRoot(span ptrace.Span) bool { return span.ParentSpanID().IsEmpty() } diff --git a/enrichments/trace/internal/elastic/span_test.go b/enrichments/trace/internal/elastic/span_test.go index d1199d2..d0882d3 100644 --- a/enrichments/trace/internal/elastic/span_test.go +++ b/enrichments/trace/internal/elastic/span_test.go @@ -20,10 +20,12 @@ package elastic import ( "net/http" "testing" + "time" "github.com/elastic/opentelemetry-lib/enrichments/trace/config" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/assert" + "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/ptrace" semconv "go.opentelemetry.io/collector/semconv/v1.25.0" tracepb "go.opentelemetry.io/proto/otlp/trace/v1" @@ -32,6 +34,17 @@ import ( // Tests the enrichment logic for elastic's transaction definition. func TestElasticTransactionEnrich(t *testing.T) { + now := time.Unix(3600, 0) + expectedDuration := time.Minute + endTs := pcommon.NewTimestampFromTime(now) + startTs := pcommon.NewTimestampFromTime(now.Add(-1 * expectedDuration)) + getElasticTxn := func() ptrace.Span { + span := ptrace.NewSpan() + span.SetSpanID([8]byte{1}) + span.SetStartTimestamp(startTs) + span.SetEndTimestamp(endTs) + return span + } for _, tc := range []struct { name string input ptrace.Span @@ -39,50 +52,52 @@ func TestElasticTransactionEnrich(t *testing.T) { enrichedAttrs map[string]any }{ { + // test case gives a summary of what is emitted by default name: "empty", input: ptrace.NewSpan(), config: config.Enabled().Transaction, enrichedAttrs: map[string]any{ - AttributeTransactionRoot: true, - AttributeTransactionID: "", - AttributeTransactionName: "", - AttributeProcessorEvent: "transaction", - AttributeEventOutcome: "success", - AttributeSuccessCount: int64(1), - AttributeTransactionResult: "Success", - AttributeTransactionType: "unknown", + AttributeTransactionRoot: true, + AttributeTransactionID: "", + AttributeTransactionName: "", + AttributeProcessorEvent: "transaction", + AttributeTransactionDurationUs: int64(0), + AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), + AttributeTransactionResult: "Success", + AttributeTransactionType: "unknown", }, }, { name: "all_disabled", - input: ptrace.NewSpan(), + input: getElasticTxn(), enrichedAttrs: map[string]any{}, }, { name: "http_status_ok", input: func() ptrace.Span { - span := ptrace.NewSpan() + span := getElasticTxn() span.SetName("testtxn") - span.SetSpanID([8]byte{1}) span.Attributes().PutInt(semconv.AttributeHTTPStatusCode, http.StatusOK) return span }(), config: config.Enabled().Transaction, enrichedAttrs: map[string]any{ - AttributeTransactionRoot: true, - AttributeTransactionID: "0100000000000000", - AttributeTransactionName: "testtxn", - AttributeProcessorEvent: "transaction", - AttributeEventOutcome: "success", - AttributeSuccessCount: int64(1), - AttributeTransactionResult: "HTTP 2xx", - AttributeTransactionType: "request", + AttributeTransactionRoot: true, + AttributeTransactionID: "0100000000000000", + AttributeTransactionName: "testtxn", + AttributeProcessorEvent: "transaction", + AttributeTransactionDurationUs: expectedDuration.Microseconds(), + AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), + AttributeTransactionResult: "HTTP 2xx", + AttributeTransactionType: "request", }, }, { name: "http_status_1xx", input: func() ptrace.Span { - span := ptrace.NewSpan() + span := getElasticTxn() span.SetName("testtxn") span.SetSpanID([8]byte{1}) // attributes should be preferred over span status for txn result @@ -95,20 +110,21 @@ func TestElasticTransactionEnrich(t *testing.T) { }(), config: config.Enabled().Transaction, enrichedAttrs: map[string]any{ - AttributeTransactionRoot: true, - AttributeTransactionID: "0100000000000000", - AttributeTransactionName: "testtxn", - AttributeProcessorEvent: "transaction", - AttributeEventOutcome: "success", - AttributeSuccessCount: int64(1), - AttributeTransactionResult: "HTTP 1xx", - AttributeTransactionType: "request", + AttributeTransactionRoot: true, + AttributeTransactionID: "0100000000000000", + AttributeTransactionName: "testtxn", + AttributeProcessorEvent: "transaction", + AttributeTransactionDurationUs: expectedDuration.Microseconds(), + AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), + AttributeTransactionResult: "HTTP 1xx", + AttributeTransactionType: "request", }, }, { name: "http_status_5xx", input: func() ptrace.Span { - span := ptrace.NewSpan() + span := getElasticTxn() span.SetName("testtxn") span.SetSpanID([8]byte{1}) // span status code should take precedence over http status attributes @@ -120,20 +136,21 @@ func TestElasticTransactionEnrich(t *testing.T) { }(), config: config.Enabled().Transaction, enrichedAttrs: map[string]any{ - AttributeTransactionRoot: true, - AttributeTransactionID: "0100000000000000", - AttributeTransactionName: "testtxn", - AttributeProcessorEvent: "transaction", - AttributeEventOutcome: "success", - AttributeSuccessCount: int64(1), - AttributeTransactionResult: "HTTP 5xx", - AttributeTransactionType: "request", + AttributeTransactionRoot: true, + AttributeTransactionID: "0100000000000000", + AttributeTransactionName: "testtxn", + AttributeProcessorEvent: "transaction", + AttributeTransactionDurationUs: expectedDuration.Microseconds(), + AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), + AttributeTransactionResult: "HTTP 5xx", + AttributeTransactionType: "request", }, }, { name: "grpc_status_ok", input: func() ptrace.Span { - span := ptrace.NewSpan() + span := getElasticTxn() span.SetName("testtxn") span.SetSpanID([8]byte{1}) // attributes should be preferred over span status for txn result @@ -146,20 +163,21 @@ func TestElasticTransactionEnrich(t *testing.T) { }(), config: config.Enabled().Transaction, enrichedAttrs: map[string]any{ - AttributeTransactionRoot: true, - AttributeTransactionID: "0100000000000000", - AttributeTransactionName: "testtxn", - AttributeProcessorEvent: "transaction", - AttributeEventOutcome: "success", - AttributeSuccessCount: int64(1), - AttributeTransactionResult: "OK", - AttributeTransactionType: "request", + AttributeTransactionRoot: true, + AttributeTransactionID: "0100000000000000", + AttributeTransactionName: "testtxn", + AttributeProcessorEvent: "transaction", + AttributeTransactionDurationUs: expectedDuration.Microseconds(), + AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), + AttributeTransactionResult: "OK", + AttributeTransactionType: "request", }, }, { name: "grpc_status_internal_error", input: func() ptrace.Span { - span := ptrace.NewSpan() + span := getElasticTxn() span.SetName("testtxn") span.SetSpanID([8]byte{1}) // attributes should be preferred over span status for txn result @@ -172,20 +190,21 @@ func TestElasticTransactionEnrich(t *testing.T) { }(), config: config.Enabled().Transaction, enrichedAttrs: map[string]any{ - AttributeTransactionRoot: true, - AttributeTransactionID: "0100000000000000", - AttributeTransactionName: "testtxn", - AttributeProcessorEvent: "transaction", - AttributeEventOutcome: "success", - AttributeSuccessCount: int64(1), - AttributeTransactionResult: "Internal", - AttributeTransactionType: "request", + AttributeTransactionRoot: true, + AttributeTransactionID: "0100000000000000", + AttributeTransactionName: "testtxn", + AttributeProcessorEvent: "transaction", + AttributeTransactionDurationUs: expectedDuration.Microseconds(), + AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), + AttributeTransactionResult: "Internal", + AttributeTransactionType: "request", }, }, { name: "span_status_ok", input: func() ptrace.Span { - span := ptrace.NewSpan() + span := getElasticTxn() span.SetName("testtxn") span.SetSpanID([8]byte{1}) span.Status().SetCode(ptrace.StatusCodeOk) @@ -193,20 +212,21 @@ func TestElasticTransactionEnrich(t *testing.T) { }(), config: config.Enabled().Transaction, enrichedAttrs: map[string]any{ - AttributeTransactionRoot: true, - AttributeTransactionID: "0100000000000000", - AttributeTransactionName: "testtxn", - AttributeProcessorEvent: "transaction", - AttributeEventOutcome: "success", - AttributeSuccessCount: int64(1), - AttributeTransactionResult: "Success", - AttributeTransactionType: "unknown", + AttributeTransactionRoot: true, + AttributeTransactionID: "0100000000000000", + AttributeTransactionName: "testtxn", + AttributeProcessorEvent: "transaction", + AttributeTransactionDurationUs: expectedDuration.Microseconds(), + AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), + AttributeTransactionResult: "Success", + AttributeTransactionType: "unknown", }, }, { name: "span_status_error", input: func() ptrace.Span { - span := ptrace.NewSpan() + span := getElasticTxn() span.SetName("testtxn") span.SetSpanID([8]byte{1}) span.Status().SetCode(ptrace.StatusCodeError) @@ -214,20 +234,21 @@ func TestElasticTransactionEnrich(t *testing.T) { }(), config: config.Enabled().Transaction, enrichedAttrs: map[string]any{ - AttributeTransactionRoot: true, - AttributeTransactionID: "0100000000000000", - AttributeTransactionName: "testtxn", - AttributeProcessorEvent: "transaction", - AttributeEventOutcome: "failure", - AttributeSuccessCount: int64(0), - AttributeTransactionResult: "Error", - AttributeTransactionType: "unknown", + AttributeTransactionRoot: true, + AttributeTransactionID: "0100000000000000", + AttributeTransactionName: "testtxn", + AttributeProcessorEvent: "transaction", + AttributeTransactionDurationUs: expectedDuration.Microseconds(), + AttributeEventOutcome: "failure", + AttributeSuccessCount: int64(0), + AttributeTransactionResult: "Error", + AttributeTransactionType: "unknown", }, }, { name: "messaging_type_kafka", input: func() ptrace.Span { - span := ptrace.NewSpan() + span := getElasticTxn() span.SetName("testtxn") span.SetSpanID([8]byte{1}) span.Attributes().PutStr(semconv.AttributeMessagingSystem, "kafka") @@ -235,14 +256,15 @@ func TestElasticTransactionEnrich(t *testing.T) { }(), config: config.Enabled().Transaction, enrichedAttrs: map[string]any{ - AttributeTransactionRoot: true, - AttributeTransactionID: "0100000000000000", - AttributeTransactionName: "testtxn", - AttributeProcessorEvent: "transaction", - AttributeEventOutcome: "success", - AttributeSuccessCount: int64(1), - AttributeTransactionResult: "Success", - AttributeTransactionType: "messaging", + AttributeTransactionRoot: true, + AttributeTransactionID: "0100000000000000", + AttributeTransactionName: "testtxn", + AttributeProcessorEvent: "transaction", + AttributeTransactionDurationUs: expectedDuration.Microseconds(), + AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), + AttributeTransactionResult: "Success", + AttributeTransactionType: "messaging", }, }, } { @@ -265,9 +287,15 @@ func TestElasticTransactionEnrich(t *testing.T) { // Tests the enrichment logic for elastic's span definition. func TestElasticSpanEnrich(t *testing.T) { + now := time.Unix(3600, 0) + expectedDuration := time.Minute + endTs := pcommon.NewTimestampFromTime(now) + startTs := pcommon.NewTimestampFromTime(now.Add(-1 * expectedDuration)) getElasticSpan := func() ptrace.Span { span := ptrace.NewSpan() span.SetParentSpanID([8]byte{8, 9, 10, 11, 12, 13, 14}) + span.SetStartTimestamp(startTs) + span.SetEndTimestamp(endTs) return span } for _, tc := range []struct { @@ -277,12 +305,18 @@ func TestElasticSpanEnrich(t *testing.T) { enrichedAttrs map[string]any }{ { - name: "empty", - input: getElasticSpan(), + // test case gives a summary of what is emitted by default + name: "empty", + input: func() ptrace.Span { + span := ptrace.NewSpan() + span.SetParentSpanID([8]byte{1}) + return span + }(), config: config.Enabled().Span, enrichedAttrs: map[string]any{ AttributeSpanName: "", AttributeProcessorEvent: "span", + AttributeSpanDurationUs: int64(0), AttributeEventOutcome: "success", AttributeSuccessCount: int64(1), }, @@ -304,6 +338,7 @@ func TestElasticSpanEnrich(t *testing.T) { enrichedAttrs: map[string]any{ AttributeSpanName: "testspan", AttributeProcessorEvent: "span", + AttributeSpanDurationUs: expectedDuration.Microseconds(), AttributeEventOutcome: "success", AttributeSuccessCount: int64(1), AttributeServiceTargetName: "testsvc", @@ -327,6 +362,7 @@ func TestElasticSpanEnrich(t *testing.T) { enrichedAttrs: map[string]any{ AttributeSpanName: "testspan", AttributeProcessorEvent: "span", + AttributeSpanDurationUs: expectedDuration.Microseconds(), AttributeEventOutcome: "success", AttributeSuccessCount: int64(1), AttributeServiceTargetType: "http", @@ -356,6 +392,7 @@ func TestElasticSpanEnrich(t *testing.T) { enrichedAttrs: map[string]any{ AttributeSpanName: "testspan", AttributeProcessorEvent: "span", + AttributeSpanDurationUs: expectedDuration.Microseconds(), AttributeEventOutcome: "success", AttributeSuccessCount: int64(1), AttributeServiceTargetType: "http", @@ -383,6 +420,7 @@ func TestElasticSpanEnrich(t *testing.T) { enrichedAttrs: map[string]any{ AttributeSpanName: "testspan", AttributeProcessorEvent: "span", + AttributeSpanDurationUs: expectedDuration.Microseconds(), AttributeEventOutcome: "success", AttributeSuccessCount: int64(1), AttributeServiceTargetType: "http", @@ -406,6 +444,7 @@ func TestElasticSpanEnrich(t *testing.T) { enrichedAttrs: map[string]any{ AttributeSpanName: "testspan", AttributeProcessorEvent: "span", + AttributeSpanDurationUs: expectedDuration.Microseconds(), AttributeEventOutcome: "success", AttributeSuccessCount: int64(1), AttributeServiceTargetType: "grpc", @@ -426,6 +465,7 @@ func TestElasticSpanEnrich(t *testing.T) { enrichedAttrs: map[string]any{ AttributeSpanName: "testspan", AttributeProcessorEvent: "span", + AttributeSpanDurationUs: expectedDuration.Microseconds(), AttributeEventOutcome: "success", AttributeSuccessCount: int64(1), AttributeServiceTargetType: "xmlrpc", @@ -448,6 +488,7 @@ func TestElasticSpanEnrich(t *testing.T) { enrichedAttrs: map[string]any{ AttributeSpanName: "testspan", AttributeProcessorEvent: "span", + AttributeSpanDurationUs: expectedDuration.Microseconds(), AttributeEventOutcome: "success", AttributeSuccessCount: int64(1), AttributeServiceTargetType: "external", @@ -468,6 +509,7 @@ func TestElasticSpanEnrich(t *testing.T) { enrichedAttrs: map[string]any{ AttributeSpanName: "testspan", AttributeProcessorEvent: "span", + AttributeSpanDurationUs: expectedDuration.Microseconds(), AttributeEventOutcome: "success", AttributeSuccessCount: int64(1), AttributeServiceTargetType: "kafka", @@ -488,6 +530,7 @@ func TestElasticSpanEnrich(t *testing.T) { enrichedAttrs: map[string]any{ AttributeSpanName: "testspan", AttributeProcessorEvent: "span", + AttributeSpanDurationUs: expectedDuration.Microseconds(), AttributeEventOutcome: "success", AttributeSuccessCount: int64(1), AttributeServiceTargetType: "messaging", @@ -509,6 +552,7 @@ func TestElasticSpanEnrich(t *testing.T) { enrichedAttrs: map[string]any{ AttributeSpanName: "testspan", AttributeProcessorEvent: "span", + AttributeSpanDurationUs: expectedDuration.Microseconds(), AttributeEventOutcome: "success", AttributeSuccessCount: int64(1), AttributeServiceTargetType: "messaging", @@ -536,6 +580,7 @@ func TestElasticSpanEnrich(t *testing.T) { enrichedAttrs: map[string]any{ AttributeSpanName: "testspan", AttributeProcessorEvent: "span", + AttributeSpanDurationUs: expectedDuration.Microseconds(), AttributeEventOutcome: "success", AttributeSuccessCount: int64(1), AttributeServiceTargetType: "elasticsearch", @@ -568,6 +613,7 @@ func TestElasticSpanEnrich(t *testing.T) { enrichedAttrs: map[string]any{ AttributeSpanName: "testspan", AttributeProcessorEvent: "span", + AttributeSpanDurationUs: expectedDuration.Microseconds(), AttributeEventOutcome: "success", AttributeSuccessCount: int64(1), AttributeServiceTargetType: "cassandra",