From 00bc4046eb2d3bfdd34ffbf7a65517812ba4454a Mon Sep 17 00:00:00 2001 From: John Date: Tue, 16 Nov 2021 05:10:22 -0800 Subject: [PATCH] Check resource and span for service.name Signed-off-by: John --- .../coreinternal/processor/filterspan/filterspan.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/coreinternal/processor/filterspan/filterspan.go b/internal/coreinternal/processor/filterspan/filterspan.go index 72724b0dae57..a1ad71596af0 100644 --- a/internal/coreinternal/processor/filterspan/filterspan.go +++ b/internal/coreinternal/processor/filterspan/filterspan.go @@ -111,7 +111,8 @@ func SkipSpan(include Matcher, exclude Matcher, span pdata.Span, resource pdata. func (mp *propertiesMatcher) MatchSpan(span pdata.Span, resource pdata.Resource, library pdata.InstrumentationLibrary) bool { // If a set of properties was not in the mp, all spans are considered to match on that property if mp.serviceFilters != nil { - serviceName := serviceNameForResource(resource) + // Check resource and spans for service.name + serviceName := serviceNameForResource(resource, span) if !mp.serviceFilters.Matches(serviceName) { return false } @@ -124,11 +125,14 @@ func (mp *propertiesMatcher) MatchSpan(span pdata.Span, resource pdata.Resource, return mp.PropertiesMatcher.Match(span.Attributes(), resource, library) } -// serviceNameForResource gets the service name for a specified Resource. -func serviceNameForResource(resource pdata.Resource) string { +// serviceNameForResource gets the service name for a specified Resource and its associated Span. +func serviceNameForResource(resource pdata.Resource, span pdata.Span) string { service, found := resource.Attributes().Get(conventions.AttributeServiceName) if !found { - return "" + service, found = span.Attributes().Get(conventions.AttributeServiceName) + if !found { + return "" + } } return service.StringVal()