Skip to content

Commit

Permalink
extract method SkipSpan
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitlinger committed May 7, 2020
1 parent 1da3156 commit 7482f90
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 50 deletions.
24 changes: 24 additions & 0 deletions internal/processor/filterspan/filterspan.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,30 @@ func newAttributesMatcher(config *MatchProperties) (attributesMatcher, error) {
return rawAttributes, nil
}

// SkipSpan determines if a span should be processed.
// True is returned when a span should be skipped.
// False is returned when a span should not be skipped.
// The logic determining if a span should be processed is set
// in the attribute configuration with the include and exclude settings.
// Include properties are checked before exclude settings are checked.
func SkipSpan(include Matcher, exclude Matcher, span pdata.Span, serviceName string) bool {
if include != nil {
// A false returned in this case means the span should not be processed.
if i := include.MatchSpan(span, serviceName); !i {
return true
}
}

if exclude != nil {
// A true returned in this case means the span should not be processed.
if e := exclude.MatchSpan(span, serviceName); e {
return true
}
}

return false
}

// MatchSpan matches a span and service to a set of properties.
// There are 3 sets of properties to match against.
// The service name is checked first, if specified. Then span names are matched, if specified.
Expand Down
26 changes: 1 addition & 25 deletions processor/attributesprocessor/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (a *attributesProcessor) processSpan(span pdata.Span, serviceName string) {
return
}

if a.skipSpan(span, serviceName) {
if filterspan.SkipSpan(a.config.include, a.config.exclude, span, serviceName) {
return
}

Expand Down Expand Up @@ -158,27 +158,3 @@ func hashAttribute(action attributeAction, attrs pdata.AttributeMap) {
SHA1AttributeHasher(value)
}
}

// skipSpan determines if a span should be processed.
// True is returned when a span should be skipped.
// False is returned when a span should not be skipped.
// The logic determining if a span should be processed is set
// in the attribute configuration with the include and exclude settings.
// Include properties are checked before exclude settings are checked.
func (a *attributesProcessor) skipSpan(span pdata.Span, serviceName string) bool {
if a.config.include != nil {
// A false returned in this case means the span should not be processed.
if include := a.config.include.MatchSpan(span, serviceName); !include {
return true
}
}

if a.config.exclude != nil {
// A true returned in this case means the span should not be processed.
if exclude := a.config.exclude.MatchSpan(span, serviceName); exclude {
return true
}
}

return false
}
26 changes: 1 addition & 25 deletions processor/spanprocessor/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (sp *spanProcessor) ConsumeTraces(ctx context.Context, td pdata.Traces) err
continue
}

if sp.skipSpan(s, serviceName) {
if filterspan.SkipSpan(sp.include, sp.exclude, s, serviceName) {
continue
}
sp.processFromAttributes(s)
Expand Down Expand Up @@ -254,27 +254,3 @@ func (sp *spanProcessor) processToAttributes(span pdata.Span) {
}
}
}

// skipSpan determines if a span should be processed.
// True is returned when a span should be skipped.
// False is returned when a span should not be skipped.
// The logic determining if a span should be processed is set
// in the attribute configuration with the include and exclude settings.
// Include properties are checked before exclude settings are checked.
func (sp *spanProcessor) skipSpan(span pdata.Span, serviceName string) bool {
if sp.include != nil {
// A false returned in this case means the span should not be processed.
if include := sp.include.MatchSpan(span, serviceName); !include {
return true
}
}

if sp.exclude != nil {
// A true returned in this case means the span should not be processed.
if exclude := sp.exclude.MatchSpan(span, serviceName); exclude {
return true
}
}

return false
}

0 comments on commit 7482f90

Please sign in to comment.