diff --git a/connector/countconnector/connector.go b/connector/countconnector/connector.go index 178f2a0e2704..2cf5280fecec 100644 --- a/connector/countconnector/connector.go +++ b/connector/countconnector/connector.go @@ -5,6 +5,7 @@ package countconnector // import "github.com/open-telemetry/opentelemetry-collec import ( "context" + "errors" "fmt" "go.opentelemetry.io/collector/component" @@ -13,7 +14,6 @@ import ( "go.opentelemetry.io/collector/pdata/plog" "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/pdata/ptrace" - "go.uber.org/multierr" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottldatapoint" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl/contexts/ottllog" @@ -43,7 +43,7 @@ func (c *count) Capabilities() consumer.Capabilities { } func (c *count) ConsumeTraces(ctx context.Context, td ptrace.Traces) error { - var errors error + var multiError error countMetrics := pmetric.NewMetrics() countMetrics.ResourceMetrics().EnsureCapacity(td.ResourceSpans().Len()) for i := 0; i < td.ResourceSpans().Len(); i++ { @@ -57,12 +57,12 @@ func (c *count) ConsumeTraces(ctx context.Context, td ptrace.Traces) error { for k := 0; k < scopeSpan.Spans().Len(); k++ { span := scopeSpan.Spans().At(k) sCtx := ottlspan.NewTransformContext(span, scopeSpan.Scope(), resourceSpan.Resource()) - errors = multierr.Append(errors, spansCounter.update(ctx, span.Attributes(), sCtx)) + multiError = errors.Join(multiError, spansCounter.update(ctx, span.Attributes(), sCtx)) for l := 0; l < span.Events().Len(); l++ { event := span.Events().At(l) eCtx := ottlspanevent.NewTransformContext(event, span, scopeSpan.Scope(), resourceSpan.Resource()) - errors = multierr.Append(errors, spanEventsCounter.update(ctx, event.Attributes(), eCtx)) + multiError = errors.Join(multiError, spanEventsCounter.update(ctx, event.Attributes(), eCtx)) } } } @@ -81,14 +81,14 @@ func (c *count) ConsumeTraces(ctx context.Context, td ptrace.Traces) error { spansCounter.appendMetricsTo(countScope.Metrics()) spanEventsCounter.appendMetricsTo(countScope.Metrics()) } - if errors != nil { - return errors + if multiError != nil { + return multiError } return c.metricsConsumer.ConsumeMetrics(ctx, countMetrics) } func (c *count) ConsumeMetrics(ctx context.Context, md pmetric.Metrics) error { - var errors error + var multiError error countMetrics := pmetric.NewMetrics() countMetrics.ResourceMetrics().EnsureCapacity(md.ResourceMetrics().Len()) for i := 0; i < md.ResourceMetrics().Len(); i++ { @@ -102,7 +102,7 @@ func (c *count) ConsumeMetrics(ctx context.Context, md pmetric.Metrics) error { for k := 0; k < scopeMetrics.Metrics().Len(); k++ { metric := scopeMetrics.Metrics().At(k) mCtx := ottlmetric.NewTransformContext(metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource()) - errors = multierr.Append(errors, metricsCounter.update(ctx, pcommon.NewMap(), mCtx)) + multiError = errors.Join(multiError, metricsCounter.update(ctx, pcommon.NewMap(), mCtx)) //exhaustive:enforce switch metric.Type() { @@ -110,34 +110,34 @@ func (c *count) ConsumeMetrics(ctx context.Context, md pmetric.Metrics) error { dps := metric.Gauge().DataPoints() for i := 0; i < dps.Len(); i++ { dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource()) - errors = multierr.Append(errors, dataPointsCounter.update(ctx, dps.At(i).Attributes(), dCtx)) + multiError = errors.Join(multiError, dataPointsCounter.update(ctx, dps.At(i).Attributes(), dCtx)) } case pmetric.MetricTypeSum: dps := metric.Sum().DataPoints() for i := 0; i < dps.Len(); i++ { dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource()) - errors = multierr.Append(errors, dataPointsCounter.update(ctx, dps.At(i).Attributes(), dCtx)) + multiError = errors.Join(multiError, dataPointsCounter.update(ctx, dps.At(i).Attributes(), dCtx)) } case pmetric.MetricTypeSummary: dps := metric.Summary().DataPoints() for i := 0; i < dps.Len(); i++ { dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource()) - errors = multierr.Append(errors, dataPointsCounter.update(ctx, dps.At(i).Attributes(), dCtx)) + multiError = errors.Join(multiError, dataPointsCounter.update(ctx, dps.At(i).Attributes(), dCtx)) } case pmetric.MetricTypeHistogram: dps := metric.Histogram().DataPoints() for i := 0; i < dps.Len(); i++ { dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource()) - errors = multierr.Append(errors, dataPointsCounter.update(ctx, dps.At(i).Attributes(), dCtx)) + multiError = errors.Join(multiError, dataPointsCounter.update(ctx, dps.At(i).Attributes(), dCtx)) } case pmetric.MetricTypeExponentialHistogram: dps := metric.ExponentialHistogram().DataPoints() for i := 0; i < dps.Len(); i++ { dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource()) - errors = multierr.Append(errors, dataPointsCounter.update(ctx, dps.At(i).Attributes(), dCtx)) + multiError = errors.Join(multiError, dataPointsCounter.update(ctx, dps.At(i).Attributes(), dCtx)) } case pmetric.MetricTypeEmpty: - errors = multierr.Append(errors, fmt.Errorf("metric %q: invalid metric type: %v", metric.Name(), metric.Type())) + multiError = errors.Join(multiError, fmt.Errorf("metric %q: invalid metric type: %v", metric.Name(), metric.Type())) } } } @@ -156,14 +156,14 @@ func (c *count) ConsumeMetrics(ctx context.Context, md pmetric.Metrics) error { metricsCounter.appendMetricsTo(countScope.Metrics()) dataPointsCounter.appendMetricsTo(countScope.Metrics()) } - if errors != nil { - return errors + if multiError != nil { + return multiError } return c.metricsConsumer.ConsumeMetrics(ctx, countMetrics) } func (c *count) ConsumeLogs(ctx context.Context, ld plog.Logs) error { - var errors error + var multiError error countMetrics := pmetric.NewMetrics() countMetrics.ResourceMetrics().EnsureCapacity(ld.ResourceLogs().Len()) for i := 0; i < ld.ResourceLogs().Len(); i++ { @@ -177,7 +177,7 @@ func (c *count) ConsumeLogs(ctx context.Context, ld plog.Logs) error { logRecord := scopeLogs.LogRecords().At(k) lCtx := ottllog.NewTransformContext(logRecord, scopeLogs.Scope(), resourceLog.Resource()) - errors = multierr.Append(errors, counter.update(ctx, logRecord.Attributes(), lCtx)) + multiError = errors.Join(multiError, counter.update(ctx, logRecord.Attributes(), lCtx)) } } @@ -194,8 +194,8 @@ func (c *count) ConsumeLogs(ctx context.Context, ld plog.Logs) error { counter.appendMetricsTo(countScope.Metrics()) } - if errors != nil { - return errors + if multiError != nil { + return multiError } return c.metricsConsumer.ConsumeMetrics(ctx, countMetrics) } diff --git a/connector/countconnector/counter.go b/connector/countconnector/counter.go index 77cfe9f9bab7..52afc6db23b9 100644 --- a/connector/countconnector/counter.go +++ b/connector/countconnector/counter.go @@ -5,11 +5,11 @@ package countconnector // import "github.com/open-telemetry/opentelemetry-collec import ( "context" + "errors" "time" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/pmetric" - "go.uber.org/multierr" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil" ) @@ -36,7 +36,7 @@ type attrCounter struct { } func (c *counter[K]) update(ctx context.Context, attrs pcommon.Map, tCtx K) error { - var errors error + var multiError error for name, md := range c.metricDefs { countAttrs := pcommon.NewMap() for _, attr := range md.attrs { @@ -54,17 +54,17 @@ func (c *counter[K]) update(ctx context.Context, attrs pcommon.Map, tCtx K) erro // No conditions, so match all. if md.condition == nil { - errors = multierr.Append(errors, c.increment(name, countAttrs)) + multiError = errors.Join(multiError, c.increment(name, countAttrs)) continue } if match, err := md.condition.Eval(ctx, tCtx); err != nil { - errors = multierr.Append(errors, err) + multiError = errors.Join(multiError, err) } else if match { - errors = multierr.Append(errors, c.increment(name, countAttrs)) + multiError = errors.Join(multiError, c.increment(name, countAttrs)) } } - return errors + return multiError } func (c *counter[K]) increment(metricName string, attrs pcommon.Map) error { diff --git a/connector/countconnector/go.mod b/connector/countconnector/go.mod index faf3fa9a4ad9..3d46c6b6926f 100644 --- a/connector/countconnector/go.mod +++ b/connector/countconnector/go.mod @@ -14,7 +14,6 @@ require ( go.opentelemetry.io/collector/connector v0.82.0 go.opentelemetry.io/collector/consumer v0.82.0 go.opentelemetry.io/collector/pdata v1.0.0-rcv0014 - go.uber.org/multierr v1.11.0 go.uber.org/zap v1.25.0 ) @@ -43,6 +42,7 @@ require ( go.opentelemetry.io/otel v1.16.0 // indirect go.opentelemetry.io/otel/metric v1.16.0 // indirect go.opentelemetry.io/otel/trace v1.16.0 // indirect + go.uber.org/multierr v1.11.0 // indirect golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea // indirect golang.org/x/net v0.14.0 // indirect golang.org/x/sys v0.11.0 // indirect diff --git a/connector/routingconnector/go.mod b/connector/routingconnector/go.mod index 38e366909666..e8c9a85dc906 100644 --- a/connector/routingconnector/go.mod +++ b/connector/routingconnector/go.mod @@ -10,7 +10,6 @@ require ( go.opentelemetry.io/collector/connector v0.82.0 go.opentelemetry.io/collector/consumer v0.82.0 go.opentelemetry.io/collector/pdata v1.0.0-rcv0014 - go.uber.org/multierr v1.11.0 go.uber.org/zap v1.25.0 ) @@ -38,6 +37,7 @@ require ( go.opentelemetry.io/otel v1.16.0 // indirect go.opentelemetry.io/otel/metric v1.16.0 // indirect go.opentelemetry.io/otel/trace v1.16.0 // indirect + go.uber.org/multierr v1.11.0 // indirect golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect golang.org/x/net v0.14.0 // indirect golang.org/x/sys v0.11.0 // indirect diff --git a/connector/routingconnector/logs.go b/connector/routingconnector/logs.go index e60281350246..e1db011eefda 100644 --- a/connector/routingconnector/logs.go +++ b/connector/routingconnector/logs.go @@ -5,12 +5,12 @@ package routingconnector // import "github.com/open-telemetry/opentelemetry-coll import ( "context" + "errors" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/connector" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/pdata/plog" - "go.uber.org/multierr" "go.uber.org/zap" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" @@ -94,7 +94,7 @@ func (c *logsConnector) ConsumeLogs(ctx context.Context, ld plog.Logs) error { } } for consumer, group := range groups { - errs = multierr.Append(errs, consumer.ConsumeLogs(ctx, group)) + errs = errors.Join(errs, consumer.ConsumeLogs(ctx, group)) } return errs } diff --git a/connector/routingconnector/metrics.go b/connector/routingconnector/metrics.go index d3c79ccb5fbd..c0c7fdad5e7e 100644 --- a/connector/routingconnector/metrics.go +++ b/connector/routingconnector/metrics.go @@ -5,12 +5,12 @@ package routingconnector // import "github.com/open-telemetry/opentelemetry-coll import ( "context" + "errors" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/connector" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/pdata/pmetric" - "go.uber.org/multierr" "go.uber.org/zap" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" @@ -95,7 +95,7 @@ func (c *metricsConnector) ConsumeMetrics(ctx context.Context, md pmetric.Metric } for consumer, group := range groups { - errs = multierr.Append(errs, consumer.ConsumeMetrics(ctx, group)) + errs = errors.Join(errs, consumer.ConsumeMetrics(ctx, group)) } return errs } diff --git a/connector/routingconnector/traces.go b/connector/routingconnector/traces.go index 5517cde8ebab..99397d4482ab 100644 --- a/connector/routingconnector/traces.go +++ b/connector/routingconnector/traces.go @@ -5,12 +5,12 @@ package routingconnector // import "github.com/open-telemetry/opentelemetry-coll import ( "context" + "errors" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/connector" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/pdata/ptrace" - "go.uber.org/multierr" "go.uber.org/zap" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/ottl" @@ -94,7 +94,7 @@ func (c *tracesConnector) ConsumeTraces(ctx context.Context, t ptrace.Traces) er } for consumer, group := range groups { - errs = multierr.Append(errs, consumer.ConsumeTraces(ctx, group)) + errs = errors.Join(errs, consumer.ConsumeTraces(ctx, group)) } return errs } diff --git a/connector/spanmetricsconnector/config_test.go b/connector/spanmetricsconnector/config_test.go index 77775c87c00f..31505a2de16a 100644 --- a/connector/spanmetricsconnector/config_test.go +++ b/connector/spanmetricsconnector/config_test.go @@ -4,6 +4,7 @@ package spanmetricsconnector import ( + "errors" "path/filepath" "testing" "time" @@ -13,7 +14,6 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/confmap/confmaptest" "go.opentelemetry.io/collector/pdata/pmetric" - "go.uber.org/multierr" "github.com/open-telemetry/opentelemetry-collector-contrib/connector/spanmetricsconnector/internal/metadata" "github.com/open-telemetry/opentelemetry-collector-contrib/connector/spanmetricsconnector/internal/metrics" @@ -107,7 +107,7 @@ func TestLoadConfig(t *testing.T) { err = component.UnmarshalConfig(sub, cfg) if tt.expected == nil { - err = multierr.Append(err, component.ValidateConfig(cfg)) + err = errors.Join(err, component.ValidateConfig(cfg)) assert.ErrorContains(t, err, tt.errorMessage) return } diff --git a/connector/spanmetricsconnector/go.mod b/connector/spanmetricsconnector/go.mod index ee5ae96d4f4f..4cb34dae9bef 100644 --- a/connector/spanmetricsconnector/go.mod +++ b/connector/spanmetricsconnector/go.mod @@ -15,7 +15,6 @@ require ( go.opentelemetry.io/collector/consumer v0.82.0 go.opentelemetry.io/collector/pdata v1.0.0-rcv0014 go.opentelemetry.io/collector/semconv v0.82.0 - go.uber.org/multierr v1.11.0 go.uber.org/zap v1.25.0 google.golang.org/grpc v1.57.0 ) @@ -42,6 +41,7 @@ require ( go.opentelemetry.io/otel/metric v1.16.0 // indirect go.opentelemetry.io/otel/trace v1.16.0 // indirect go.uber.org/goleak v1.2.1 // indirect + go.uber.org/multierr v1.11.0 // indirect golang.org/x/net v0.14.0 // indirect golang.org/x/sys v0.11.0 // indirect golang.org/x/text v0.12.0 // indirect