From 42bfa0055cac54bea904f0e0c238286f04c9124b Mon Sep 17 00:00:00 2001 From: Nikola Grcevski <6207777+grcevski@users.noreply.github.com> Date: Tue, 10 Dec 2024 13:53:24 -0500 Subject: [PATCH] Backport 1441 to 1.8 (#1442) --- pkg/export/prom/prom.go | 6 +++++- pkg/export/prom/prom_test.go | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/pkg/export/prom/prom.go b/pkg/export/prom/prom.go index 89916b717..b5cf29aee 100644 --- a/pkg/export/prom/prom.go +++ b/pkg/export/prom/prom.go @@ -581,9 +581,13 @@ func (r *metricsReporter) otelSpanObserved(span *request.Span) bool { return r.cfg.OTelMetricsEnabled() && !span.ServiceID.ExportsOTelMetrics() } +func (r *metricsReporter) otelSpanFiltered(span *request.Span) bool { + return span.InternalSignal() || span.IgnoreMetrics() +} + // nolint:cyclop func (r *metricsReporter) observe(span *request.Span) { - if span.InternalSignal() { + if r.otelSpanFiltered(span) { return } t := span.Timings() diff --git a/pkg/export/prom/prom_test.go b/pkg/export/prom/prom_test.go index b3c0c6398..e47971aa4 100644 --- a/pkg/export/prom/prom_test.go +++ b/pkg/export/prom/prom_test.go @@ -316,31 +316,45 @@ func TestSpanMetricsDiscarded(t *testing.T) { svcExportTraces := svc.ID{} svcExportTraces.SetExportsOTelTraces() + ignoredSpan := request.Span{ServiceID: svcExportTraces, Type: request.EventTypeHTTPClient, Method: "GET", Route: "/v1/traces", RequestStart: 100, End: 200} + ignoredSpan.SetIgnoreMetrics() + tests := []struct { name string span request.Span discarded bool + filtered bool }{ { name: "Foo span is not filtered", span: request.Span{ServiceID: svcNoExport, Type: request.EventTypeHTTPClient, Method: "GET", Route: "/foo", RequestStart: 100, End: 200}, discarded: false, + filtered: false, }, { name: "/v1/metrics span is filtered", span: request.Span{ServiceID: svcExportMetrics, Type: request.EventTypeHTTPClient, Method: "GET", Route: "/v1/metrics", RequestStart: 100, End: 200}, discarded: true, + filtered: false, + }, + { + name: "/v1/traces span is filtered because we ignore this span", + span: ignoredSpan, + discarded: false, + filtered: true, }, { name: "/v1/traces span is not filtered", span: request.Span{ServiceID: svcExportTraces, Type: request.EventTypeHTTPClient, Method: "GET", Route: "/v1/traces", RequestStart: 100, End: 200}, discarded: false, + filtered: false, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { assert.Equal(t, tt.discarded, !mr.otelSpanObserved(&tt.span), tt.name) + assert.Equal(t, tt.filtered, mr.otelSpanFiltered(&tt.span), tt.name) }) } }