From 4c3eca3d559237ce6a1d5e1ae09edc4c1a2ee25f Mon Sep 17 00:00:00 2001 From: Mario Macias Date: Fri, 21 Feb 2025 17:01:13 +0100 Subject: [PATCH] Fix OTEL HTTP exclusion detection (#1688) * Fix OTEL HTTP exclusion detection * Fix grpc and add traces too * add unit test (cherry picked from commit dabf256a3e526a286bdcea66eb1150d9d8e44814) --- pkg/internal/request/span.go | 4 ++-- pkg/internal/request/span_test.go | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/internal/request/span.go b/pkg/internal/request/span.go index 25a6d452e..5e6527497 100644 --- a/pkg/internal/request/span.go +++ b/pkg/internal/request/span.go @@ -490,7 +490,7 @@ func (s *Span) isMetricsExportURL() bool { case EventTypeGRPCClient: return strings.HasPrefix(s.Path, grpcMetricsDetectPattern) case EventTypeHTTPClient: - return strings.HasPrefix(s.Path, metricsDetectPattern) + return strings.HasSuffix(s.Path, metricsDetectPattern) default: return false } @@ -501,7 +501,7 @@ func (s *Span) isTracesExportURL() bool { case EventTypeGRPCClient: return strings.HasPrefix(s.Path, grpcTracesDetectPattern) case EventTypeHTTPClient: - return strings.HasPrefix(s.Path, tracesDetectPattern) + return strings.HasSuffix(s.Path, tracesDetectPattern) default: return false } diff --git a/pkg/internal/request/span_test.go b/pkg/internal/request/span_test.go index edc131d80..646c96d10 100644 --- a/pkg/internal/request/span_test.go +++ b/pkg/internal/request/span_test.go @@ -264,10 +264,15 @@ func TestDetectsOTelExport(t *testing.T) { exports: false, }, { - name: "Successfull HTTP /v1/metrics spans export", + name: "Successful HTTP /v1/metrics spans export", span: Span{Type: EventTypeHTTPClient, Method: "GET", Path: "/v1/metrics", RequestStart: 100, End: 200, Status: 200}, exports: true, }, + { + name: "Successful HTTP /prefix/v1/metrics spans export", + span: Span{Type: EventTypeHTTPClient, Method: "GET", Path: "/prefix/v1/metrics", RequestStart: 100, End: 200, Status: 200}, + exports: true, + }, { name: "GRPC server spans don't export", span: Span{Type: EventTypeGRPC, Method: "GET", Path: "/opentelemetry.proto.collector.metrics.v1.MetricsService/Export", RequestStart: 100, End: 200, Status: 0},