diff --git a/.golangci.yml b/.golangci.yml index 512e11a3740..a86971538da 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -32,6 +32,7 @@ linters: - unconvert - unparam - unused + - usestdlibvars issues: # Maximum issues count per one linter. @@ -68,6 +69,7 @@ issues: linters: - gosec - perfsprint + - usestdlibvars include: # revive exported should have comment or be unexported. - EXC0012 diff --git a/bridges/otellogr/logsink_test.go b/bridges/otellogr/logsink_test.go index 78d3bf491c4..e904fef00bf 100644 --- a/bridges/otellogr/logsink_test.go +++ b/bridges/otellogr/logsink_test.go @@ -462,3 +462,92 @@ func TestConvertKVs(t *testing.T) { }) } } + +func BenchmarkLogSink(b *testing.B) { + message := "body" + keyValues := []any{ + "string", "hello", + "int", 42, + "float", 3.14, + "bool", false, + } + err := errors.New("error") + + b.Run("Info", func(b *testing.B) { + logSinks := make([]logr.LogSink, b.N) + for i := range logSinks { + logSinks[i] = NewLogSink("") + } + + b.ReportAllocs() + b.ResetTimer() + for n := 0; n < b.N; n++ { + logSinks[n].Info(0, message, keyValues...) + } + }) + + b.Run("Error", func(b *testing.B) { + logSinks := make([]logr.LogSink, b.N) + for i := range logSinks { + logSinks[i] = NewLogSink("") + } + + b.ReportAllocs() + b.ResetTimer() + for n := 0; n < b.N; n++ { + logSinks[n].Error(err, message, keyValues...) + } + }) + + b.Run("WithValues", func(b *testing.B) { + logSinks := make([]logr.LogSink, b.N) + for i := range logSinks { + logSinks[i] = NewLogSink("") + } + + b.ReportAllocs() + b.ResetTimer() + for n := 0; n < b.N; n++ { + logSinks[n].WithValues(keyValues...) + } + }) + + b.Run("WithName", func(b *testing.B) { + logSinks := make([]logr.LogSink, b.N) + for i := range logSinks { + logSinks[i] = NewLogSink("") + } + + b.ReportAllocs() + b.ResetTimer() + for n := 0; n < b.N; n++ { + logSinks[n].WithName("name") + } + }) + + b.Run("WithName.WithValues", func(b *testing.B) { + logSinks := make([]logr.LogSink, b.N) + for i := range logSinks { + logSinks[i] = NewLogSink("") + } + + b.ReportAllocs() + b.ResetTimer() + for n := 0; n < b.N; n++ { + logSinks[n].WithName("name").WithValues(keyValues...) + } + }) + + b.Run("(WithName.WithValues).Info", func(b *testing.B) { + logSinks := make([]logr.LogSink, b.N) + for i := range logSinks { + logSinks[i] = NewLogSink("").WithName("name").WithValues(keyValues...) + } + + b.ReportAllocs() + b.ResetTimer() + for n := 0; n < b.N; n++ { + logSinks[n].Info(0, message) + } + }) +} diff --git a/detectors/aws/eks/go.mod b/detectors/aws/eks/go.mod index bcfb9829a83..9f6704f8d59 100644 --- a/detectors/aws/eks/go.mod +++ b/detectors/aws/eks/go.mod @@ -21,7 +21,7 @@ require ( github.com/go-openapi/swag v0.23.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/protobuf v1.5.4 // indirect - github.com/google/gnostic-models v0.6.8 // indirect + github.com/google/gnostic-models v0.6.9 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/google/gofuzz v1.2.0 // indirect github.com/google/uuid v1.6.0 // indirect diff --git a/detectors/aws/eks/go.sum b/detectors/aws/eks/go.sum index 8174e73fa0b..9ce25cea314 100644 --- a/detectors/aws/eks/go.sum +++ b/detectors/aws/eks/go.sum @@ -23,8 +23,8 @@ github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= -github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I= -github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U= +github.com/google/gnostic-models v0.6.9 h1:MU/8wDLif2qCXZmzncUQ/BOfxWfthHi63KqpoNbWqVw= +github.com/google/gnostic-models v0.6.9/go.mod h1:CiWsm0s6BSQd1hRn8/QmxqB6BesYcbSZxsz9b0KuDBw= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= diff --git a/detectors/azure/azurevm/vm.go b/detectors/azure/azurevm/vm.go index e1005b0db87..cd3a3ef27a1 100644 --- a/detectors/azure/azurevm/vm.go +++ b/detectors/azure/azurevm/vm.go @@ -89,7 +89,7 @@ func (detector *ResourceDetector) getJSONMetadata(ctx context.Context) ([]byte, client := http.Client{Transport: pTransport} - req, err := http.NewRequestWithContext(ctx, "GET", detector.endpoint, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, detector.endpoint, nil) if err != nil { return nil, false, err } diff --git a/instrumentation/github.com/aws/aws-lambda-go/otellambda/example/go.mod b/instrumentation/github.com/aws/aws-lambda-go/otellambda/example/go.mod index a133d4c1f15..8055047e6c6 100644 --- a/instrumentation/github.com/aws/aws-lambda-go/otellambda/example/go.mod +++ b/instrumentation/github.com/aws/aws-lambda-go/otellambda/example/go.mod @@ -12,7 +12,7 @@ replace ( require ( github.com/aws/aws-lambda-go v1.47.0 github.com/aws/aws-sdk-go-v2/config v1.28.5 - github.com/aws/aws-sdk-go-v2/service/s3 v1.68.0 + github.com/aws/aws-sdk-go-v2/service/s3 v1.69.0 go.opentelemetry.io/contrib/detectors/aws/lambda v0.57.0 go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-lambda-go/otellambda v0.57.0 go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws v0.57.0 diff --git a/instrumentation/github.com/aws/aws-lambda-go/otellambda/example/go.sum b/instrumentation/github.com/aws/aws-lambda-go/otellambda/example/go.sum index 4a8ec934e2c..c5250023c1d 100644 --- a/instrumentation/github.com/aws/aws-lambda-go/otellambda/example/go.sum +++ b/instrumentation/github.com/aws/aws-lambda-go/otellambda/example/go.sum @@ -30,8 +30,8 @@ github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.5 h1:wtpJ4zcwr github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.5/go.mod h1:qu/W9HXQbbQ4+1+JcZp0ZNPV31ym537ZJN+fiS7Ti8E= github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.5 h1:P1doBzv5VEg1ONxnJss1Kh5ZG/ewoIE4MQtKKc6Crgg= github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.5/go.mod h1:NOP+euMW7W3Ukt28tAxPuoWao4rhhqJD3QEBk7oCg7w= -github.com/aws/aws-sdk-go-v2/service/s3 v1.68.0 h1:bFpcqdwtAEsgpZXvkTxIThFQx/EM0oV6kXmfFIGjxME= -github.com/aws/aws-sdk-go-v2/service/s3 v1.68.0/go.mod h1:ralv4XawHjEMaHOWnTFushl0WRqim/gQWesAMF6hTow= +github.com/aws/aws-sdk-go-v2/service/s3 v1.69.0 h1:Q2ax8S21clKOnHhhr933xm3JxdJebql+R7aNo7p7GBQ= +github.com/aws/aws-sdk-go-v2/service/s3 v1.69.0/go.mod h1:ralv4XawHjEMaHOWnTFushl0WRqim/gQWesAMF6hTow= github.com/aws/aws-sdk-go-v2/service/sqs v1.37.1 h1:39WvSrVq9DD6UHkD+fx5x19P5KpRQfNdtgReDVNbelc= github.com/aws/aws-sdk-go-v2/service/sqs v1.37.1/go.mod h1:3gwPzC9LER/BTQdQZ3r6dUktb1rSjABF1D3Sr6nS7VU= github.com/aws/aws-sdk-go-v2/service/sso v1.24.6 h1:3zu537oLmsPfDMyjnUS2g+F2vITgy5pB74tHI+JBNoM= diff --git a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/go.mod b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/go.mod index 8633e0de912..a177e66b6ce 100644 --- a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/go.mod +++ b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/go.mod @@ -8,7 +8,7 @@ require ( github.com/aws/aws-sdk-go-v2 v1.32.5 github.com/aws/aws-sdk-go-v2/config v1.28.5 github.com/aws/aws-sdk-go-v2/service/dynamodb v1.37.1 - github.com/aws/aws-sdk-go-v2/service/s3 v1.68.0 + github.com/aws/aws-sdk-go-v2/service/s3 v1.69.0 go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws v0.57.0 go.opentelemetry.io/otel v1.32.0 go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.32.0 diff --git a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/go.sum b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/go.sum index 0afbbb33c7a..2592224e9b0 100644 --- a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/go.sum +++ b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/example/go.sum @@ -28,8 +28,8 @@ github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.5 h1:wtpJ4zcwr github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.5/go.mod h1:qu/W9HXQbbQ4+1+JcZp0ZNPV31ym537ZJN+fiS7Ti8E= github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.5 h1:P1doBzv5VEg1ONxnJss1Kh5ZG/ewoIE4MQtKKc6Crgg= github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.5/go.mod h1:NOP+euMW7W3Ukt28tAxPuoWao4rhhqJD3QEBk7oCg7w= -github.com/aws/aws-sdk-go-v2/service/s3 v1.68.0 h1:bFpcqdwtAEsgpZXvkTxIThFQx/EM0oV6kXmfFIGjxME= -github.com/aws/aws-sdk-go-v2/service/s3 v1.68.0/go.mod h1:ralv4XawHjEMaHOWnTFushl0WRqim/gQWesAMF6hTow= +github.com/aws/aws-sdk-go-v2/service/s3 v1.69.0 h1:Q2ax8S21clKOnHhhr933xm3JxdJebql+R7aNo7p7GBQ= +github.com/aws/aws-sdk-go-v2/service/s3 v1.69.0/go.mod h1:ralv4XawHjEMaHOWnTFushl0WRqim/gQWesAMF6hTow= github.com/aws/aws-sdk-go-v2/service/sqs v1.37.1 h1:39WvSrVq9DD6UHkD+fx5x19P5KpRQfNdtgReDVNbelc= github.com/aws/aws-sdk-go-v2/service/sqs v1.37.1/go.mod h1:3gwPzC9LER/BTQdQZ3r6dUktb1rSjABF1D3Sr6nS7VU= github.com/aws/aws-sdk-go-v2/service/sso v1.24.6 h1:3zu537oLmsPfDMyjnUS2g+F2vITgy5pB74tHI+JBNoM= diff --git a/instrumentation/net/http/httptrace/otelhttptrace/example/client/client.go b/instrumentation/net/http/httptrace/otelhttptrace/example/client/client.go index 24a98265d4e..d685ce61bf9 100644 --- a/instrumentation/net/http/httptrace/otelhttptrace/example/client/client.go +++ b/instrumentation/net/http/httptrace/otelhttptrace/example/client/client.go @@ -79,7 +79,7 @@ func main() { ctx, span := tr.Start(ctx, "say hello", trace.WithAttributes(semconv.PeerService("ExampleService"))) defer span.End() - req, _ := http.NewRequestWithContext(ctx, "GET", *url, nil) + req, _ := http.NewRequestWithContext(ctx, http.MethodGet, *url, nil) fmt.Printf("Sending request...\n") res, err := client.Do(req) diff --git a/instrumentation/net/http/otelhttp/client.go b/instrumentation/net/http/otelhttp/client.go index 6aae83bfd20..b25641c55d3 100644 --- a/instrumentation/net/http/otelhttp/client.go +++ b/instrumentation/net/http/otelhttp/client.go @@ -18,7 +18,7 @@ var DefaultClient = &http.Client{Transport: NewTransport(http.DefaultTransport)} // Get is a convenient replacement for http.Get that adds a span around the request. func Get(ctx context.Context, targetURL string) (resp *http.Response, err error) { - req, err := http.NewRequestWithContext(ctx, "GET", targetURL, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, targetURL, nil) if err != nil { return nil, err } @@ -27,7 +27,7 @@ func Get(ctx context.Context, targetURL string) (resp *http.Response, err error) // Head is a convenient replacement for http.Head that adds a span around the request. func Head(ctx context.Context, targetURL string) (resp *http.Response, err error) { - req, err := http.NewRequestWithContext(ctx, "HEAD", targetURL, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodHead, targetURL, nil) if err != nil { return nil, err } @@ -36,7 +36,7 @@ func Head(ctx context.Context, targetURL string) (resp *http.Response, err error // Post is a convenient replacement for http.Post that adds a span around the request. func Post(ctx context.Context, targetURL, contentType string, body io.Reader) (resp *http.Response, err error) { - req, err := http.NewRequestWithContext(ctx, "POST", targetURL, body) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, targetURL, body) if err != nil { return nil, err } diff --git a/instrumentation/net/http/otelhttp/example/client/client.go b/instrumentation/net/http/otelhttp/example/client/client.go index 0fd9e070df1..0dfa44f493c 100644 --- a/instrumentation/net/http/otelhttp/example/client/client.go +++ b/instrumentation/net/http/otelhttp/example/client/client.go @@ -66,7 +66,7 @@ func main() { err = func(ctx context.Context) error { ctx, span := tr.Start(ctx, "say hello", trace.WithAttributes(semconv.PeerService("ExampleService"))) defer span.End() - req, _ := http.NewRequestWithContext(ctx, "GET", *url, nil) + req, _ := http.NewRequestWithContext(ctx, http.MethodGet, *url, nil) fmt.Printf("Sending request...\n") res, err := client.Do(req)