diff --git a/.golangci.yml b/.golangci.yml index c6ce728bd..6d9c8b649 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -11,6 +11,7 @@ linters: enable: - depguard - errcheck + - errorlint - godot - gofumpt - goimports diff --git a/baggage/baggage.go b/baggage/baggage.go index 275b09258..c40c896cc 100644 --- a/baggage/baggage.go +++ b/baggage/baggage.go @@ -302,7 +302,7 @@ func parseMember(member string) (Member, error) { // Decode a percent-encoded value. value, err := url.PathUnescape(val) if err != nil { - return newInvalidMember(), fmt.Errorf("%w: %v", errInvalidValue, err) + return newInvalidMember(), fmt.Errorf("%w: %w", errInvalidValue, err) } return Member{key: key, value: value, properties: props, hasData: true}, nil } diff --git a/exporters/otlp/otlplog/otlploggrpc/config.go b/exporters/otlp/otlplog/otlploggrpc/config.go index 37220acab..52e8c256c 100644 --- a/exporters/otlp/otlplog/otlploggrpc/config.go +++ b/exporters/otlp/otlplog/otlploggrpc/config.go @@ -532,7 +532,7 @@ func loadCertificates(certPath, keyPath string) ([]tls.Certificate, error) { func compressorToCompression(compressor string) Compression { c, err := convCompression(compressor) if err != nil { - otel.Handle(fmt.Errorf("%s, using no compression as default", err)) + otel.Handle(fmt.Errorf("%w, using no compression as default", err)) return NoCompression } diff --git a/exporters/otlp/otlplog/otlploggrpc/internal/retry/retry.go b/exporters/otlp/otlplog/otlploggrpc/internal/retry/retry.go index 7e59d5106..f2da12382 100644 --- a/exporters/otlp/otlplog/otlploggrpc/internal/retry/retry.go +++ b/exporters/otlp/otlplog/otlploggrpc/internal/retry/retry.go @@ -112,7 +112,7 @@ func (c Config) RequestFunc(evaluate EvaluateFunc) RequestFunc { } if ctxErr := waitFunc(ctx, delay); ctxErr != nil { - return fmt.Errorf("%w: %s", ctxErr, err) + return fmt.Errorf("%w: %w", ctxErr, err) } } } diff --git a/exporters/otlp/otlplog/otlploghttp/client.go b/exporters/otlp/otlplog/otlploghttp/client.go index 09a950838..04d46d42e 100644 --- a/exporters/otlp/otlplog/otlploghttp/client.go +++ b/exporters/otlp/otlplog/otlploghttp/client.go @@ -291,7 +291,10 @@ func evaluate(err error) (bool, time.Duration) { return false, 0 } - rErr, ok := err.(retryableError) + // Do not use errors.As here, this should only be flattened one layer. If + // there are several chained errors, all the errors above it will be + // discarded if errors.As is used instead. + rErr, ok := err.(retryableError) //nolint:errorlint if !ok { return false, 0 } diff --git a/exporters/otlp/otlplog/otlploghttp/internal/retry/retry.go b/exporters/otlp/otlplog/otlploghttp/internal/retry/retry.go index dcd31893c..661576ce2 100644 --- a/exporters/otlp/otlplog/otlploghttp/internal/retry/retry.go +++ b/exporters/otlp/otlplog/otlploghttp/internal/retry/retry.go @@ -112,7 +112,7 @@ func (c Config) RequestFunc(evaluate EvaluateFunc) RequestFunc { } if ctxErr := waitFunc(ctx, delay); ctxErr != nil { - return fmt.Errorf("%w: %s", ctxErr, err) + return fmt.Errorf("%w: %w", ctxErr, err) } } } diff --git a/exporters/otlp/otlpmetric/otlpmetricgrpc/exporter.go b/exporters/otlp/otlpmetric/otlpmetricgrpc/exporter.go index 462dc8a7a..98afc0b1e 100644 --- a/exporters/otlp/otlpmetric/otlpmetricgrpc/exporter.go +++ b/exporters/otlp/otlpmetric/otlpmetricgrpc/exporter.go @@ -79,7 +79,7 @@ func (e *Exporter) Export(ctx context.Context, rm *metricdata.ResourceMetrics) e return fmt.Errorf("failed to upload metrics: %w", upErr) } // Merge the two errors. - return fmt.Errorf("failed to upload incomplete metrics (%s): %w", err, upErr) + return fmt.Errorf("failed to upload incomplete metrics (%w): %w", err, upErr) } return err } diff --git a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/retry/retry.go b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/retry/retry.go index b552333db..cc3a77055 100644 --- a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/retry/retry.go +++ b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/retry/retry.go @@ -112,7 +112,7 @@ func (c Config) RequestFunc(evaluate EvaluateFunc) RequestFunc { } if ctxErr := waitFunc(ctx, delay); ctxErr != nil { - return fmt.Errorf("%w: %s", ctxErr, err) + return fmt.Errorf("%w: %w", ctxErr, err) } } } diff --git a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/error.go b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/error.go index fb009ba21..d31652b4d 100644 --- a/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/error.go +++ b/exporters/otlp/otlpmetric/otlpmetricgrpc/internal/transform/error.go @@ -58,7 +58,7 @@ func (e *multiErr) append(err error) { // Do not use errors.As here, this should only be flattened one layer. If // there is a *multiErr several steps down the chain, all the errors above // it will be discarded if errors.As is used instead. - switch other := err.(type) { + switch other := err.(type) { //nolint:errorlint case *multiErr: // Flatten err errors into e. e.errs = append(e.errs, other.errs...) diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/client.go b/exporters/otlp/otlpmetric/otlpmetrichttp/client.go index eeb39339d..205594b7f 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/client.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/client.go @@ -294,7 +294,10 @@ func evaluate(err error) (bool, time.Duration) { return false, 0 } - rErr, ok := err.(retryableError) + // Do not use errors.As here, this should only be flattened one layer. If + // there are several chained errors, all the errors above it will be + // discarded if errors.As is used instead. + rErr, ok := err.(retryableError) //nolint:errorlint if !ok { return false, 0 } diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/exporter.go b/exporters/otlp/otlpmetric/otlpmetrichttp/exporter.go index 442d80961..701deb6d3 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/exporter.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/exporter.go @@ -79,7 +79,7 @@ func (e *Exporter) Export(ctx context.Context, rm *metricdata.ResourceMetrics) e return fmt.Errorf("failed to upload metrics: %w", upErr) } // Merge the two errors. - return fmt.Errorf("failed to upload incomplete metrics (%s): %w", err, upErr) + return fmt.Errorf("failed to upload incomplete metrics (%w): %w", err, upErr) } return err } diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/retry/retry.go b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/retry/retry.go index ea4cff080..a9a08ffe6 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/retry/retry.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/retry/retry.go @@ -112,7 +112,7 @@ func (c Config) RequestFunc(evaluate EvaluateFunc) RequestFunc { } if ctxErr := waitFunc(ctx, delay); ctxErr != nil { - return fmt.Errorf("%w: %s", ctxErr, err) + return fmt.Errorf("%w: %w", ctxErr, err) } } } diff --git a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/error.go b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/error.go index 60d0d1f72..bb6d21f0b 100644 --- a/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/error.go +++ b/exporters/otlp/otlpmetric/otlpmetrichttp/internal/transform/error.go @@ -58,7 +58,7 @@ func (e *multiErr) append(err error) { // Do not use errors.As here, this should only be flattened one layer. If // there is a *multiErr several steps down the chain, all the errors above // it will be discarded if errors.As is used instead. - switch other := err.(type) { + switch other := err.(type) { //nolint:errorlint case *multiErr: // Flatten err errors into e. e.errs = append(e.errs, other.errs...) diff --git a/exporters/otlp/otlptrace/otlptracegrpc/internal/retry/retry.go b/exporters/otlp/otlptrace/otlptracegrpc/internal/retry/retry.go index 4f2113ae2..1c5450ab6 100644 --- a/exporters/otlp/otlptrace/otlptracegrpc/internal/retry/retry.go +++ b/exporters/otlp/otlptrace/otlptracegrpc/internal/retry/retry.go @@ -112,7 +112,7 @@ func (c Config) RequestFunc(evaluate EvaluateFunc) RequestFunc { } if ctxErr := waitFunc(ctx, delay); ctxErr != nil { - return fmt.Errorf("%w: %s", ctxErr, err) + return fmt.Errorf("%w: %w", ctxErr, err) } } } diff --git a/exporters/otlp/otlptrace/otlptracehttp/client.go b/exporters/otlp/otlptrace/otlptracehttp/client.go index 1c487a096..1e59ff239 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/client.go +++ b/exporters/otlp/otlptrace/otlptracehttp/client.go @@ -316,7 +316,10 @@ func evaluate(err error) (bool, time.Duration) { return false, 0 } - rErr, ok := err.(retryableError) + // Do not use errors.As here, this should only be flattened one layer. If + // there are several chained errors, all the errors above it will be + // discarded if errors.As is used instead. + rErr, ok := err.(retryableError) //nolint:errorlint if !ok { return false, 0 } diff --git a/exporters/otlp/otlptrace/otlptracehttp/internal/retry/retry.go b/exporters/otlp/otlptrace/otlptracehttp/internal/retry/retry.go index e3e647783..86c4819f4 100644 --- a/exporters/otlp/otlptrace/otlptracehttp/internal/retry/retry.go +++ b/exporters/otlp/otlptrace/otlptracehttp/internal/retry/retry.go @@ -112,7 +112,7 @@ func (c Config) RequestFunc(evaluate EvaluateFunc) RequestFunc { } if ctxErr := waitFunc(ctx, delay); ctxErr != nil { - return fmt.Errorf("%w: %s", ctxErr, err) + return fmt.Errorf("%w: %w", ctxErr, err) } } } diff --git a/exporters/prometheus/exporter.go b/exporters/prometheus/exporter.go index 1a8e28542..d2e387e60 100644 --- a/exporters/prometheus/exporter.go +++ b/exporters/prometheus/exporter.go @@ -192,7 +192,7 @@ func (c *collector) Collect(ch chan<- prometheus.Metric) { if !c.disableScopeInfo { scopeInfo, err := c.scopeInfo(scopeMetrics.Scope) - if err == errScopeInvalid { + if errors.Is(err, errScopeInvalid) { // Do not report the same error multiple times. continue } diff --git a/exporters/zipkin/zipkin.go b/exporters/zipkin/zipkin.go index 1b07c8c25..2b81fa92e 100644 --- a/exporters/zipkin/zipkin.go +++ b/exporters/zipkin/zipkin.go @@ -86,7 +86,7 @@ func New(collectorURL string, opts ...Option) (*Exporter, error) { } u, err := url.Parse(collectorURL) if err != nil { - return nil, fmt.Errorf("invalid collector URL %q: %v", collectorURL, err) + return nil, fmt.Errorf("invalid collector URL %q: %w", collectorURL, err) } if u.Scheme == "" || u.Host == "" { return nil, fmt.Errorf("invalid collector URL %q: no scheme or host", collectorURL) diff --git a/internal/shared/otlp/otlpmetric/transform/error.go.tmpl b/internal/shared/otlp/otlpmetric/transform/error.go.tmpl index 69f0dd5d7..4ba997474 100644 --- a/internal/shared/otlp/otlpmetric/transform/error.go.tmpl +++ b/internal/shared/otlp/otlpmetric/transform/error.go.tmpl @@ -58,7 +58,7 @@ func (e *multiErr) append(err error) { // Do not use errors.As here, this should only be flattened one layer. If // there is a *multiErr several steps down the chain, all the errors above // it will be discarded if errors.As is used instead. - switch other := err.(type) { + switch other := err.(type) { //nolint:errorlint case *multiErr: // Flatten err errors into e. e.errs = append(e.errs, other.errs...) diff --git a/internal/shared/otlp/retry/retry.go.tmpl b/internal/shared/otlp/retry/retry.go.tmpl index 02d3c2147..7cb77391e 100644 --- a/internal/shared/otlp/retry/retry.go.tmpl +++ b/internal/shared/otlp/retry/retry.go.tmpl @@ -112,7 +112,7 @@ func (c Config) RequestFunc(evaluate EvaluateFunc) RequestFunc { } if ctxErr := waitFunc(ctx, delay); ctxErr != nil { - return fmt.Errorf("%w: %s", ctxErr, err) + return fmt.Errorf("%w: %w", ctxErr, err) } } } diff --git a/sdk/metric/periodic_reader.go b/sdk/metric/periodic_reader.go index 9cdd9384c..67ee1b11a 100644 --- a/sdk/metric/periodic_reader.go +++ b/sdk/metric/periodic_reader.go @@ -334,7 +334,7 @@ func (r *PeriodicReader) Shutdown(ctx context.Context) error { } sErr := r.exporter.Shutdown(ctx) - if err == nil || err == ErrReaderShutdown { + if err == nil || errors.Is(err, ErrReaderShutdown) { err = sErr } diff --git a/sdk/trace/batch_span_processor_test.go b/sdk/trace/batch_span_processor_test.go index 85eef8984..d0720ff5d 100644 --- a/sdk/trace/batch_span_processor_test.go +++ b/sdk/trace/batch_span_processor_test.go @@ -329,7 +329,7 @@ func TestBatchSpanProcessorExportTimeout(t *testing.T) { generateSpan(t, tr, testOption{genNumSpans: 1}) tp.UnregisterSpanProcessor(bsp) - if exp.err != context.DeadlineExceeded { + if !errors.Is(exp.err, context.DeadlineExceeded) { t.Errorf("context deadline error not returned: got %+v", exp.err) } } diff --git a/sdk/trace/provider.go b/sdk/trace/provider.go index dec237ca7..14c2e5beb 100644 --- a/sdk/trace/provider.go +++ b/sdk/trace/provider.go @@ -291,7 +291,7 @@ func (p *TracerProvider) Shutdown(ctx context.Context) error { retErr = err } else { // Poor man's list of errors - retErr = fmt.Errorf("%v; %v", retErr, err) + retErr = fmt.Errorf("%w; %w", retErr, err) } } }