diff --git a/.golangci.yml b/.golangci.yml index ceddb297cb4..5badff67a54 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -12,6 +12,7 @@ linters: enable: - depguard - errcheck + - errorlint - godot - gofumpt - goimports diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d6868c9a93..d799ceaceb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Use `c.FullPath()` method to set `http.route` attribute in `go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin`. (#5734) - The double setup in `go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace/example` that caused duplicate traces. (#5564) - Out-of-bounds panic in case of invalid span ID in `go.opentelemetry.io/contrib/propagators/b3`. (#5754) +- Do not panic if a zero-value `SpanProcessor` is used from `go.opentelemetry.io/contrib/processors/baggage/baggagetrace`. (#5811) - Non-200 HTTP status codes when retrieving sampling rules in `go.opentelemetry.io/contrib/samplers/aws/xray` now return an error. (#5718) ### Deprecated @@ -46,6 +47,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm - Improve performance of `go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc` with the usage of `WithAttributeSet()` instead of `WithAttribute()`. (#5664) - Improve performance of `go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp` with the usage of `WithAttributeSet()` instead of `WithAttribute()`. (#5664) - Update `go.opentelemetry.io/contrib/config` to latest released configuration schema which introduces breaking changes where `Attributes` is now a `map[string]interface{}`. (#5758) +- Rename `BaggageKeyPredicate` to `Filter` in `go.opentelemetry.io/contrib/processors/baggage/baggagetrace`. (#5809) +- Return `*SpanProcessor` from `"go.opentelemetry.io/contrib/processors/baggage/baggagetrace".New` instead of the `trace.SpanProcessor` interface. (#5810) +- The `Filter` in `go.opentelemetry.io/contrib/processors/baggage/baggagetrace` now accepts a `baggage.Member` as a parameter instead of a string. (#5813) +- Rename `AllowAllBaggageKeys` to `AllowAllMembers` in `go.opentelemetry.io/contrib/processors/baggage/baggagetrace`. (#5813) ## [1.27.0/0.52.0/0.21.0/0.7.0/0.2.0] - 2024-05-21 diff --git a/bridges/otelzap/README.md b/bridges/otelzap/README.md new file mode 100644 index 00000000000..5565260ae55 --- /dev/null +++ b/bridges/otelzap/README.md @@ -0,0 +1,3 @@ +# OpenTelemetry Zap Log Bridge + +[![Go Reference](https://pkg.go.dev/badge/go.opentelemetry.io/contrib/bridges/otelzap.svg)](https://pkg.go.dev/go.opentelemetry.io/contrib/bridges/otelzap) diff --git a/bridges/otelzap/example_test.go b/bridges/otelzap/example_test.go new file mode 100644 index 00000000000..3a15ee262ce --- /dev/null +++ b/bridges/otelzap/example_test.go @@ -0,0 +1,44 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + +package otelzap_test + +import ( + "os" + + "go.opentelemetry.io/contrib/bridges/otelzap" + "go.opentelemetry.io/otel/log/noop" + + "go.uber.org/zap" + "go.uber.org/zap/zapcore" +) + +func Example() { + // Use a working LoggerProvider implementation instead e.g. use go.opentelemetry.io/otel/sdk/log. + provider := noop.NewLoggerProvider() + + // Initialize a zap logger with the otelzap bridge core. + // This method actually doesn't log anything on your STDOUT, as everything + // is shipped to a configured otel endpoint. + logger := zap.New(otelzap.NewCore("my/pkg/name", otelzap.WithLoggerProvider(provider))) + + // You can now use your logger in your code. + logger.Info("something really cool") +} + +func Example_multiple() { + // Use a working LoggerProvider implementation instead e.g. use go.opentelemetry.io/otel/sdk/log. + provider := noop.NewLoggerProvider() + + // If you want to log also on stdout, you can initialize a new zap.Core + // that has multiple outputs using the method zap.NewTee(). With the following code, + // logs will be written to stdout and also exported to the OTEL endpoint through the bridge. + core := zapcore.NewTee( + zapcore.NewCore(zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()), zapcore.AddSync(os.Stdout), zapcore.InfoLevel), + otelzap.NewCore("my/pkg/name", otelzap.WithLoggerProvider(provider)), + ) + logger := zap.New(core) + + // You can now use your logger in your code. + logger.Info("something really cool") +} diff --git a/config/metric.go b/config/metric.go index 53676330994..72f21cf3850 100644 --- a/config/metric.go +++ b/config/metric.go @@ -262,7 +262,7 @@ func prometheusReader(ctx context.Context, prometheusConfig *Prometheus) (sdkmet } go func() { - if err := server.Serve(lis); err != nil && err != http.ErrServerClosed { + if err := server.Serve(lis); err != nil && errors.Is(err, http.ErrServerClosed) { otel.Handle(fmt.Errorf("the Prometheus HTTP server exited unexpectedly: %w", err)) } }() diff --git a/detectors/aws/ec2/ec2.go b/detectors/aws/ec2/ec2.go index ee8aade2ed6..e88fe8c2351 100644 --- a/detectors/aws/ec2/ec2.go +++ b/detectors/aws/ec2/ec2.go @@ -5,6 +5,7 @@ package ec2 // import "go.opentelemetry.io/contrib/detectors/aws/ec2" import ( "context" + "errors" "fmt" "net/http" @@ -139,7 +140,8 @@ func (m *metadata) add(k attribute.Key, n string) { return } - rf, ok := err.(awserr.RequestFailure) + var rf awserr.RequestFailure + ok := errors.As(err, &rf) if !ok { m.errs = append(m.errs, fmt.Errorf("%q: %w", n, err)) return diff --git a/detectors/aws/ec2/go.mod b/detectors/aws/ec2/go.mod index c3221f275c9..92721b4427d 100644 --- a/detectors/aws/ec2/go.mod +++ b/detectors/aws/ec2/go.mod @@ -3,7 +3,7 @@ module go.opentelemetry.io/contrib/detectors/aws/ec2 go 1.21 require ( - github.com/aws/aws-sdk-go v1.54.9 + github.com/aws/aws-sdk-go v1.54.10 github.com/stretchr/testify v1.9.0 go.opentelemetry.io/otel v1.27.0 go.opentelemetry.io/otel/sdk v1.27.0 diff --git a/detectors/aws/ec2/go.sum b/detectors/aws/ec2/go.sum index 6b56c633040..19ea5c61ffd 100644 --- a/detectors/aws/ec2/go.sum +++ b/detectors/aws/ec2/go.sum @@ -1,5 +1,5 @@ -github.com/aws/aws-sdk-go v1.54.9 h1:e0Czh9AhrCVPuyaIUnibYmih3cYexJKlqlHSJ2eMKbI= -github.com/aws/aws-sdk-go v1.54.9/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU= +github.com/aws/aws-sdk-go v1.54.10 h1:dvkMlAttUsyacKj2L4poIQBLzOSWL2JG2ty+yWrqets= +github.com/aws/aws-sdk-go v1.54.10/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/detectors/gcp/cloud-function_test.go b/detectors/gcp/cloud-function_test.go index 351f8044e27..240c072e0c9 100644 --- a/detectors/gcp/cloud-function_test.go +++ b/detectors/gcp/cloud-function_test.go @@ -134,7 +134,7 @@ func TestCloudFunctionDetect(t *testing.T) { cloudRun: test.cr, } res, err := detector.Detect(context.Background()) - if err != test.expected.err { + if !errors.Is(err, test.expected.err) { t.Fatalf("got unexpected failure: %v", err) } else if diff := cmp.Diff(test.expected.res, res); diff != "" { t.Errorf("detected resource differ from expected (-want, +got)\n%s", diff) diff --git a/detectors/gcp/gce.go b/detectors/gcp/gce.go index c655dc80a88..694991a1625 100644 --- a/detectors/gcp/gce.go +++ b/detectors/gcp/gce.go @@ -5,6 +5,7 @@ package gcp // import "go.opentelemetry.io/contrib/detectors/gcp" import ( "context" + "errors" "fmt" "os" "strings" @@ -90,7 +91,9 @@ func hasProblem(err error) bool { if err == nil { return false } - if _, undefined := err.(metadata.NotDefinedError); undefined { + + var nde metadata.NotDefinedError + if undefined := errors.As(err, &nde); undefined { return false } return true diff --git a/exporters/autoexport/metrics.go b/exporters/autoexport/metrics.go index 25270de7f9a..5e16b170b4e 100644 --- a/exporters/autoexport/metrics.go +++ b/exporters/autoexport/metrics.go @@ -193,7 +193,7 @@ func init() { } go func() { - if err := server.Serve(lis); err != nil && err != http.ErrServerClosed { + if err := server.Serve(lis); err != nil && !errors.Is(err, http.ErrServerClosed) { otel.Handle(fmt.Errorf("the Prometheus HTTP server exited unexpectedly: %w", 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 8f28ef9596c..510c4d3b34d 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 @@ -41,7 +41,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/sso v1.22.0 // indirect github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.0 // indirect github.com/aws/aws-sdk-go-v2/service/sts v1.30.0 // indirect - github.com/aws/smithy-go v1.20.2 // indirect + github.com/aws/smithy-go v1.20.3 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect 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 b6a9d977cc3..2f4907afdfd 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 @@ -40,8 +40,8 @@ github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.0 h1:/4r71ghx+hX9spr884cqXHPE github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.0/go.mod h1:z0P8K+cBIsFXUr5rzo/psUeJ20XjPN0+Nn8067Nd+E4= github.com/aws/aws-sdk-go-v2/service/sts v1.30.0 h1:9ja34PaKybhCJjVKvxtDsUjbATUJGN+eF6QnO58u5cI= github.com/aws/aws-sdk-go-v2/service/sts v1.30.0/go.mod h1:N2mQiucsO0VwK9CYuS4/c2n6Smeh1v47Rz3dWCPFLdE= -github.com/aws/smithy-go v1.20.2 h1:tbp628ireGtzcHDDmLT/6ADHidqnwgF57XOXZe6tp4Q= -github.com/aws/smithy-go v1.20.2/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E= +github.com/aws/smithy-go v1.20.3 h1:ryHwveWzPV5BIof6fyDvor6V3iUL7nTfiTKXHiW05nE= +github.com/aws/smithy-go v1.20.3/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 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 448cf034daf..c40bfe89eab 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 @@ -33,7 +33,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/sso v1.22.0 // indirect github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.0 // indirect github.com/aws/aws-sdk-go-v2/service/sts v1.30.0 // indirect - github.com/aws/smithy-go v1.20.2 // indirect + github.com/aws/smithy-go v1.20.3 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect 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 8c9f1b0e64e..3cd129c4f27 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 @@ -38,8 +38,8 @@ github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.0 h1:/4r71ghx+hX9spr884cqXHPE github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.0/go.mod h1:z0P8K+cBIsFXUr5rzo/psUeJ20XjPN0+Nn8067Nd+E4= github.com/aws/aws-sdk-go-v2/service/sts v1.30.0 h1:9ja34PaKybhCJjVKvxtDsUjbATUJGN+eF6QnO58u5cI= github.com/aws/aws-sdk-go-v2/service/sts v1.30.0/go.mod h1:N2mQiucsO0VwK9CYuS4/c2n6Smeh1v47Rz3dWCPFLdE= -github.com/aws/smithy-go v1.20.2 h1:tbp628ireGtzcHDDmLT/6ADHidqnwgF57XOXZe6tp4Q= -github.com/aws/smithy-go v1.20.2/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E= +github.com/aws/smithy-go v1.20.3 h1:ryHwveWzPV5BIof6fyDvor6V3iUL7nTfiTKXHiW05nE= +github.com/aws/smithy-go v1.20.3/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/go.mod b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/go.mod index efc29ed2691..29fe003b04a 100644 --- a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/go.mod +++ b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/go.mod @@ -6,7 +6,7 @@ require ( github.com/aws/aws-sdk-go-v2 v1.30.0 github.com/aws/aws-sdk-go-v2/service/dynamodb v1.34.0 github.com/aws/aws-sdk-go-v2/service/sqs v1.34.0 - github.com/aws/smithy-go v1.20.2 + github.com/aws/smithy-go v1.20.3 github.com/stretchr/testify v1.9.0 go.opentelemetry.io/otel v1.27.0 go.opentelemetry.io/otel/trace v1.27.0 diff --git a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/go.sum b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/go.sum index 7dc1fc9425c..f776179d071 100644 --- a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/go.sum +++ b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/go.sum @@ -12,8 +12,8 @@ github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.9.13 h1:TiBH github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.9.13/go.mod h1:XN5B38yJn1XZvhyCeTzU5Ypha6+7UzVGj2w+aN0zn3k= github.com/aws/aws-sdk-go-v2/service/sqs v1.34.0 h1:YWyd8KPykQE9YS7M+RTAlVyOmUxXiesIC2WtMMSEnX4= github.com/aws/aws-sdk-go-v2/service/sqs v1.34.0/go.mod h1:4kCM5tMCkys9PFbuGHP+LjpxlsA5oMRUs3QvnWo11BM= -github.com/aws/smithy-go v1.20.2 h1:tbp628ireGtzcHDDmLT/6ADHidqnwgF57XOXZe6tp4Q= -github.com/aws/smithy-go v1.20.2/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E= +github.com/aws/smithy-go v1.20.3 h1:ryHwveWzPV5BIof6fyDvor6V3iUL7nTfiTKXHiW05nE= +github.com/aws/smithy-go v1.20.3/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/test/go.mod b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/test/go.mod index bc7270842c9..7f56ef8ac35 100644 --- a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/test/go.mod +++ b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/test/go.mod @@ -6,7 +6,7 @@ require ( github.com/aws/aws-sdk-go-v2 v1.30.0 github.com/aws/aws-sdk-go-v2/service/dynamodb v1.34.0 github.com/aws/aws-sdk-go-v2/service/route53 v1.42.0 - github.com/aws/smithy-go v1.20.2 + github.com/aws/smithy-go v1.20.3 github.com/stretchr/testify v1.9.0 go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws v0.52.0 go.opentelemetry.io/otel v1.27.0 diff --git a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/test/go.sum b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/test/go.sum index be7538a45e1..11b31b43161 100644 --- a/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/test/go.sum +++ b/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws/test/go.sum @@ -14,8 +14,8 @@ github.com/aws/aws-sdk-go-v2/service/route53 v1.42.0 h1:eTLaQC3n6hjuiLEC/YYL5xV1 github.com/aws/aws-sdk-go-v2/service/route53 v1.42.0/go.mod h1:aIGJVylrqjjBnf2NU2O1oHOOoBDFvHw6hy/GhelYksQ= github.com/aws/aws-sdk-go-v2/service/sqs v1.34.0 h1:YWyd8KPykQE9YS7M+RTAlVyOmUxXiesIC2WtMMSEnX4= github.com/aws/aws-sdk-go-v2/service/sqs v1.34.0/go.mod h1:4kCM5tMCkys9PFbuGHP+LjpxlsA5oMRUs3QvnWo11BM= -github.com/aws/smithy-go v1.20.2 h1:tbp628ireGtzcHDDmLT/6ADHidqnwgF57XOXZe6tp4Q= -github.com/aws/smithy-go v1.20.2/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E= +github.com/aws/smithy-go v1.20.3 h1:ryHwveWzPV5BIof6fyDvor6V3iUL7nTfiTKXHiW05nE= +github.com/aws/smithy-go v1.20.3/go.mod h1:krry+ya/rV9RDcV/Q16kpu6ypI4K2czasz0NC3qS14E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/go.mod b/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/go.mod index f63c8558f0d..9ecad9db05b 100644 --- a/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/go.mod +++ b/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/go.mod @@ -4,7 +4,7 @@ module go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/m go 1.21 require ( - go.mongodb.org/mongo-driver v1.15.1 + go.mongodb.org/mongo-driver v1.16.0 go.opentelemetry.io/otel v1.27.0 go.opentelemetry.io/otel/trace v1.27.0 ) diff --git a/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/go.sum b/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/go.sum index 37b5854ca15..b421392eaf9 100644 --- a/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/go.sum +++ b/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/go.sum @@ -26,8 +26,8 @@ github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gi github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA= github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -go.mongodb.org/mongo-driver v1.15.1 h1:l+RvoUOoMXFmADTLfYDm7On9dRm7p4T80/lEQM+r7HU= -go.mongodb.org/mongo-driver v1.15.1/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c= +go.mongodb.org/mongo-driver v1.16.0 h1:tpRsfBJMROVHKpdGyc1BBEzzjDUWjItxbVSZ8Ls4BQ4= +go.mongodb.org/mongo-driver v1.16.0/go.mod h1:oB6AhJQvFQL4LEHyXi6aJzQJtBiTQHiAd83l0GdFaiw= go.opentelemetry.io/otel v1.27.0 h1:9BZoF3yMK/O1AafMiQTVu0YDj5Ea4hPhxCs7sGva+cg= go.opentelemetry.io/otel v1.27.0/go.mod h1:DMpAK8fzYRzs+bi3rS5REupisuqTheUlSZJ1WnZaPAQ= go.opentelemetry.io/otel/metric v1.27.0 h1:hvj3vdEKyeCi4YaYfNjv2NUje8FqKqUY8IlF0FxV/ik= diff --git a/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/test/go.mod b/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/test/go.mod index 21ee8ccc3d7..1010ce15c3f 100644 --- a/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/test/go.mod +++ b/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/test/go.mod @@ -5,7 +5,7 @@ go 1.21 require ( github.com/stretchr/testify v1.9.0 - go.mongodb.org/mongo-driver v1.15.1 + go.mongodb.org/mongo-driver v1.16.0 go.opentelemetry.io/contrib v1.27.0 go.opentelemetry.io/contrib/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo v0.52.0 go.opentelemetry.io/otel v1.27.0 diff --git a/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/test/go.sum b/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/test/go.sum index 7418e0c4504..a321f76e5fc 100644 --- a/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/test/go.sum +++ b/instrumentation/go.mongodb.org/mongo-driver/mongo/otelmongo/test/go.sum @@ -26,8 +26,8 @@ github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gi github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA= github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -go.mongodb.org/mongo-driver v1.15.1 h1:l+RvoUOoMXFmADTLfYDm7On9dRm7p4T80/lEQM+r7HU= -go.mongodb.org/mongo-driver v1.15.1/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c= +go.mongodb.org/mongo-driver v1.16.0 h1:tpRsfBJMROVHKpdGyc1BBEzzjDUWjItxbVSZ8Ls4BQ4= +go.mongodb.org/mongo-driver v1.16.0/go.mod h1:oB6AhJQvFQL4LEHyXi6aJzQJtBiTQHiAd83l0GdFaiw= go.opentelemetry.io/otel v1.27.0 h1:9BZoF3yMK/O1AafMiQTVu0YDj5Ea4hPhxCs7sGva+cg= go.opentelemetry.io/otel v1.27.0/go.mod h1:DMpAK8fzYRzs+bi3rS5REupisuqTheUlSZJ1WnZaPAQ= go.opentelemetry.io/otel/metric v1.27.0 h1:hvj3vdEKyeCi4YaYfNjv2NUje8FqKqUY8IlF0FxV/ik= diff --git a/instrumentation/google.golang.org/grpc/otelgrpc/example/client/main.go b/instrumentation/google.golang.org/grpc/otelgrpc/example/client/main.go index 2f681b1d270..31240c2e438 100644 --- a/instrumentation/google.golang.org/grpc/otelgrpc/example/client/main.go +++ b/instrumentation/google.golang.org/grpc/otelgrpc/example/client/main.go @@ -5,6 +5,7 @@ package main import ( "context" + "errors" "fmt" "io" "log" @@ -121,7 +122,7 @@ func callSayHelloServerStream(c api.HelloServiceClient) error { for { response, err := stream.Recv() - if err == io.EOF { + if errors.Is(err, io.EOF) { break } else if err != nil { return fmt.Errorf("receiving from SayHelloServerStream: %w", err) @@ -172,7 +173,7 @@ func callSayHelloBidiStream(c api.HelloServiceClient) error { go func() { for { response, err := stream.Recv() - if err == io.EOF { + if errors.Is(err, io.EOF) { break } else if err != nil { // nolint: revive // This acts as its own main func. diff --git a/instrumentation/google.golang.org/grpc/otelgrpc/example/server/main.go b/instrumentation/google.golang.org/grpc/otelgrpc/example/server/main.go index 447c24ed6a6..5f6eecb131f 100644 --- a/instrumentation/google.golang.org/grpc/otelgrpc/example/server/main.go +++ b/instrumentation/google.golang.org/grpc/otelgrpc/example/server/main.go @@ -5,6 +5,7 @@ package main import ( "context" + "errors" "fmt" "io" "log" @@ -68,7 +69,7 @@ func (s *server) SayHelloClientStream(stream api.HelloService_SayHelloClientStre for { in, err := stream.Recv() - if err == io.EOF { + if errors.Is(err, io.EOF) { break } else if err != nil { log.Printf("Non EOF error: %v\n", err) @@ -88,7 +89,7 @@ func (s *server) SayHelloBidiStream(stream api.HelloService_SayHelloBidiStreamSe for { in, err := stream.Recv() - if err == io.EOF { + if errors.Is(err, io.EOF) { break } else if err != nil { log.Printf("Non EOF error: %v\n", err) diff --git a/instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go b/instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go index 58c3a4bfada..7d5ed058082 100644 --- a/instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go +++ b/instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go @@ -7,6 +7,7 @@ package otelgrpc // import "go.opentelemetry.io/contrib/instrumentation/google.g // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/rpc.md import ( "context" + "errors" "io" "net" "strconv" @@ -136,7 +137,7 @@ func (w *clientStream) RecvMsg(m interface{}) error { if err == nil && !w.desc.ServerStreams { w.endSpan(nil) - } else if err == io.EOF { + } else if errors.Is(err, io.EOF) { w.endSpan(nil) } else if err != nil { w.endSpan(err) diff --git a/instrumentation/google.golang.org/grpc/otelgrpc/internal/test/test_utils.go b/instrumentation/google.golang.org/grpc/otelgrpc/internal/test/test_utils.go index c5697a88322..8feea135dae 100644 --- a/instrumentation/google.golang.org/grpc/otelgrpc/internal/test/test_utils.go +++ b/instrumentation/google.golang.org/grpc/otelgrpc/internal/test/test_utils.go @@ -28,6 +28,7 @@ package test // import "go.opentelemetry.io/contrib/instrumentation/google.golan import ( "context" + "errors" "fmt" "io" "time" @@ -162,7 +163,7 @@ func DoServerStreaming(ctx context.Context, tc testpb.TestServiceClient, args .. index++ respCnt++ } - if rpcStatus != io.EOF { + if !errors.Is(rpcStatus, io.EOF) { logger.Fatalf("Failed to finish the server streaming rpc: %v", rpcStatus) } if respCnt != len(respSizes) { @@ -209,7 +210,7 @@ func DoPingPong(ctx context.Context, tc testpb.TestServiceClient, args ...grpc.C if err := stream.CloseSend(); err != nil { logger.Fatalf("%v.CloseSend() got %v, want %v", stream, err, nil) } - if _, err := stream.Recv(); err != io.EOF { + if _, err := stream.Recv(); !errors.Is(err, io.EOF) { logger.Fatalf("%v failed to complele the ping pong test: %v", stream, err) } } @@ -223,7 +224,7 @@ func DoEmptyStream(ctx context.Context, tc testpb.TestServiceClient, args ...grp if err := stream.CloseSend(); err != nil { logger.Fatalf("%v.CloseSend() got %v, want %v", stream, err, nil) } - if _, err := stream.Recv(); err != io.EOF { + if _, err := stream.Recv(); !errors.Is(err, io.EOF) { logger.Fatalf("%v failed to complete the empty stream test: %v", stream, err) } } @@ -306,7 +307,7 @@ func (s *testServer) StreamingInputCall(stream testpb.TestService_StreamingInput var sum int for { in, err := stream.Recv() - if err == io.EOF { + if errors.Is(err, io.EOF) { return stream.SendAndClose(&testpb.StreamingInputCallResponse{ AggregatedPayloadSize: int32(sum), }) @@ -332,7 +333,7 @@ func (s *testServer) FullDuplexCall(stream testpb.TestService_FullDuplexCallServ } for { in, err := stream.Recv() - if err == io.EOF { + if errors.Is(err, io.EOF) { // read done. return nil } @@ -366,7 +367,7 @@ func (s *testServer) HalfDuplexCall(stream testpb.TestService_HalfDuplexCallServ var msgBuf []*testpb.StreamingOutputCallRequest for { in, err := stream.Recv() - if err == io.EOF { + if errors.Is(err, io.EOF) { // read done. break } diff --git a/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_stats_handler_test.go b/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_stats_handler_test.go index 72f9de68758..7d951d6b2a3 100644 --- a/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_stats_handler_test.go +++ b/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_stats_handler_test.go @@ -5,6 +5,7 @@ package test import ( "context" + "errors" "io" "net" "strconv" @@ -1438,7 +1439,7 @@ func TestStatsHandlerConcurrentSafeContextCancellation(t *testing.T) { Payload: pl, } err := stream.Send(req) - if err == io.EOF { // possible due to context cancellation + if errors.Is(err, io.EOF) { // possible due to context cancellation require.ErrorIs(t, ctx.Err(), context.Canceled) } else { require.NoError(t, err) diff --git a/instrumentation/net/http/otelhttp/internal/semconv/v1.20.0.go b/instrumentation/net/http/otelhttp/internal/semconv/v1.20.0.go index cc4d6e12e29..c3e838aaa54 100644 --- a/instrumentation/net/http/otelhttp/internal/semconv/v1.20.0.go +++ b/instrumentation/net/http/otelhttp/internal/semconv/v1.20.0.go @@ -4,6 +4,7 @@ package semconv // import "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp/internal/semconv" import ( + "errors" "io" "net/http" @@ -43,7 +44,7 @@ func (o oldHTTPServer) ResponseTraceAttrs(resp ResponseTelemetry) []attribute.Ke if resp.ReadBytes > 0 { attributes = append(attributes, semconv.HTTPRequestContentLength(int(resp.ReadBytes))) } - if resp.ReadError != nil && resp.ReadError != io.EOF { + if resp.ReadError != nil && !errors.Is(resp.ReadError, io.EOF) { // This is not in the semantic conventions, but is historically provided attributes = append(attributes, attribute.String("http.read_error", resp.ReadError.Error())) } @@ -53,7 +54,7 @@ func (o oldHTTPServer) ResponseTraceAttrs(resp ResponseTelemetry) []attribute.Ke if resp.StatusCode > 0 { attributes = append(attributes, semconv.HTTPStatusCode(resp.StatusCode)) } - if resp.WriteError != nil && resp.WriteError != io.EOF { + if resp.WriteError != nil && !errors.Is(resp.WriteError, io.EOF) { // This is not in the semantic conventions, but is historically provided attributes = append(attributes, attribute.String("http.write_error", resp.WriteError.Error())) } diff --git a/processors/baggage/baggagetrace/example_test.go b/processors/baggage/baggagetrace/example_test.go index 416ef66c765..a8641841667 100644 --- a/processors/baggage/baggagetrace/example_test.go +++ b/processors/baggage/baggagetrace/example_test.go @@ -8,12 +8,13 @@ import ( "strings" "go.opentelemetry.io/contrib/processors/baggage/baggagetrace" + "go.opentelemetry.io/otel/baggage" "go.opentelemetry.io/otel/sdk/trace" ) func ExampleNew_allKeys() { trace.NewTracerProvider( - trace.WithSpanProcessor(baggagetrace.New(baggagetrace.AllowAllBaggageKeys)), + trace.WithSpanProcessor(baggagetrace.New(baggagetrace.AllowAllMembers)), ) } @@ -21,8 +22,8 @@ func ExampleNew_keysWithPrefix() { trace.NewTracerProvider( trace.WithSpanProcessor( baggagetrace.New( - func(baggageKey string) bool { - return strings.HasPrefix(baggageKey, "my-key") + func(m baggage.Member) bool { + return strings.HasPrefix(m.Key(), "my-key") }, ), ), @@ -34,8 +35,8 @@ func ExampleNew_keysMatchingRegex() { trace.NewTracerProvider( trace.WithSpanProcessor( baggagetrace.New( - func(baggageKey string) bool { - return expr.MatchString(baggageKey) + func(m baggage.Member) bool { + return expr.MatchString(m.Key()) }, ), ), diff --git a/processors/baggage/baggagetrace/processor.go b/processors/baggage/baggagetrace/processor.go index 589f57c01cf..77dc5c4dad8 100644 --- a/processors/baggage/baggagetrace/processor.go +++ b/processors/baggage/baggagetrace/processor.go @@ -7,39 +7,47 @@ import ( "context" "go.opentelemetry.io/otel/attribute" - otelbaggage "go.opentelemetry.io/otel/baggage" + "go.opentelemetry.io/otel/baggage" "go.opentelemetry.io/otel/sdk/trace" ) -// BaggageKeyPredicate is a function that returns true if the baggage key should be added to the span. -type BaggageKeyPredicate func(baggageKey string) bool +// Filter returns true if the baggage member should be added to a span. +type Filter func(member baggage.Member) bool -// AllowAllBaggageKeys is a BaggageKeyPredicate that allows all baggage keys. -var AllowAllBaggageKeys = func(string) bool { return true } +// AllowAllMembers allows all baggage members to be added to a span. +var AllowAllMembers Filter = func(baggage.Member) bool { return true } -// SpanProcessor is a processing pipeline for spans in the trace signal. +// SpanProcessor is a [trace.SpanProcessor] implementation that adds baggage +// members onto a span as attributes. type SpanProcessor struct { - baggageKeyPredicate BaggageKeyPredicate + filter Filter } var _ trace.SpanProcessor = (*SpanProcessor)(nil) -// New returns a new SpanProcessor. +// New returns a new [SpanProcessor]. // // The Baggage span processor duplicates onto a span the attributes found // in Baggage in the parent context at the moment the span is started. -// The predicate function is used to filter which baggage keys are added to the span. -func New(baggageKeyPredicate BaggageKeyPredicate) trace.SpanProcessor { +// The passed filter determines which baggage members are added to the span. +// +// If filter is nil, all baggage members will be added. +func New(filter Filter) *SpanProcessor { return &SpanProcessor{ - baggageKeyPredicate: baggageKeyPredicate, + filter: filter, } } // OnStart is called when a span is started and adds span attributes for baggage contents. func (processor SpanProcessor) OnStart(ctx context.Context, span trace.ReadWriteSpan) { - for _, entry := range otelbaggage.FromContext(ctx).Members() { - if processor.baggageKeyPredicate(entry.Key()) { - span.SetAttributes(attribute.String(entry.Key(), entry.Value())) + filter := processor.filter + if filter == nil { + filter = AllowAllMembers + } + + for _, member := range baggage.FromContext(ctx).Members() { + if filter(member) { + span.SetAttributes(attribute.String(member.Key(), member.Value())) } } } diff --git a/processors/baggage/baggagetrace/processor_test.go b/processors/baggage/baggagetrace/processor_test.go index 46fc9a3db3c..bd680c03842 100644 --- a/processors/baggage/baggagetrace/processor_test.go +++ b/processors/baggage/baggagetrace/processor_test.go @@ -9,11 +9,13 @@ import ( "strings" "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "go.opentelemetry.io/otel/attribute" - otelbaggage "go.opentelemetry.io/otel/baggage" + "go.opentelemetry.io/otel/baggage" "go.opentelemetry.io/otel/sdk/trace" + "go.opentelemetry.io/otel/sdk/trace/tracetest" ) var _ trace.SpanExporter = &testExporter{} @@ -35,14 +37,14 @@ func NewTestExporter() *testExporter { } func TestSpanProcessorAppendsAllBaggageAttributes(t *testing.T) { - baggage, _ := otelbaggage.New() - baggage = addEntryToBaggage(t, baggage, "baggage.test", "baggage value") - ctx := otelbaggage.ContextWithBaggage(context.Background(), baggage) + b, _ := baggage.New() + b = addEntryToBaggage(t, b, "baggage.test", "baggage value") + ctx := baggage.ContextWithBaggage(context.Background(), b) // create trace provider with baggage processor and test exporter exporter := NewTestExporter() tp := trace.NewTracerProvider( - trace.WithSpanProcessor(New(AllowAllBaggageKeys)), + trace.WithSpanProcessor(New(AllowAllMembers)), trace.WithSpanProcessor(trace.NewSimpleSpanProcessor(exporter)), ) @@ -59,12 +61,12 @@ func TestSpanProcessorAppendsAllBaggageAttributes(t *testing.T) { } func TestSpanProcessorAppendsBaggageAttributesWithHaPrefixPredicate(t *testing.T) { - baggage, _ := otelbaggage.New() - baggage = addEntryToBaggage(t, baggage, "baggage.test", "baggage value") - ctx := otelbaggage.ContextWithBaggage(context.Background(), baggage) + b, _ := baggage.New() + b = addEntryToBaggage(t, b, "baggage.test", "baggage value") + ctx := baggage.ContextWithBaggage(context.Background(), b) - baggageKeyPredicate := func(key string) bool { - return strings.HasPrefix(key, "baggage.") + baggageKeyPredicate := func(m baggage.Member) bool { + return strings.HasPrefix(m.Key(), "baggage.") } // create trace provider with baggage processor and test exporter @@ -87,13 +89,13 @@ func TestSpanProcessorAppendsBaggageAttributesWithHaPrefixPredicate(t *testing.T } func TestSpanProcessorAppendsBaggageAttributesWithRegexPredicate(t *testing.T) { - baggage, _ := otelbaggage.New() - baggage = addEntryToBaggage(t, baggage, "baggage.test", "baggage value") - ctx := otelbaggage.ContextWithBaggage(context.Background(), baggage) + b, _ := baggage.New() + b = addEntryToBaggage(t, b, "baggage.test", "baggage value") + ctx := baggage.ContextWithBaggage(context.Background(), b) expr := regexp.MustCompile(`^baggage\..*`) - baggageKeyPredicate := func(key string) bool { - return expr.MatchString(key) + baggageKeyPredicate := func(m baggage.Member) bool { + return expr.MatchString(m.Key()) } // create trace provider with baggage processor and test exporter @@ -116,13 +118,13 @@ func TestSpanProcessorAppendsBaggageAttributesWithRegexPredicate(t *testing.T) { } func TestOnlyAddsBaggageEntriesThatMatchPredicate(t *testing.T) { - baggage, _ := otelbaggage.New() - baggage = addEntryToBaggage(t, baggage, "baggage.test", "baggage value") - baggage = addEntryToBaggage(t, baggage, "foo", "bar") - ctx := otelbaggage.ContextWithBaggage(context.Background(), baggage) + b, _ := baggage.New() + b = addEntryToBaggage(t, b, "baggage.test", "baggage value") + b = addEntryToBaggage(t, b, "foo", "bar") + ctx := baggage.ContextWithBaggage(context.Background(), b) - baggageKeyPredicate := func(key string) bool { - return key == "baggage.test" + baggageKeyPredicate := func(m baggage.Member) bool { + return m.Key() == "baggage.test" } // create trace provider with baggage processor and test exporter @@ -144,10 +146,35 @@ func TestOnlyAddsBaggageEntriesThatMatchPredicate(t *testing.T) { require.Equal(t, want, exporter.spans[0].Attributes()[0]) } -func addEntryToBaggage(t *testing.T, baggage otelbaggage.Baggage, key, value string) otelbaggage.Baggage { - member, err := otelbaggage.NewMemberRaw(key, value) +func addEntryToBaggage(t *testing.T, b baggage.Baggage, key, value string) baggage.Baggage { + member, err := baggage.NewMemberRaw(key, value) require.NoError(t, err) - baggage, err = baggage.SetMember(member) + b, err = b.SetMember(member) require.NoError(t, err) - return baggage + return b } + +func TestZeroSpanProcessorNoPanic(t *testing.T) { + sp := new(SpanProcessor) + + m, err := baggage.NewMember("key", "val") + require.NoError(t, err) + b, err := baggage.New(m) + require.NoError(t, err) + + ctx := baggage.ContextWithBaggage(context.Background(), b) + roS := (tracetest.SpanStub{}).Snapshot() + rwS := rwSpan{} + assert.NotPanics(t, func() { + sp.OnStart(ctx, rwS) + sp.OnEnd(roS) + _ = sp.ForceFlush(ctx) + _ = sp.Shutdown(ctx) + }) +} + +type rwSpan struct { + trace.ReadWriteSpan +} + +func (s rwSpan) SetAttributes(kv ...attribute.KeyValue) {} diff --git a/samplers/probability/consistent/tracestate.go b/samplers/probability/consistent/tracestate.go index 332cec5497e..4d01102867f 100644 --- a/samplers/probability/consistent/tracestate.go +++ b/samplers/probability/consistent/tracestate.go @@ -198,6 +198,7 @@ func parseNumber(key string, input string, maximum uint8) (uint8, error) { if value > uint64(maximum) { return maximum + 1, parseError(key, strconv.ErrRange) } + // `value` is strictly less then the uint8 maximum. This cast is safe. return uint8(value), nil }