From c28cb688a734191c7e0d3b541a75775b16ae13e1 Mon Sep 17 00:00:00 2001 From: Riccardo Magliocchetti Date: Wed, 4 Jun 2025 14:54:53 +0200 Subject: [PATCH] enrichments: handle gen_ai.provider.name too Same enrichment as the previous gen_ai.system --- enrichments/internal/elastic/span.go | 3 ++- enrichments/internal/elastic/span_test.go | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/enrichments/internal/elastic/span.go b/enrichments/internal/elastic/span.go index 2e7d311..136798b 100644 --- a/enrichments/internal/elastic/span.go +++ b/enrichments/internal/elastic/span.go @@ -37,6 +37,7 @@ import ( "go.opentelemetry.io/collector/pdata/ptrace" semconv25 "go.opentelemetry.io/otel/semconv/v1.25.0" semconv27 "go.opentelemetry.io/otel/semconv/v1.27.0" + semconv37 "go.opentelemetry.io/otel/semconv/v1.37.0" tracepb "go.opentelemetry.io/proto/otlp/trace/v1" "google.golang.org/grpc/codes" ) @@ -197,7 +198,7 @@ func (s *spanEnrichmentContext) Enrich( case string(semconv25.DBSystemKey): s.isDB = true s.dbSystem = v.Str() - case string(semconv27.GenAISystemKey): + case string(semconv27.GenAISystemKey), string(semconv37.GenAIProviderNameKey): s.isGenAi = true s.genAiSystem = v.Str() case string(semconv27.UserAgentOriginalKey): diff --git a/enrichments/internal/elastic/span_test.go b/enrichments/internal/elastic/span_test.go index 7e37d7b..c403df4 100644 --- a/enrichments/internal/elastic/span_test.go +++ b/enrichments/internal/elastic/span_test.go @@ -34,6 +34,7 @@ import ( "go.opentelemetry.io/collector/pdata/ptrace" semconv25 "go.opentelemetry.io/otel/semconv/v1.25.0" semconv27 "go.opentelemetry.io/otel/semconv/v1.27.0" + semconv37 "go.opentelemetry.io/otel/semconv/v1.37.0" tracepb "go.opentelemetry.io/proto/otlp/trace/v1" "google.golang.org/grpc/codes" ) @@ -1351,6 +1352,28 @@ func TestElasticSpanEnrich(t *testing.T) { elasticattr.SuccessCount: int64(1), }, }, + { + name: "genai_with_provider_name", + input: func() ptrace.Span { + span := getElasticSpan() + span.SetName("testspan") + span.SetSpanID([8]byte{1}) + span.Attributes().PutStr(string(semconv37.GenAIProviderNameKey), "openai") + return span + }(), + config: config.Enabled().Span, + enrichedAttrs: map[string]any{ + elasticattr.TimestampUs: startTs.AsTime().UnixMicro(), + elasticattr.SpanName: "testspan", + elasticattr.ProcessorEvent: "span", + elasticattr.SpanRepresentativeCount: float64(1), + elasticattr.SpanType: "genai", + elasticattr.SpanSubtype: "openai", + elasticattr.SpanDurationUs: expectedDuration.Microseconds(), + elasticattr.EventOutcome: "success", + elasticattr.SuccessCount: int64(1), + }, + }, { name: "rpc_span_with_only_rpc_sevice_attr", input: func() ptrace.Span {