Skip to content

Commit

Permalink
[processor/filter] Update processor to log errors (open-telemetry#18862)
Browse files Browse the repository at this point in the history
* Log error

* add changelog

* fix lint
  • Loading branch information
TylerHelmuth committed Feb 23, 2023
1 parent b2d2c40 commit c9aa6e7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
16 changes: 16 additions & 0 deletions .chloggen/fp-log-errors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: filterprocessor

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fixes issue where errors in the filterprocessor might not be logged

# One or more tracking issues related to the change
issues: [18862]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
13 changes: 10 additions & 3 deletions processor/filterprocessor/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/processor/processorhelper"
"go.uber.org/multierr"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/expr"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterconfig"
Expand All @@ -32,16 +33,20 @@ import (

type filterLogProcessor struct {
skipExpr expr.BoolExpr[ottllog.TransformContext]
logger *zap.Logger
}

func newFilterLogsProcessor(set component.TelemetrySettings, cfg *Config) (*filterLogProcessor, error) {
flp := &filterLogProcessor{
logger: set.Logger,
}
if cfg.Logs.LogConditions != nil {
skipExpr, err := common.ParseLog(cfg.Logs.LogConditions, set)
if err != nil {
return nil, err
}

return &filterLogProcessor{skipExpr: skipExpr}, nil
flp.skipExpr = skipExpr
return flp, nil
}

cfgMatch := filterconfig.MatchConfig{}
Expand All @@ -57,8 +62,9 @@ func newFilterLogsProcessor(set component.TelemetrySettings, cfg *Config) (*filt
if err != nil {
return nil, fmt.Errorf("failed to build skip matcher: %w", err)
}
flp.skipExpr = skipExpr

return &filterLogProcessor{skipExpr: skipExpr}, nil
return flp, nil
}

func (flp *filterLogProcessor) processLogs(ctx context.Context, ld plog.Logs) (plog.Logs, error) {
Expand Down Expand Up @@ -87,6 +93,7 @@ func (flp *filterLogProcessor) processLogs(ctx context.Context, ld plog.Logs) (p
})

if errors != nil {
flp.logger.Error("failed processing logs", zap.Error(errors))
return ld, errors
}
if ld.ResourceLogs().Len() == 0 {
Expand Down
6 changes: 5 additions & 1 deletion processor/filterprocessor/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ type filterMetricProcessor struct {
skipResourceExpr expr.BoolExpr[ottlresource.TransformContext]
skipMetricExpr expr.BoolExpr[ottlmetric.TransformContext]
skipDataPointExpr expr.BoolExpr[ottldatapoint.TransformContext]
logger *zap.Logger
}

func newFilterMetricProcessor(set component.TelemetrySettings, cfg *Config) (*filterMetricProcessor, error) {
var err error
fsp := &filterMetricProcessor{}
fsp := &filterMetricProcessor{
logger: set.Logger,
}
if cfg.Metrics.MetricConditions != nil || cfg.Metrics.DataPointConditions != nil {
if cfg.Metrics.MetricConditions != nil {
fsp.skipMetricExpr, err = common.ParseMetric(cfg.Metrics.MetricConditions, set)
Expand Down Expand Up @@ -169,6 +172,7 @@ func (fmp *filterMetricProcessor) processMetrics(ctx context.Context, md pmetric
})

if errors != nil {
fmp.logger.Error("failed processing metrics", zap.Error(errors))
return md, errors
}
if md.ResourceMetrics().Len() == 0 {
Expand Down
6 changes: 5 additions & 1 deletion processor/filterprocessor/traces.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ import (
type filterSpanProcessor struct {
skipSpanExpr expr.BoolExpr[ottlspan.TransformContext]
skipSpanEventExpr expr.BoolExpr[ottlspanevent.TransformContext]
logger *zap.Logger
}

func newFilterSpansProcessor(set component.TelemetrySettings, cfg *Config) (*filterSpanProcessor, error) {
var err error
fsp := &filterSpanProcessor{}
fsp := &filterSpanProcessor{
logger: set.Logger,
}
if cfg.Traces.SpanConditions != nil || cfg.Traces.SpanEventConditions != nil {
if cfg.Traces.SpanConditions != nil {
fsp.skipSpanExpr, err = common.ParseSpan(cfg.Traces.SpanConditions, set)
Expand Down Expand Up @@ -117,6 +120,7 @@ func (fsp *filterSpanProcessor) processTraces(ctx context.Context, td ptrace.Tra
})

if errors != nil {
fsp.logger.Error("failed processing traces", zap.Error(errors))
return td, errors
}
if td.ResourceSpans().Len() == 0 {
Expand Down

0 comments on commit c9aa6e7

Please sign in to comment.