diff --git a/go.mod b/go.mod index 5fcfcc46..c75b993d 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,6 @@ require ( github.com/aws/smithy-go v1.20.3 github.com/coocood/freecache v1.2.4 github.com/google/uuid v1.6.0 - github.com/pkg/errors v0.9.1 github.com/solarwinds/apm-proto v1.0.5 github.com/stretchr/testify v1.9.0 go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 diff --git a/go.sum b/go.sum index 234979b7..ca8fa31a 100644 --- a/go.sum +++ b/go.sum @@ -30,8 +30,6 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= -github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= diff --git a/internal/config/config.go b/internal/config/config.go index 142716ff..650c289f 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -25,6 +25,7 @@ package config import ( + "errors" "fmt" "net" "os" @@ -36,7 +37,6 @@ import ( "github.com/solarwinds/apm-go/internal/log" - "github.com/pkg/errors" "gopkg.in/yaml.v2" ) @@ -200,7 +200,7 @@ func (f *TransactionFilter) UnmarshalYAML(unmarshal func(interface{}) error) err }{} if err := unmarshal(&aux); err != nil { - return errors.Wrap(err, "failed to unmarshal TransactionFilter") + return fmt.Errorf("failed to unmarshal TransactionFilter: %w", err) } if aux.Type != URL { return ErrTFInvalidType @@ -235,7 +235,7 @@ func (s *SamplingConfig) UnmarshalYAML(unmarshal func(interface{}) error) error SampleRate: -1, } if err := unmarshal(&aux); err != nil { - return errors.Wrap(err, "failed to unmarshal SamplingConfig") + return fmt.Errorf("failed to unmarshal SamplingConfig: %w", err) } if aux.TracingMode != "Invalid" { @@ -373,7 +373,7 @@ func (c *Config) validate() error { if c.ServiceKey != "" { c.ServiceKey = ToServiceKey(c.ServiceKey) if ok := IsValidServiceKey(c.ServiceKey); !ok { - return errors.Wrap(ErrInvalidServiceKey, fmt.Sprintf("service key: \"%s\"", c.ServiceKey)) + return fmt.Errorf("service key: \"%s\": %w", c.ServiceKey, ErrInvalidServiceKey) } } } @@ -419,7 +419,7 @@ func (c *Config) Load(opts ...Option) *Config { c.reset() if err := c.loadConfigFile(); err != nil { - log.Warning(errors.Wrap(err, "config file load error").Error()) + log.Warning(fmt.Errorf("config file load error: %w", err).Error()) return c.resetThenDisable() } c.loadEnvs() @@ -433,7 +433,7 @@ func (c *Config) Load(opts ...Option) *Config { } if err := c.validate(); err != nil { - log.Warning(errors.Wrap(err, "validation error").Error()) + log.Warning(fmt.Errorf("validation error: %w", err).Error()) return c.resetThenDisable() } @@ -692,7 +692,7 @@ func (c *Config) getConfigPath() string { func (c *Config) loadYaml(path string) error { data, err := os.ReadFile(path) if err != nil { - return errors.Wrap(err, "loadYaml") + return fmt.Errorf("loadYaml: %w", err) } // A pointer field may be assigned with nil in unmarshal, so just keep the @@ -703,7 +703,7 @@ func (c *Config) loadYaml(path string) error { // The config struct is modified in place so we won't tolerate any error err = yaml.Unmarshal(data, &c) if err != nil { - return errors.Wrap(err, fmt.Sprintf("loadYaml: %s", path)) + return fmt.Errorf("loadYaml: %s: %w", path, err) } if c.Sampling == nil { @@ -719,11 +719,11 @@ func (c *Config) loadYaml(path string) error { func (c *Config) checkFileSize(path string) error { file, err := os.Stat(path) if err != nil { - return errors.Wrap(err, "checkFileSize") + return fmt.Errorf("checkFileSize: %w", err) } size := file.Size() if size > maxConfigFileSize { - return errors.Wrap(ErrFileTooLarge, fmt.Sprintf("File size: %d", size)) + return fmt.Errorf("file size: %d: %w", size, ErrFileTooLarge) } return nil } @@ -736,7 +736,7 @@ func (c *Config) loadConfigFile() error { } if err := c.checkFileSize(path); err != nil { - return errors.Wrap(err, "loadConfigFile") + return fmt.Errorf("loadConfigFile: %w", err) } ext := filepath.Ext(path) @@ -744,7 +744,7 @@ func (c *Config) loadConfigFile() error { case ".yml", ".yaml": return c.loadYaml(path) default: - return errors.Wrap(ErrUnsupportedFormat, path) + return fmt.Errorf("%s: %w", path, ErrUnsupportedFormat) } } diff --git a/internal/config/env.go b/internal/config/env.go index c9530e8b..9520ff8b 100644 --- a/internal/config/env.go +++ b/internal/config/env.go @@ -21,8 +21,6 @@ import ( "reflect" "strconv" "strings" - - "github.com/pkg/errors" ) func toBool(s string) (bool, error) { @@ -116,7 +114,7 @@ func stringToValue(s string, typ reflect.Type) (reflect.Value, error) { } val, err = toBool(s) if err != nil { - log.Warningf("Ignore invalid bool value: %s", errors.Wrap(err, s)) + log.Warningf("Ignore invalid bool value: %s", fmt.Errorf("%w: %s", err, s)) } case reflect.Slice: if s == "" { diff --git a/internal/entryspans/entryspans.go b/internal/entryspans/entryspans.go index fc242d0f..2150bb39 100644 --- a/internal/entryspans/entryspans.go +++ b/internal/entryspans/entryspans.go @@ -15,8 +15,8 @@ package entryspans import ( + "errors" "fmt" - "github.com/pkg/errors" "github.com/solarwinds/apm-go/internal/config" sdktrace "go.opentelemetry.io/otel/sdk/trace" "go.opentelemetry.io/otel/trace" diff --git a/internal/hdrhist/encode.go b/internal/hdrhist/encode.go index bc56cec0..6f485caf 100644 --- a/internal/hdrhist/encode.go +++ b/internal/hdrhist/encode.go @@ -19,9 +19,8 @@ import ( "compress/zlib" "encoding/base64" "encoding/binary" + "fmt" "io" - - "github.com/pkg/errors" ) func EncodeCompressed(h *Hist) ([]byte, error) { @@ -29,7 +28,7 @@ func EncodeCompressed(h *Hist) ([]byte, error) { b64w := base64.NewEncoder(base64.StdEncoding, &buf) if err := encodeCompressed(h, b64w, h.Max()); err != nil { _ = b64w.Close() - return nil, errors.Wrap(err, "unable to encode histogram") + return nil, fmt.Errorf("unable to encode histogram: %w", err) } // DO NOT defer this close, otherwise that could prevent bytes from getting flushed if err := b64w.Close(); err != nil { @@ -58,8 +57,10 @@ func encodeCompressed(h *Hist, w io.Writer, histMax int64) error { } binary.BigEndian.PutUint32(buf.Bytes()[4:], uint32(buf.Len()-preCompressed)) - _, err = buf.WriteTo(w) - return errors.Wrap(err, "unable to write compressed hist") + if _, err = buf.WriteTo(w); err != nil { + return fmt.Errorf("unable to write compressed hist: %w", err) + } + return nil } func encodeInto(h *Hist, w io.Writer, max int64) error { @@ -88,8 +89,10 @@ func encodeInto(h *Hist, w io.Writer, max int64) error { payloadStart := buf.Len() fillBuffer(&buf, h, importantLen) binary.BigEndian.PutUint32(buf.Bytes()[4:], uint32(buf.Len()-payloadStart)) - _, err := buf.WriteTo(w) - return errors.Wrap(err, "unable to write uncompressed hist") + if _, err := buf.WriteTo(w); err != nil { + return fmt.Errorf("unable to write uncompressed hist: %w", err) + } + return nil } func fillBuffer(buf *bytes.Buffer, h *Hist, n int) { @@ -101,7 +104,7 @@ func fillBuffer(buf *bytes.Buffer, h *Hist, n int) { c := h.b.counts[srci] srci++ if c < 0 { - panic(errors.Errorf( + panic(fmt.Errorf( "can't encode hist with negative counts (count: %d, idx: %d, value range: [%d, %d])", c, srci, diff --git a/internal/hdrhist/log_writer.go b/internal/hdrhist/log_writer.go index 3234b95d..908a8d9c 100644 --- a/internal/hdrhist/log_writer.go +++ b/internal/hdrhist/log_writer.go @@ -20,8 +20,6 @@ import ( "fmt" "io" "time" - - "github.com/pkg/errors" ) type LogWriter struct { @@ -38,19 +36,19 @@ func (l *LogWriter) WriteStartTime(start time.Time) error { _, err := fmt.Fprintf(l.w, "#[StartTime: %.3f (seconds since epoch), %s]\n", float64(sec)+millis, start.Format(JavaDate)) - return errors.Wrap(err, "unable to write start time") + return fmt.Errorf("unable to write start time: %w", err) } func (l *LogWriter) WriteBaseTime(base time.Time) error { sec := base.Unix() millis := float64(base.Nanosecond()) / 1e6 // Java version only stores ms _, err := fmt.Fprintf(l.w, "#[BaseTime: %.3f (seconds since epoch)]\n", float64(sec)+millis) - return errors.Wrap(err, "unable to write base time") + return fmt.Errorf("unable to write base time: %w", err) } func (l *LogWriter) WriteComment(text string) error { _, err := l.w.Write([]byte("#" + text + "\n")) - return errors.Wrapf(err, "unable to write comment") + return fmt.Errorf("unable to write comment: %w", err) } var logWriterLegend = []byte("\"StartTimestamp\",\"Interval_Length\",\"Interval_Max\",\"Interval_Compressed_Histogram\"\n") @@ -100,5 +98,5 @@ func (l *LogWriter) writeHist(h *Hist, start time.Time, end time.Time) error { } l.buf.WriteString("\n") _, err := l.buf.WriteTo(l.w) - return errors.Wrap(err, "unable to write hist") + return fmt.Errorf("unable to write hist: %w", err) } diff --git a/internal/host/azure/azure.go b/internal/host/azure/azure.go index 1a1a9e4c..4d39ab13 100644 --- a/internal/host/azure/azure.go +++ b/internal/host/azure/azure.go @@ -18,7 +18,6 @@ import ( "context" "encoding/json" "fmt" - "github.com/pkg/errors" "github.com/solarwinds/apm-go/internal/log" collector "github.com/solarwinds/apm-proto/go/collectorpb" "io" @@ -114,7 +113,7 @@ func queryAzureIMDS(url_ string) (*MetadataCompute, error) { m := &MetadataCompute{} if err = json.Unmarshal(b, m); err != nil { - return nil, errors.Wrap(err, "failed to unmarshal json") + return nil, fmt.Errorf("failed to unmarshal json: %w", err) } return m, err } diff --git a/internal/log/logging_test.go b/internal/log/logging_test.go index bdf26b49..0020da85 100644 --- a/internal/log/logging_test.go +++ b/internal/log/logging_test.go @@ -15,6 +15,7 @@ package log import ( "bytes" + "errors" "github.com/solarwinds/apm-go/internal/utils" "io" "math/rand" @@ -25,7 +26,6 @@ import ( "sync" - "github.com/pkg/errors" "github.com/stretchr/testify/assert" ) diff --git a/internal/metrics/metrics.go b/internal/metrics/metrics.go index 88d6714c..ca555ec5 100644 --- a/internal/metrics/metrics.go +++ b/internal/metrics/metrics.go @@ -15,6 +15,7 @@ package metrics import ( + "errors" "github.com/solarwinds/apm-go/internal/bson" "github.com/solarwinds/apm-go/internal/config" "github.com/solarwinds/apm-go/internal/hdrhist" @@ -28,8 +29,6 @@ import ( "sync" "sync/atomic" "time" - - "github.com/pkg/errors" ) const ( diff --git a/internal/oboe/url.go b/internal/oboe/url.go index 6923754d..0af4bb9d 100644 --- a/internal/oboe/url.go +++ b/internal/oboe/url.go @@ -15,6 +15,7 @@ package oboe import ( + "fmt" "github.com/solarwinds/apm-go/internal/config" "github.com/solarwinds/apm-go/internal/log" "path/filepath" @@ -22,7 +23,6 @@ import ( "strings" "github.com/coocood/freecache" - "github.com/pkg/errors" ) var urls *urlFilters @@ -78,7 +78,7 @@ type regexFilter struct { func newRegexFilter(regex string, mode TracingMode) (*regexFilter, error) { re, err := regexp.Compile(regex) if err != nil { - return nil, errors.Wrap(err, "failed to parse regexp") + return nil, fmt.Errorf("failed to parse regexp: %w", err) } return ®exFilter{regex: re, trace: mode}, nil } diff --git a/internal/reporter/log_writer.go b/internal/reporter/log_writer.go index d381b7de..b9e1aa89 100644 --- a/internal/reporter/log_writer.go +++ b/internal/reporter/log_writer.go @@ -16,13 +16,12 @@ package reporter import ( "encoding/base64" "encoding/json" + "errors" "fmt" "github.com/solarwinds/apm-go/internal/log" "io" "os" "sync" - - "github.com/pkg/errors" ) // FlushWriter offers an interface to write a byte slice to a specific destination. @@ -119,7 +118,7 @@ func (lr *logWriter) flush() error { data, err := json.Marshal(lr.msg) if err != nil { - return errors.Wrap(err, "error marshaling message") + return fmt.Errorf("error marshaling message: %w", err) } lr.msg.Data.Events = []string{} lr.msg.Data.Metrics = []string{} @@ -128,7 +127,7 @@ func (lr *logWriter) flush() error { data = append(data, "\n"...) if _, err := lr.dest.Write(data); err != nil { - return errors.Wrap(err, "write to log reporter failed") + return fmt.Errorf("write to log reporter failed: %w", err) } if file, ok := lr.dest.(*os.File); ok { diff --git a/internal/reporter/methods_test.go b/internal/reporter/methods_test.go index 7321760f..7db15327 100644 --- a/internal/reporter/methods_test.go +++ b/internal/reporter/methods_test.go @@ -16,11 +16,11 @@ package reporter import ( "context" + "errors" "github.com/solarwinds/apm-go/internal/host" "github.com/solarwinds/apm-go/internal/reporter/mocks" "testing" - "github.com/pkg/errors" collector "github.com/solarwinds/apm-proto/go/collectorpb" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" diff --git a/internal/reporter/reporter.go b/internal/reporter/reporter.go index 39d00b77..f99e34c2 100644 --- a/internal/reporter/reporter.go +++ b/internal/reporter/reporter.go @@ -20,7 +20,6 @@ import ( "strings" "time" - "github.com/pkg/errors" "github.com/solarwinds/apm-go/internal/config" "github.com/solarwinds/apm-go/internal/log" "github.com/solarwinds/apm-go/internal/metrics" @@ -114,7 +113,7 @@ func CreateInitMessage(tid trace.TraceID, r *resource.Resource) Event { func sendInitMessage(r Reporter, rsrc *resource.Resource) { if r.Closed() { - log.Info(errors.Wrap(ErrReporterIsClosed, "send init message")) + log.Info(fmt.Errorf("send init message: %w", ErrReporterIsClosed)) return } tid := trace.TraceID{0} diff --git a/internal/reporter/reporter_grpc_test.go b/internal/reporter/reporter_grpc_test.go index 25d583d2..198d6865 100644 --- a/internal/reporter/reporter_grpc_test.go +++ b/internal/reporter/reporter_grpc_test.go @@ -18,6 +18,7 @@ import ( "crypto/subtle" "crypto/x509" "encoding/json" + "errors" "fmt" "github.com/solarwinds/apm-go/internal/utils" "io" @@ -31,7 +32,6 @@ import ( "time" "context" - "github.com/pkg/errors" pb "github.com/solarwinds/apm-proto/go/collectorpb" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -164,7 +164,7 @@ type TestProxyServer struct { func NewTestProxyServer(rawUrl string, pem, key string) (*TestProxyServer, error) { u, err := url.Parse(rawUrl) if err != nil { - return nil, errors.Wrap(err, "failed to create test proxy server") + return nil, fmt.Errorf("failed to create test proxy server: %w", err) } return &TestProxyServer{url: u, pemFile: pem, keyFile: key}, nil } diff --git a/internal/uams/file.go b/internal/uams/file.go index 7786cce6..c823dc53 100644 --- a/internal/uams/file.go +++ b/internal/uams/file.go @@ -17,7 +17,6 @@ package uams import ( "fmt" "github.com/google/uuid" - "github.com/pkg/errors" "os" "runtime" ) @@ -35,16 +34,16 @@ func determineFileForOS() string { func ReadFromFile(f string) (uuid.UUID, error) { if st, err := os.Stat(f); err != nil { - return uuid.Nil, errors.Wrap(err, "could not stat uams client file") + return uuid.Nil, fmt.Errorf("could not stat uams client file: %w", err) } else if st.IsDir() { return uuid.Nil, fmt.Errorf("could not open path (%s); Expected a file, got a directory instead", f) } if data, err := os.ReadFile(f); err != nil { - return uuid.Nil, errors.Wrap(err, fmt.Sprintf("could not read uams client file (%s)", f)) + return uuid.Nil, fmt.Errorf("could not read uams client file (%s): %w", f, err) } else { if uid, err := uuid.ParseBytes(data); err != nil { - return uuid.Nil, errors.Wrap(err, fmt.Sprintf("uams client file (%s) did not contain parseable UUID", f)) + return uuid.Nil, fmt.Errorf("uams client file (%s) did not contain parseable UUID: %w", f, err) } else { return uid, nil } diff --git a/internal/xtrace/xtrace.go b/internal/xtrace/xtrace.go index f5615cb8..ab9586ed 100644 --- a/internal/xtrace/xtrace.go +++ b/internal/xtrace/xtrace.go @@ -20,7 +20,6 @@ import ( "crypto/sha1" "encoding/hex" "fmt" - "github.com/pkg/errors" "github.com/solarwinds/apm-go/internal/log" "github.com/solarwinds/apm-go/internal/oboe" "regexp" @@ -212,7 +211,7 @@ func hmacHash(token, data []byte) string { func tsInScope(tsStr string) (string, error) { ts, err := strconv.ParseInt(tsStr, 10, 64) if err != nil { - return "", errors.Wrap(err, "tsInScope") + return "", fmt.Errorf("tsInScope: %w", err) } t := time.Unix(ts, 0) diff --git a/swo/agent.go b/swo/agent.go index 9e863132..b038a4f8 100644 --- a/swo/agent.go +++ b/swo/agent.go @@ -16,9 +16,9 @@ package swo import ( "context" + "errors" "os" - "github.com/pkg/errors" "github.com/solarwinds/apm-go/internal/config" "github.com/solarwinds/apm-go/internal/entryspans" "github.com/solarwinds/apm-go/internal/exporter"