From 5278001706c7b84079138bd566165e9247e5e89e Mon Sep 17 00:00:00 2001 From: Vishal Raj Date: Wed, 2 Oct 2024 16:16:36 +0100 Subject: [PATCH] Add enrichment for error.grouping_name --- enrichments/trace/config/config.go | 6 ++---- enrichments/trace/internal/elastic/attributes.go | 1 + enrichments/trace/internal/elastic/span.go | 5 +++++ enrichments/trace/internal/elastic/span_test.go | 2 ++ 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/enrichments/trace/config/config.go b/enrichments/trace/config/config.go index 96a78fd..e0dc370 100644 --- a/enrichments/trace/config/config.go +++ b/enrichments/trace/config/config.go @@ -88,9 +88,7 @@ type SpanEventConfig struct { ErrorID AttributeConfig `mapstructure:"error_id"` ErrorExceptionHandled AttributeConfig `mapstructure:"error_exception_handled"` ErrorGroupingKey AttributeConfig `mapstructure:"error_grouping_key"` - - // For no exceptions/errors - EventKind AttributeConfig `mapstructure:"event_kind"` + ErrorGroupingName AttributeConfig `mapstructure:"error_grouping_name"` } // AttributeConfig is the configuration options for each attribute. @@ -141,7 +139,7 @@ func Enabled() Config { ErrorID: AttributeConfig{Enabled: true}, ErrorExceptionHandled: AttributeConfig{Enabled: true}, ErrorGroupingKey: AttributeConfig{Enabled: true}, - EventKind: AttributeConfig{Enabled: true}, + ErrorGroupingName: AttributeConfig{Enabled: true}, }, } } diff --git a/enrichments/trace/internal/elastic/attributes.go b/enrichments/trace/internal/elastic/attributes.go index b7466df..b94ccdd 100644 --- a/enrichments/trace/internal/elastic/attributes.go +++ b/enrichments/trace/internal/elastic/attributes.go @@ -53,4 +53,5 @@ const ( AttributeErrorID = "error.id" AttributeErrorExceptionHandled = "error.exception.handled" AttributeErrorGroupingKey = "error.grouping_key" + AttributeErrorGroupingName = "error.grouping_name" ) diff --git a/enrichments/trace/internal/elastic/span.go b/enrichments/trace/internal/elastic/span.go index cf17e5d..ed8db26 100644 --- a/enrichments/trace/internal/elastic/span.go +++ b/enrichments/trace/internal/elastic/span.go @@ -491,6 +491,11 @@ func (s *spanEventEnrichmentContext) enrich( } se.Attributes().PutStr(AttributeErrorGroupingKey, hex.EncodeToString(hash.Sum(nil))) } + if cfg.ErrorGroupingName.Enabled { + if s.exceptionMessage != "" { + se.Attributes().PutStr(AttributeErrorGroupingName, s.exceptionMessage) + } + } // Transaction type and sampled are added as span event enrichment only for errors if parentCtx.isTransaction && s.exception { diff --git a/enrichments/trace/internal/elastic/span_test.go b/enrichments/trace/internal/elastic/span_test.go index 258102e..8b9c511 100644 --- a/enrichments/trace/internal/elastic/span_test.go +++ b/enrichments/trace/internal/elastic/span_test.go @@ -811,6 +811,7 @@ func TestSpanEventEnrich(t *testing.T) { hash.Write([]byte("java.net.ConnectionError")) return hex.EncodeToString(hash.Sum(nil)) }(), + AttributeErrorGroupingName: "something is wrong", AttributeTransactionSampled: true, AttributeTransactionType: "unknown", }, @@ -843,6 +844,7 @@ func TestSpanEventEnrich(t *testing.T) { hash.Write([]byte("java.net.ConnectionError")) return hex.EncodeToString(hash.Sum(nil)) }(), + AttributeErrorGroupingName: "something is wrong", }, }, } {