Skip to content

Commit

Permalink
use errors.Join instead of go.uber.org/multierr
Browse files Browse the repository at this point in the history
  • Loading branch information
shivanshuraj1333 committed Aug 14, 2023
1 parent 81242fa commit 5e26371
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 30 deletions.
13 changes: 6 additions & 7 deletions obsreport/obsreport_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/trace"
"go.uber.org/multierr"
"go.uber.org/zap"

"go.opentelemetry.io/collector/component"
Expand Down Expand Up @@ -89,37 +88,37 @@ func (exp *Exporter) createOtelMetrics(cfg ExporterSettings) error {
obsmetrics.ExporterPrefix+obsmetrics.SentSpansKey,
metric.WithDescription("Number of spans successfully sent to destination."),
metric.WithUnit("1"))
errors = multierr.Append(errors, err)
errors = errors.Join(errors, err)

Check failure on line 91 in obsreport/obsreport_exporter.go

View workflow job for this annotation

GitHub Actions / Integration test

errors.Join undefined (type error has no field or method Join)

Check failure on line 91 in obsreport/obsreport_exporter.go

View workflow job for this annotation

GitHub Actions / govulncheck

errors.Join undefined (type error has no field or method Join)

Check failure on line 91 in obsreport/obsreport_exporter.go

View workflow job for this annotation

GitHub Actions / test-coverage

errors.Join undefined (type error has no field or method Join)

Check failure on line 91 in obsreport/obsreport_exporter.go

View workflow job for this annotation

GitHub Actions / contrib_tests

errors.Join undefined (type error has no field or method Join)

exp.failedToSendSpans, err = meter.Int64Counter(
obsmetrics.ExporterPrefix+obsmetrics.FailedToSendSpansKey,
metric.WithDescription("Number of spans in failed attempts to send to destination."),
metric.WithUnit("1"))
errors = multierr.Append(errors, err)
errors = errors.Join(errors, err)

Check failure on line 97 in obsreport/obsreport_exporter.go

View workflow job for this annotation

GitHub Actions / Integration test

errors.Join undefined (type error has no field or method Join)

Check failure on line 97 in obsreport/obsreport_exporter.go

View workflow job for this annotation

GitHub Actions / govulncheck

errors.Join undefined (type error has no field or method Join)

Check failure on line 97 in obsreport/obsreport_exporter.go

View workflow job for this annotation

GitHub Actions / test-coverage

errors.Join undefined (type error has no field or method Join)

Check failure on line 97 in obsreport/obsreport_exporter.go

View workflow job for this annotation

GitHub Actions / contrib_tests

errors.Join undefined (type error has no field or method Join)

exp.sentMetricPoints, err = meter.Int64Counter(
obsmetrics.ExporterPrefix+obsmetrics.SentMetricPointsKey,
metric.WithDescription("Number of metric points successfully sent to destination."),
metric.WithUnit("1"))
errors = multierr.Append(errors, err)
errors = errors.Join(errors, err)

Check failure on line 103 in obsreport/obsreport_exporter.go

View workflow job for this annotation

GitHub Actions / Integration test

errors.Join undefined (type error has no field or method Join)

Check failure on line 103 in obsreport/obsreport_exporter.go

View workflow job for this annotation

GitHub Actions / govulncheck

errors.Join undefined (type error has no field or method Join)

Check failure on line 103 in obsreport/obsreport_exporter.go

View workflow job for this annotation

GitHub Actions / test-coverage

errors.Join undefined (type error has no field or method Join)

Check failure on line 103 in obsreport/obsreport_exporter.go

View workflow job for this annotation

GitHub Actions / contrib_tests

errors.Join undefined (type error has no field or method Join)

exp.failedToSendMetricPoints, err = meter.Int64Counter(
obsmetrics.ExporterPrefix+obsmetrics.FailedToSendMetricPointsKey,
metric.WithDescription("Number of metric points in failed attempts to send to destination."),
metric.WithUnit("1"))
errors = multierr.Append(errors, err)
errors = errors.Join(errors, err)

Check failure on line 109 in obsreport/obsreport_exporter.go

View workflow job for this annotation

GitHub Actions / Integration test

errors.Join undefined (type error has no field or method Join)

Check failure on line 109 in obsreport/obsreport_exporter.go

View workflow job for this annotation

GitHub Actions / govulncheck

errors.Join undefined (type error has no field or method Join)

Check failure on line 109 in obsreport/obsreport_exporter.go

View workflow job for this annotation

GitHub Actions / test-coverage

errors.Join undefined (type error has no field or method Join)

Check failure on line 109 in obsreport/obsreport_exporter.go

View workflow job for this annotation

GitHub Actions / contrib_tests

errors.Join undefined (type error has no field or method Join)

exp.sentLogRecords, err = meter.Int64Counter(
obsmetrics.ExporterPrefix+obsmetrics.SentLogRecordsKey,
metric.WithDescription("Number of log record successfully sent to destination."),
metric.WithUnit("1"))
errors = multierr.Append(errors, err)
errors = errors.Join(errors, err)

Check failure on line 115 in obsreport/obsreport_exporter.go

View workflow job for this annotation

GitHub Actions / Integration test

errors.Join undefined (type error has no field or method Join)

Check failure on line 115 in obsreport/obsreport_exporter.go

View workflow job for this annotation

GitHub Actions / govulncheck

errors.Join undefined (type error has no field or method Join)

Check failure on line 115 in obsreport/obsreport_exporter.go

View workflow job for this annotation

GitHub Actions / test-coverage

errors.Join undefined (type error has no field or method Join)

Check failure on line 115 in obsreport/obsreport_exporter.go

View workflow job for this annotation

GitHub Actions / contrib_tests

errors.Join undefined (type error has no field or method Join)

exp.failedToSendLogRecords, err = meter.Int64Counter(
obsmetrics.ExporterPrefix+obsmetrics.FailedToSendLogRecordsKey,
metric.WithDescription("Number of log records in failed attempts to send to destination."),
metric.WithUnit("1"))
errors = multierr.Append(errors, err)
errors = errors.Join(errors, err)

Check failure on line 121 in obsreport/obsreport_exporter.go

View workflow job for this annotation

GitHub Actions / Integration test

errors.Join undefined (type error has no field or method Join)

Check failure on line 121 in obsreport/obsreport_exporter.go

View workflow job for this annotation

GitHub Actions / govulncheck

errors.Join undefined (type error has no field or method Join)

Check failure on line 121 in obsreport/obsreport_exporter.go

View workflow job for this annotation

GitHub Actions / test-coverage

errors.Join undefined (type error has no field or method Join)

Check failure on line 121 in obsreport/obsreport_exporter.go

View workflow job for this annotation

GitHub Actions / contrib_tests

errors.Join undefined (type error has no field or method Join)

return errors
}
Expand Down
19 changes: 9 additions & 10 deletions obsreport/obsreport_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"go.opencensus.io/tag"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.uber.org/multierr"
"go.uber.org/zap"

"go.opentelemetry.io/collector/component"
Expand Down Expand Up @@ -102,63 +101,63 @@ func (por *Processor) createOtelMetrics(cfg ProcessorSettings) error {
metric.WithDescription("Number of spans successfully pushed into the next component in the pipeline."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)
errors = errors.Join(errors, err)

Check failure on line 104 in obsreport/obsreport_processor.go

View workflow job for this annotation

GitHub Actions / Integration test

errors.Join undefined (type error has no field or method Join)

Check failure on line 104 in obsreport/obsreport_processor.go

View workflow job for this annotation

GitHub Actions / govulncheck

errors.Join undefined (type error has no field or method Join)

Check failure on line 104 in obsreport/obsreport_processor.go

View workflow job for this annotation

GitHub Actions / test-coverage

errors.Join undefined (type error has no field or method Join)

Check failure on line 104 in obsreport/obsreport_processor.go

View workflow job for this annotation

GitHub Actions / contrib_tests

errors.Join undefined (type error has no field or method Join)

por.refusedSpansCounter, err = meter.Int64Counter(
obsmetrics.ProcessorPrefix+obsmetrics.RefusedSpansKey,
metric.WithDescription("Number of spans that were rejected by the next component in the pipeline."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)
errors = errors.Join(errors, err)

Check failure on line 111 in obsreport/obsreport_processor.go

View workflow job for this annotation

GitHub Actions / Integration test

errors.Join undefined (type error has no field or method Join)

Check failure on line 111 in obsreport/obsreport_processor.go

View workflow job for this annotation

GitHub Actions / govulncheck

errors.Join undefined (type error has no field or method Join)

Check failure on line 111 in obsreport/obsreport_processor.go

View workflow job for this annotation

GitHub Actions / test-coverage

errors.Join undefined (type error has no field or method Join)

Check failure on line 111 in obsreport/obsreport_processor.go

View workflow job for this annotation

GitHub Actions / contrib_tests

errors.Join undefined (type error has no field or method Join)

por.droppedSpansCounter, err = meter.Int64Counter(
obsmetrics.ProcessorPrefix+obsmetrics.DroppedSpansKey,
metric.WithDescription("Number of spans that were dropped."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)
errors = errors.Join(errors, err)

Check failure on line 118 in obsreport/obsreport_processor.go

View workflow job for this annotation

GitHub Actions / Integration test

errors.Join undefined (type error has no field or method Join)

Check failure on line 118 in obsreport/obsreport_processor.go

View workflow job for this annotation

GitHub Actions / govulncheck

errors.Join undefined (type error has no field or method Join)

Check failure on line 118 in obsreport/obsreport_processor.go

View workflow job for this annotation

GitHub Actions / test-coverage

errors.Join undefined (type error has no field or method Join)

Check failure on line 118 in obsreport/obsreport_processor.go

View workflow job for this annotation

GitHub Actions / contrib_tests

errors.Join undefined (type error has no field or method Join)

por.acceptedMetricPointsCounter, err = meter.Int64Counter(
obsmetrics.ProcessorPrefix+obsmetrics.AcceptedMetricPointsKey,
metric.WithDescription("Number of metric points successfully pushed into the next component in the pipeline."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)
errors = errors.Join(errors, err)

Check failure on line 125 in obsreport/obsreport_processor.go

View workflow job for this annotation

GitHub Actions / Integration test

errors.Join undefined (type error has no field or method Join)

Check failure on line 125 in obsreport/obsreport_processor.go

View workflow job for this annotation

GitHub Actions / govulncheck

errors.Join undefined (type error has no field or method Join)

Check failure on line 125 in obsreport/obsreport_processor.go

View workflow job for this annotation

GitHub Actions / test-coverage

errors.Join undefined (type error has no field or method Join)

Check failure on line 125 in obsreport/obsreport_processor.go

View workflow job for this annotation

GitHub Actions / contrib_tests

errors.Join undefined (type error has no field or method Join)

por.refusedMetricPointsCounter, err = meter.Int64Counter(
obsmetrics.ProcessorPrefix+obsmetrics.RefusedMetricPointsKey,
metric.WithDescription("Number of metric points that were rejected by the next component in the pipeline."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)
errors = errors.Join(errors, err)

por.droppedMetricPointsCounter, err = meter.Int64Counter(
obsmetrics.ProcessorPrefix+obsmetrics.DroppedMetricPointsKey,
metric.WithDescription("Number of metric points that were dropped."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)
errors = errors.Join(errors, err)

por.acceptedLogRecordsCounter, err = meter.Int64Counter(
obsmetrics.ProcessorPrefix+obsmetrics.AcceptedLogRecordsKey,
metric.WithDescription("Number of log records successfully pushed into the next component in the pipeline."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)
errors = errors.Join(errors, err)

por.refusedLogRecordsCounter, err = meter.Int64Counter(
obsmetrics.ProcessorPrefix+obsmetrics.RefusedLogRecordsKey,
metric.WithDescription("Number of log records that were rejected by the next component in the pipeline."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)
errors = errors.Join(errors, err)

por.droppedLogRecordsCounter, err = meter.Int64Counter(
obsmetrics.ProcessorPrefix+obsmetrics.DroppedLogRecordsKey,
metric.WithDescription("Number of log records that were dropped."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)
errors = errors.Join(errors, err)

return errors
}
Expand Down
13 changes: 6 additions & 7 deletions obsreport/obsreport_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/trace"
"go.uber.org/multierr"
"go.uber.org/zap"

"go.opentelemetry.io/collector/component"
Expand Down Expand Up @@ -107,42 +106,42 @@ func (rec *Receiver) createOtelMetrics() error {
metric.WithDescription("Number of spans successfully pushed into the pipeline."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)
errors = errors.Join(errors, err)

rec.refusedSpansCounter, err = rec.meter.Int64Counter(
obsmetrics.ReceiverPrefix+obsmetrics.RefusedSpansKey,
metric.WithDescription("Number of spans that could not be pushed into the pipeline."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)
errors = errors.Join(errors, err)

rec.acceptedMetricPointsCounter, err = rec.meter.Int64Counter(
obsmetrics.ReceiverPrefix+obsmetrics.AcceptedMetricPointsKey,
metric.WithDescription("Number of metric points successfully pushed into the pipeline."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)
errors = errors.Join(errors, err)

rec.refusedMetricPointsCounter, err = rec.meter.Int64Counter(
obsmetrics.ReceiverPrefix+obsmetrics.RefusedMetricPointsKey,
metric.WithDescription("Number of metric points that could not be pushed into the pipeline."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)
errors = errors.Join(errors, err)

rec.acceptedLogRecordsCounter, err = rec.meter.Int64Counter(
obsmetrics.ReceiverPrefix+obsmetrics.AcceptedLogRecordsKey,
metric.WithDescription("Number of log records successfully pushed into the pipeline."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)
errors = errors.Join(errors, err)

rec.refusedLogRecordsCounter, err = rec.meter.Int64Counter(
obsmetrics.ReceiverPrefix+obsmetrics.RefusedLogRecordsKey,
metric.WithDescription("Number of log records that could not be pushed into the pipeline."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)
errors = errors.Join(errors, err)

return errors
}
Expand Down
5 changes: 2 additions & 3 deletions obsreport/obsreport_scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"go.opentelemetry.io/otel/trace"
"go.uber.org/multierr"
"go.uber.org/zap"

"go.opentelemetry.io/collector/component"
Expand Down Expand Up @@ -94,14 +93,14 @@ func (s *Scraper) createOtelMetrics(cfg ScraperSettings) error {
metric.WithDescription("Number of metric points successfully scraped."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)
errors = errors.Join(errors, err)

s.erroredMetricsPoints, err = meter.Int64Counter(
obsmetrics.ScraperPrefix+obsmetrics.ErroredMetricPointsKey,
metric.WithDescription("Number of metric points that were unable to be scraped."),
metric.WithUnit("1"),
)
errors = multierr.Append(errors, err)
errors = errors.Join(errors, err)

return errors
}
Expand Down
6 changes: 3 additions & 3 deletions obsreport/obsreporttest/obsreporttest.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package obsreporttest // import "go.opentelemetry.io/collector/obsreport/obsrepo

import (
"context"
"errors"

ocprom "contrib.go.opencensus.io/exporter/prometheus"
"github.com/prometheus/client_golang/prometheus"
Expand All @@ -14,7 +15,6 @@ import (
"go.opentelemetry.io/otel/sdk/resource"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/sdk/trace/tracetest"
"go.uber.org/multierr"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
Expand Down Expand Up @@ -136,9 +136,9 @@ func (tts *TestTelemetry) Shutdown(ctx context.Context) error {
view.Unregister(tts.views...)
view.UnregisterExporter(tts.ocExporter)
var errs error
errs = multierr.Append(errs, tts.SpanRecorder.Shutdown(ctx))
errs = errors.Join(errs, tts.SpanRecorder.Shutdown(ctx))
if tts.meterProvider != nil {
errs = multierr.Append(errs, tts.meterProvider.Shutdown(ctx))
errs = errors.Join(errs, tts.meterProvider.Shutdown(ctx))
}
return errs
}
Expand Down

0 comments on commit 5e26371

Please sign in to comment.