From 800b6b35642832e670dc480c1ab3e23d02fcd20f Mon Sep 17 00:00:00 2001 From: Edward McFarlane <3036610+emcfarlane@users.noreply.github.com> Date: Fri, 11 Oct 2024 12:30:12 -0400 Subject: [PATCH] Upgrade go v1.23 and libs (#182) This upgrades the minimum go v1.23. Upgrades otel libs to v1.29.0 (latest at go1.21) and the rest to latest. Fixes lint issues. Migrates buf yaml config to v2. --------- Signed-off-by: Edward McFarlane --- .github/workflows/ci.yaml | 4 +- .golangci.yml | 14 +- Makefile | 6 +- buf.gen.yaml | 11 +- buf.work.yaml | 3 - buf.yaml | 15 ++ context.go | 25 ---- context_legacy.go | 43 ------ go.mod | 27 ++-- go.sum | 48 +++--- interceptor.go | 2 +- interceptor_test.go | 31 ++-- internal/gen/observability/ping/v1/ping.pb.go | 138 ++++-------------- internal/proto/buf.yaml | 7 - option.go | 7 +- 15 files changed, 115 insertions(+), 266 deletions(-) delete mode 100644 buf.work.yaml create mode 100644 buf.yaml delete mode 100644 context.go delete mode 100644 context_legacy.go delete mode 100644 internal/proto/buf.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ff8a8d5..5854aa4 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go-version: [1.20.x,1.21.x,1.22.x] + go-version: [1.21.x,1.22.x,1.23.x] steps: - name: Checkout Code uses: actions/checkout@v4 @@ -30,5 +30,5 @@ jobs: - name: Lint # Often, lint & gofmt guidelines depend on the Go version. To prevent # conflicting guidance, run only on the most recent supported version. - if: matrix.go-version == '1.22.x' + if: matrix.go-version == '1.23.x' run: make checkgenerate && make lint diff --git a/.golangci.yml b/.golangci.yml index c373f6d..4e97f0d 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -36,37 +36,29 @@ linters: enable-all: true disable: - cyclop # covered by gocyclo - - deadcode # abandoned - depguard # unnecessary for small libraries - - exhaustivestruct # replaced by exhaustruct + - execinquery # deprecated since golangci v1.58 - funlen # rely on code review to limit function length - gocognit # dubious "cognitive overhead" quantification - gofumpt # prefer standard gofmt - goimports # rely on gci instead - - golint # deprecated by Go team - gomnd # some unnamed constants are okay - - ifshort # deprecated by author - inamedparam # convention is not followed - - interfacer # deprecated by author - ireturn # "accept interfaces, return structs" isn't ironclad - lll # don't want hard limits for line length - maintidx # covered by gocyclo - - maligned # readability trumps efficient struct packing + - mnd # status codes are clearer than constants - nlreturn # generous whitespace violates house style - nonamedreturns # named returns are fine; it's *bare* returns that are bad - - nosnakecase # deprecated in https://github.com/golangci/golangci-lint/pull/3065 - protogetter # too many false positives - - scopelint # deprecated by author - - structcheck # abandoned - testpackage # internal tests are fine - - varcheck # abandoned - wrapcheck # don't _always_ need to wrap errors - wsl # generous whitespace violates house style issues: exclude: # Don't ban use of fmt.Errorf to create new errors, but the remaining # checks from err113 are useful. - - "err113: do not define dynamic errors.*" + - "do not define dynamic errors, use wrapped static errors instead: .*" exclude-rules: # If-else is clearer than switch here. diff --git a/Makefile b/Makefile index 089642e..785bcc1 100644 --- a/Makefile +++ b/Makefile @@ -80,16 +80,16 @@ $(BIN)/protoc-gen-connect-go: go.mod $(BIN)/buf: Makefile @mkdir -p $(@D) - GOBIN=$(abspath $(@D)) $(GO) install github.com/bufbuild/buf/cmd/buf@v1.29.0 + GOBIN=$(abspath $(@D)) $(GO) install github.com/bufbuild/buf/cmd/buf@v1.45.0 $(BIN)/license-header: Makefile @mkdir -p $(@D) GOBIN=$(abspath $(@D)) $(GO) install \ - github.com/bufbuild/buf/private/pkg/licenseheader/cmd/license-header@v1.29.0 + github.com/bufbuild/buf/private/pkg/licenseheader/cmd/license-header@v1.45.0 $(BIN)/golangci-lint: Makefile @mkdir -p $(@D) - GOBIN=$(abspath $(@D)) $(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.56.2 + GOBIN=$(abspath $(@D)) $(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.61.0 $(BIN)/protoc-gen-go: Makefile @mkdir -p $(@D) diff --git a/buf.gen.yaml b/buf.gen.yaml index e97f033..d2baac1 100644 --- a/buf.gen.yaml +++ b/buf.gen.yaml @@ -1,12 +1,13 @@ -version: v1 +version: v2 managed: enabled: true - go_package_prefix: - default: connectrpc.com/otelconnect/internal/gen + override: + - file_option: go_package_prefix + value: connectrpc.com/otelconnect/internal/gen plugins: - - name: go + - local: protoc-gen-go out: internal/gen opt: paths=source_relative - - name: connect-go + - local: protoc-gen-connect-go out: internal/gen opt: paths=source_relative diff --git a/buf.work.yaml b/buf.work.yaml deleted file mode 100644 index 30f1e1f..0000000 --- a/buf.work.yaml +++ /dev/null @@ -1,3 +0,0 @@ -version: v1 -directories: - - internal/proto diff --git a/buf.yaml b/buf.yaml new file mode 100644 index 0000000..c656dcb --- /dev/null +++ b/buf.yaml @@ -0,0 +1,15 @@ +version: v2 +modules: + - path: internal/proto +lint: + use: + - STANDARD + except: + - FIELD_NOT_REQUIRED + - PACKAGE_NO_IMPORT_CYCLE + disallow_comment_ignores: true +breaking: + use: + - WIRE_JSON + except: + - FIELD_SAME_DEFAULT diff --git a/context.go b/context.go deleted file mode 100644 index 63e9f63..0000000 --- a/context.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2022-2024 The Connect Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build go1.21 - -package otelconnect - -import "context" - -// afterFunc calls context.AfterFunc. Build tags ensure that this function -// is only compiled when the Go version is at least 1.21. -func afterFunc(ctx context.Context, f func()) (stop func() bool) { - return context.AfterFunc(ctx, f) -} diff --git a/context_legacy.go b/context_legacy.go deleted file mode 100644 index 3d7d7aa..0000000 --- a/context_legacy.go +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2022-2024 The Connect Authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//go:build !go1.21 - -package otelconnect - -import ( - "context" - "sync/atomic" -) - -// afterFunc is a simple imitation of context.AfterFunc from Go 1.21. -// It is not as efficient as the real implementation, but it is sufficient -// for our purposes. -func afterFunc(ctx context.Context, f func()) (stop func() bool) { - ctx, cancel := context.WithCancel(ctx) - var once atomic.Bool - go func() { - <-ctx.Done() - if once.CompareAndSwap(false, true) { - f() - } - }() - return func() bool { - didStop := once.CompareAndSwap(false, true) - if didStop { - cancel() - } - return didStop - } -} diff --git a/go.mod b/go.mod index b093b5e..24e38c7 100644 --- a/go.mod +++ b/go.mod @@ -1,24 +1,27 @@ module connectrpc.com/otelconnect -go 1.20 +go 1.21 + +toolchain go1.23.2 require ( - connectrpc.com/connect v1.16.2 - github.com/google/go-cmp v0.5.9 - github.com/stretchr/testify v1.8.4 - go.opentelemetry.io/otel v1.19.0 - go.opentelemetry.io/otel/metric v1.19.0 - go.opentelemetry.io/otel/sdk v1.19.0 - go.opentelemetry.io/otel/sdk/metric v1.19.0 - go.opentelemetry.io/otel/trace v1.19.0 - google.golang.org/protobuf v1.33.0 + connectrpc.com/connect v1.17.0 + github.com/google/go-cmp v0.6.0 + github.com/stretchr/testify v1.9.0 + go.opentelemetry.io/otel v1.29.0 + go.opentelemetry.io/otel/metric v1.29.0 + go.opentelemetry.io/otel/sdk v1.29.0 + go.opentelemetry.io/otel/sdk/metric v1.29.0 + go.opentelemetry.io/otel/trace v1.29.0 + google.golang.org/protobuf v1.35.1 ) require ( github.com/davecgh/go-spew v1.1.1 // indirect - github.com/go-logr/logr v1.2.4 // indirect + github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect + github.com/google/uuid v1.6.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - golang.org/x/sys v0.12.0 // indirect + golang.org/x/sys v0.24.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 7645936..e105148 100644 --- a/go.sum +++ b/go.sum @@ -1,34 +1,38 @@ -connectrpc.com/connect v1.16.2 h1:ybd6y+ls7GOlb7Bh5C8+ghA6SvCBajHwxssO2CGFjqE= -connectrpc.com/connect v1.16.2/go.mod h1:n2kgwskMHXC+lVqb18wngEpF95ldBHXjZYJussz5FRc= +connectrpc.com/connect v1.17.0 h1:W0ZqMhtVzn9Zhn2yATuUokDLO5N+gIuBWMOnsQrfmZk= +connectrpc.com/connect v1.17.0/go.mod h1:0292hj1rnx8oFrStN7cB4jjVBeqs+Yx5yDIC2prWDO8= 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= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= -github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -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= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 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/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -go.opentelemetry.io/otel v1.19.0 h1:MuS/TNf4/j4IXsZuJegVzI1cwut7Qc00344rgH7p8bs= -go.opentelemetry.io/otel v1.19.0/go.mod h1:i0QyjOq3UPoTzff0PJB2N66fb4S0+rSbSB15/oyH9fY= -go.opentelemetry.io/otel/metric v1.19.0 h1:aTzpGtV0ar9wlV4Sna9sdJyII5jTVJEvKETPiOKwvpE= -go.opentelemetry.io/otel/metric v1.19.0/go.mod h1:L5rUsV9kM1IxCj1MmSdS+JQAcVm319EUrDVLrt7jqt8= -go.opentelemetry.io/otel/sdk v1.19.0 h1:6USY6zH+L8uMH8L3t1enZPR3WFEmSTADlqldyHtJi3o= -go.opentelemetry.io/otel/sdk v1.19.0/go.mod h1:NedEbbS4w3C6zElbLdPJKOpJQOrGUJ+GfzpjUvI0v1A= -go.opentelemetry.io/otel/sdk/metric v1.19.0 h1:EJoTO5qysMsYCa+w4UghwFV/ptQgqSL/8Ni+hx+8i1k= -go.opentelemetry.io/otel/sdk/metric v1.19.0/go.mod h1:XjG0jQyFJrv2PbMvwND7LwCEhsJzCzV5210euduKcKY= -go.opentelemetry.io/otel/trace v1.19.0 h1:DFVQmlVbfVeOuBRrwdtaehRrWiL1JoVs9CPIQ1Dzxpg= -go.opentelemetry.io/otel/trace v1.19.0/go.mod h1:mfaSyvGyEJEI0nyV2I4qhNQnbBOUUmYZpYojqMnX2vo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +go.opentelemetry.io/otel v1.29.0 h1:PdomN/Al4q/lN6iBJEN3AwPvUiHPMlt93c8bqTG5Llw= +go.opentelemetry.io/otel v1.29.0/go.mod h1:N/WtXPs1CNCUEx+Agz5uouwCba+i+bJGFicT8SR4NP8= +go.opentelemetry.io/otel/metric v1.29.0 h1:vPf/HFWTNkPu1aYeIsc98l4ktOQaL6LeSoeV2g+8YLc= +go.opentelemetry.io/otel/metric v1.29.0/go.mod h1:auu/QWieFVWx+DmQOUMgj0F8LHWdgalxXqvp7BII/W8= +go.opentelemetry.io/otel/sdk v1.29.0 h1:vkqKjk7gwhS8VaWb0POZKmIEDimRCMsopNYnriHyryo= +go.opentelemetry.io/otel/sdk v1.29.0/go.mod h1:pM8Dx5WKnvxLCb+8lG1PRNIDxu9g9b9g59Qr7hfAAok= +go.opentelemetry.io/otel/sdk/metric v1.29.0 h1:K2CfmJohnRgvZ9UAj2/FhIf/okdWcNdBwe1m8xFXiSY= +go.opentelemetry.io/otel/sdk/metric v1.29.0/go.mod h1:6zZLdCl2fkauYoZIOn/soQIDSWFmNSRcICarHfuhNJQ= +go.opentelemetry.io/otel/trace v1.29.0 h1:J/8ZNK4XgR7a21DZUAsbF8pZ5Jcw1VhACmnYt39JTi4= +go.opentelemetry.io/otel/trace v1.29.0/go.mod h1:eHl3w0sp3paPkYstJOmAimxhiFXPg+MMTlEh3nsQgWQ= golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= -golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= +golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= -google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA= +google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/interceptor.go b/interceptor.go index 9b89e65..bf17855 100644 --- a/interceptor.go +++ b/interceptor.go @@ -249,7 +249,7 @@ func (i *Interceptor) WrapStreamingClient(next connect.StreamingClientFunc) conn instrumentation.duration.Record(ctx, duration, metric.WithAttributes(state.attributes...)) } - stopCtxClose := afterFunc(ctx, closeSpan) + stopCtxClose := context.AfterFunc(ctx, closeSpan) return &streamingClientInterceptor{ //nolint:spancheck StreamingClientConn: conn, onClose: func() { diff --git a/interceptor_test.go b/interceptor_test.go index 9938c68..dcec47f 100644 --- a/interceptor_test.go +++ b/interceptor_test.go @@ -56,7 +56,7 @@ const ( FailMethod = "Fail" PingStreamMethod = "PingStream" UnimplementedString = "unimplemented" - TraceParentKey = "traceparent" + TraceParentKey = "Traceparent" rpcClientDuration = "rpc.client.duration" rpcClientRequestSize = "rpc.client.request.size" rpcClientResponseSize = "rpc.client.response.size" @@ -734,7 +734,7 @@ func TestMetrics(t *testing.T) { connect.WithInterceptors(interceptor), }, okayPingServer()) if _, err := pingClient.Ping(context.Background(), requestOfSize(1, 12)); err != nil { - t.Errorf(err.Error()) + t.Error(err) } metrics := &metricdata.ResourceMetrics{} require.NoError(t, metricReader.Collect(context.Background(), metrics)) @@ -888,7 +888,7 @@ func TestWithoutMetrics(t *testing.T) { connect.WithInterceptors(interceptor), }, okayPingServer()) if _, err := pingClient.Ping(context.Background(), requestOfSize(1, 12)); err != nil { - t.Errorf(err.Error()) + t.Error(err) } metrics := &metricdata.ResourceMetrics{} require.NoError(t, metricReader.Collect(context.Background(), metrics)) @@ -907,7 +907,7 @@ func TestWithoutTracing(t *testing.T) { connect.WithInterceptors(interceptor), }, nil, okayPingServer()) if _, err := pingClient.Ping(context.Background(), requestOfSize(1, 0)); err != nil { - t.Errorf(err.Error()) + t.Error(err) } if len(spanRecorder.Ended()) != 0 { t.Error("unexpected spans recorded") @@ -924,7 +924,7 @@ func TestClientSimple(t *testing.T) { connect.WithInterceptors(interceptor), }, okayPingServer()) if _, err := pingClient.Ping(context.Background(), requestOfSize(1, 0)); err != nil { - t.Errorf(err.Error()) + t.Error(err) } require.Len(t, clientSpanRecorder.Ended(), 1) require.Equal(t, codes.Unset, clientSpanRecorder.Ended()[0].Status().Code) @@ -1032,7 +1032,7 @@ func TestClientHandlerOpts(t *testing.T) { connect.WithInterceptors(clientInterceptor), }, okayPingServer()) if _, err := pingClient.Ping(context.Background(), requestOfSize(1, 0)); err != nil { - t.Errorf(err.Error()) + t.Error(err) } assertSpans(t, []wantSpans{}, serverSpanRecorder.Ended()) require.Len(t, clientSpanRecorder.Ended(), 1) @@ -1084,7 +1084,7 @@ func TestBasicFilter(t *testing.T) { req := requestOfSize(1, 0) req.Header().Set(headerKey, headerVal) if _, err := pingClient.Ping(context.Background(), req); err != nil { - t.Errorf(err.Error()) + t.Error(err) } if len(spanRecorder.Ended()) != 0 { t.Error("unexpected spans recorded") @@ -1190,10 +1190,10 @@ func TestInterceptors(t *testing.T) { connect.WithInterceptors(serverInterceptor), }, nil, okayPingServer()) if _, err := pingClient.Ping(context.Background(), requestOfSize(1, 0)); err != nil { - t.Errorf(err.Error()) + t.Error(err) } if _, err := pingClient.Ping(context.Background(), requestOfSize(2, largeMessageSize)); err != nil { - t.Errorf(err.Error()) + t.Error(err) } assertSpans(t, []wantSpans{ { @@ -1372,7 +1372,6 @@ func TestUnaryInterceptorPropagation(t *testing.T) { t.Parallel() spanRecorder := tracetest.NewSpanRecorder() traceProvider := trace.NewTracerProvider(trace.WithSpanProcessor(spanRecorder)) - var ctx context.Context var span traceapi.Span clientInterceptor, err := NewInterceptor( WithPropagator(propagation.TraceContext{}), @@ -1382,8 +1381,8 @@ func TestUnaryInterceptorPropagation(t *testing.T) { require.NoError(t, err) client, _, _ := startServer([]connect.HandlerOption{ connect.WithInterceptors(connect.UnaryInterceptorFunc(func(unaryFunc connect.UnaryFunc) connect.UnaryFunc { - return func(_ context.Context, request connect.AnyRequest) (connect.AnyResponse, error) { - ctx, span = trace.NewTracerProvider().Tracer("test").Start(context.Background(), "test") + return func(ctx context.Context, request connect.AnyRequest) (connect.AnyResponse, error) { + ctx, span = trace.NewTracerProvider().Tracer("test").Start(ctx, "test") return unaryFunc(ctx, request) } })), @@ -1482,7 +1481,6 @@ func TestStreamingHandlerInterceptorPropagation(t *testing.T) { spanRecorder := tracetest.NewSpanRecorder() traceProvider := trace.NewTracerProvider(trace.WithSpanProcessor(spanRecorder)) var span traceapi.Span - ctx := context.Background() serverInterceptor, err := NewInterceptor( WithPropagator(propagation.TraceContext{}), WithTracerProvider(traceProvider), @@ -1490,7 +1488,7 @@ func TestStreamingHandlerInterceptorPropagation(t *testing.T) { require.NoError(t, err) client, _, _ := startServer([]connect.HandlerOption{ connect.WithInterceptors(streamingHandlerInterceptorFunc(func(handlerFunc connect.StreamingHandlerFunc) connect.StreamingHandlerFunc { - return func(_ context.Context, conn connect.StreamingHandlerConn) error { + return func(ctx context.Context, conn connect.StreamingHandlerConn) error { ctx, span = trace.NewTracerProvider().Tracer("test").Start(ctx, "test") return handlerFunc(ctx, conn) } @@ -1982,9 +1980,8 @@ func TestServerSpanStatus(t *testing.T) { return nil, connect.NewError(testcase.connectCode, errors.New(testcase.connectCode.String())) }, }) - if _, err := pingClient.Ping(context.Background(), requestOfSize(1, 0)); err == nil { - t.Error("want error") - } + _, err = pingClient.Ping(context.Background(), requestOfSize(1, 0)) + require.Error(t, err) require.Len(t, spanRecorder.Ended(), 1) require.Equal(t, codes.Error, clientSpanRecorder.Ended()[0].Status().Code) require.Equal(t, testcase.wantServerSpanCode, spanRecorder.Ended()[0].Status().Code) diff --git a/internal/gen/observability/ping/v1/ping.pb.go b/internal/gen/observability/ping/v1/ping.pb.go index 7b5b2ac..d2d8be5 100644 --- a/internal/gen/observability/ping/v1/ping.pb.go +++ b/internal/gen/observability/ping/v1/ping.pb.go @@ -14,7 +14,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.33.0 +// protoc-gen-go v1.35.1 // protoc (unknown) // source: observability/ping/v1/ping.proto @@ -45,11 +45,9 @@ type PingRequest struct { func (x *PingRequest) Reset() { *x = PingRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_observability_ping_v1_ping_proto_msgTypes[0] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_observability_ping_v1_ping_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *PingRequest) String() string { @@ -60,7 +58,7 @@ func (*PingRequest) ProtoMessage() {} func (x *PingRequest) ProtoReflect() protoreflect.Message { mi := &file_observability_ping_v1_ping_proto_msgTypes[0] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -100,11 +98,9 @@ type PingResponse struct { func (x *PingResponse) Reset() { *x = PingResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_observability_ping_v1_ping_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_observability_ping_v1_ping_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *PingResponse) String() string { @@ -115,7 +111,7 @@ func (*PingResponse) ProtoMessage() {} func (x *PingResponse) ProtoReflect() protoreflect.Message { mi := &file_observability_ping_v1_ping_proto_msgTypes[1] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -154,11 +150,9 @@ type FailRequest struct { func (x *FailRequest) Reset() { *x = FailRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_observability_ping_v1_ping_proto_msgTypes[2] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_observability_ping_v1_ping_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *FailRequest) String() string { @@ -169,7 +163,7 @@ func (*FailRequest) ProtoMessage() {} func (x *FailRequest) ProtoReflect() protoreflect.Message { mi := &file_observability_ping_v1_ping_proto_msgTypes[2] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -199,11 +193,9 @@ type FailResponse struct { func (x *FailResponse) Reset() { *x = FailResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_observability_ping_v1_ping_proto_msgTypes[3] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_observability_ping_v1_ping_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *FailResponse) String() string { @@ -214,7 +206,7 @@ func (*FailResponse) ProtoMessage() {} func (x *FailResponse) ProtoReflect() protoreflect.Message { mi := &file_observability_ping_v1_ping_proto_msgTypes[3] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -240,11 +232,9 @@ type PingStreamRequest struct { func (x *PingStreamRequest) Reset() { *x = PingStreamRequest{} - if protoimpl.UnsafeEnabled { - mi := &file_observability_ping_v1_ping_proto_msgTypes[4] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_observability_ping_v1_ping_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *PingStreamRequest) String() string { @@ -255,7 +245,7 @@ func (*PingStreamRequest) ProtoMessage() {} func (x *PingStreamRequest) ProtoReflect() protoreflect.Message { mi := &file_observability_ping_v1_ping_proto_msgTypes[4] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -295,11 +285,9 @@ type PingStreamResponse struct { func (x *PingStreamResponse) Reset() { *x = PingStreamResponse{} - if protoimpl.UnsafeEnabled { - mi := &file_observability_ping_v1_ping_proto_msgTypes[5] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } + mi := &file_observability_ping_v1_ping_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } func (x *PingStreamResponse) String() string { @@ -310,7 +298,7 @@ func (*PingStreamResponse) ProtoMessage() {} func (x *PingStreamResponse) ProtoReflect() protoreflect.Message { mi := &file_observability_ping_v1_ping_proto_msgTypes[5] - if protoimpl.UnsafeEnabled && x != nil { + if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) @@ -411,7 +399,7 @@ func file_observability_ping_v1_ping_proto_rawDescGZIP() []byte { } var file_observability_ping_v1_ping_proto_msgTypes = make([]protoimpl.MessageInfo, 6) -var file_observability_ping_v1_ping_proto_goTypes = []interface{}{ +var file_observability_ping_v1_ping_proto_goTypes = []any{ (*PingRequest)(nil), // 0: observability.ping.v1.PingRequest (*PingResponse)(nil), // 1: observability.ping.v1.PingResponse (*FailRequest)(nil), // 2: observability.ping.v1.FailRequest @@ -438,80 +426,6 @@ func file_observability_ping_v1_ping_proto_init() { if File_observability_ping_v1_ping_proto != nil { return } - if !protoimpl.UnsafeEnabled { - file_observability_ping_v1_ping_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PingRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_observability_ping_v1_ping_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PingResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_observability_ping_v1_ping_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*FailRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_observability_ping_v1_ping_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*FailResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_observability_ping_v1_ping_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PingStreamRequest); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_observability_ping_v1_ping_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*PingStreamResponse); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - } type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ diff --git a/internal/proto/buf.yaml b/internal/proto/buf.yaml deleted file mode 100644 index efda402..0000000 --- a/internal/proto/buf.yaml +++ /dev/null @@ -1,7 +0,0 @@ -version: v1 -lint: - use: - - DEFAULT -breaking: - use: - - WIRE_JSON diff --git a/option.go b/option.go index f7993a7..3d82400 100644 --- a/option.go +++ b/option.go @@ -21,10 +21,11 @@ import ( connect "connectrpc.com/connect" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/metric" - "go.opentelemetry.io/otel/metric/noop" + metricnoop "go.opentelemetry.io/otel/metric/noop" "go.opentelemetry.io/otel/propagation" semconv "go.opentelemetry.io/otel/semconv/v1.21.0" "go.opentelemetry.io/otel/trace" + tracenoop "go.opentelemetry.io/otel/trace/noop" ) // An Option configures the OpenTelemetry instrumentation. @@ -61,12 +62,12 @@ func WithFilter(filter func(context.Context, connect.Spec) bool) Option { // WithoutTracing disables tracing. func WithoutTracing() Option { - return WithTracerProvider(trace.NewNoopTracerProvider()) + return WithTracerProvider(tracenoop.NewTracerProvider()) } // WithoutMetrics disables metrics. func WithoutMetrics() Option { - return WithMeterProvider(noop.NewMeterProvider()) + return WithMeterProvider(metricnoop.NewMeterProvider()) } // WithAttributeFilter sets the attribute filter for all metrics and trace attributes.