Skip to content

Commit

Permalink
Fix missing check for ignored metrics for Prometheus export (#1441)
Browse files Browse the repository at this point in the history
  • Loading branch information
grcevski authored Dec 10, 2024
1 parent 8c771fb commit 85b6cdd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 5 additions & 1 deletion pkg/export/prom/prom.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,13 @@ func (r *metricsReporter) otelSpanObserved(span *request.Span) bool {
return r.cfg.OTelMetricsEnabled() && !span.Service.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()
Expand Down
16 changes: 15 additions & 1 deletion pkg/export/prom/prom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,31 +316,45 @@ func TestSpanMetricsDiscarded(t *testing.T) {
svcExportTraces := svc.Attrs{}
svcExportTraces.SetExportsOTelTraces()

ignoredSpan := request.Span{Service: 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{Service: 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{Service: 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{Service: 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.discarded, !(mr.otelSpanObserved(&tt.span)), tt.name)
assert.Equal(t, tt.filtered, mr.otelSpanFiltered(&tt.span), tt.name)
})
}
}
Expand Down

0 comments on commit 85b6cdd

Please sign in to comment.