Skip to content

Commit

Permalink
Backport 1441 to 1.9 (#1443)
Browse files Browse the repository at this point in the history
  • Loading branch information
grcevski authored Dec 10, 2024
1 parent 0fc22d9 commit 4a34748
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/export/prom/prom.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,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
14 changes: 14 additions & 0 deletions 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.filtered, mr.otelSpanFiltered(&tt.span), tt.name)
})
}
}
Expand Down

0 comments on commit 4a34748

Please sign in to comment.