From 5df631c61989eb9b356a8e7ee5e5dd47220d788a Mon Sep 17 00:00:00 2001 From: Vishal Raj Date: Fri, 11 Oct 2024 14:22:08 +0100 Subject: [PATCH] Add support for http.url to identify url full --- .../trace/internal/elastic/resource.go | 2 +- enrichments/trace/internal/elastic/span.go | 4 +-- .../trace/internal/elastic/span_test.go | 34 +++++++++++++++++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/enrichments/trace/internal/elastic/resource.go b/enrichments/trace/internal/elastic/resource.go index 0c511d2..031f636 100644 --- a/enrichments/trace/internal/elastic/resource.go +++ b/enrichments/trace/internal/elastic/resource.go @@ -22,7 +22,7 @@ import ( "github.com/elastic/opentelemetry-lib/enrichments/trace/config" "go.opentelemetry.io/collector/pdata/pcommon" - semconv "go.opentelemetry.io/collector/semconv/v1.22.0" + semconv "go.opentelemetry.io/collector/semconv/v1.25.0" ) // EnrichResource derives and adds Elastic specific resource attributes. diff --git a/enrichments/trace/internal/elastic/span.go b/enrichments/trace/internal/elastic/span.go index ed8db26..28068fa 100644 --- a/enrichments/trace/internal/elastic/span.go +++ b/enrichments/trace/internal/elastic/span.go @@ -108,13 +108,13 @@ func (s *spanEnrichmentContext) Enrich(span ptrace.Span, cfg config.Config) { s.httpStatusCode = v.Int() case semconv.AttributeHTTPMethod, semconv.AttributeHTTPRequestMethod, - semconv.AttributeHTTPURL, semconv.AttributeHTTPTarget, semconv.AttributeHTTPScheme, semconv.AttributeHTTPFlavor, semconv.AttributeNetHostName: s.isHTTP = true - case semconv.AttributeURLFull: + case semconv.AttributeURLFull, + semconv.AttributeHTTPURL: s.isHTTP = true // ignoring error as if parse fails then we don't want the url anyway s.urlFull, _ = url.Parse(v.Str()) diff --git a/enrichments/trace/internal/elastic/span_test.go b/enrichments/trace/internal/elastic/span_test.go index 8b9c511..295ceb1 100644 --- a/enrichments/trace/internal/elastic/span_test.go +++ b/enrichments/trace/internal/elastic/span_test.go @@ -487,6 +487,40 @@ func TestElasticSpanEnrich(t *testing.T) { AttributeSpanDestinationServiceResource: "testsvc", }, }, + { + name: "http_span_deprecated_http_url", + input: func() ptrace.Span { + span := getElasticSpan() + span.SetName("testspan") + // peer.service should be ignored if more specific deductions + // can be made about the service target. + span.Attributes().PutStr(semconv.AttributePeerService, "testsvc") + span.Attributes().PutInt( + semconv.AttributeHTTPResponseStatusCode, + http.StatusOK, + ) + span.Attributes().PutStr( + semconv.AttributeHTTPURL, + "https://www.foo.bar:443/search?q=OpenTelemetry#SemConv", + ) + return span + }(), + config: config.Enabled().Span, + enrichedAttrs: map[string]any{ + AttributeTimestampUs: startTs.AsTime().UnixMicro(), + AttributeSpanName: "testspan", + AttributeProcessorEvent: "span", + AttributeSpanRepresentativeCount: float64(1), + AttributeSpanType: "external", + AttributeSpanSubtype: "http", + AttributeSpanDurationUs: expectedDuration.Microseconds(), + AttributeEventOutcome: "success", + AttributeSuccessCount: int64(1), + AttributeServiceTargetType: "http", + AttributeServiceTargetName: "www.foo.bar:443", + AttributeSpanDestinationServiceResource: "testsvc", + }, + }, { name: "http_span_no_full_url", input: func() ptrace.Span {