From e5d57959ebca03a024411d7e6ab72b22b5cc8a96 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 22 Sep 2021 17:56:07 +0000 Subject: [PATCH 1/3] Report context cancelation as non-error Someone else canceled this operation; we should not flag it as an error. Signed-off-by: Bryan Boreham --- errors.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/errors.go b/errors.go index 2f202af..4d3fb75 100644 --- a/errors.go +++ b/errors.go @@ -1,6 +1,9 @@ package otgrpc import ( + "context" + "errors" + "github.com/opentracing/opentracing-go" "github.com/opentracing/opentracing-go/ext" "google.golang.org/grpc/codes" @@ -57,6 +60,9 @@ func SetSpanTags(span opentracing.Span, err error, client bool) { code := codes.Unknown if s, ok := status.FromError(err); ok { code = s.Code() + } else if errors.Is(err, context.Canceled) { + code = codes.Canceled + err = nil // Someone else canceled this operation - we should not flag it as an error. } span.SetTag("response_code", code) span.SetTag("response_class", c) From 42ab33b690f6370f8731b3da4d9861d764c16142 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Thu, 23 Sep 2021 09:45:39 +0000 Subject: [PATCH 2/3] Add basic CircleCI config --- .circleci/config.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .circleci/config.yml diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..a57ce3f --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,17 @@ +version: 2 + +workflows: + version: 2 + test-build: + jobs: + - test + +jobs: + test: + docker: + - image: circleci/golang:1.17 + steps: + - checkout + - run: + name: Test + command: go test ./... From a0004a1c2c3b00fc08f0abfb59441e577e2a467a Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Thu, 23 Sep 2021 09:59:47 +0000 Subject: [PATCH 3/3] Fix up contect cancellation test --- test/interceptor_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/interceptor_test.go b/test/interceptor_test.go index 4626b68..8299c92 100644 --- a/test/interceptor_test.go +++ b/test/interceptor_test.go @@ -1,6 +1,7 @@ package interceptor_test import ( + "fmt" "io" "net" "testing" @@ -9,8 +10,9 @@ import ( "github.com/stretchr/testify/assert" "context" + testpb "github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc/test/otgrpc_testing" - "github.com/opentracing-contrib/go-grpc" + otgrpc "github.com/opentracing-contrib/go-grpc" "github.com/opentracing/opentracing-go/mocktracer" "google.golang.org/grpc" ) @@ -266,5 +268,6 @@ func TestStreamingContextCancellationOpenTracing(t *testing.T) { parent := spans[0] child := spans[1] assert.Equal(t, child.ParentID, parent.Context().(mocktracer.MockSpanContext).SpanID) - assert.True(t, parent.Tag("error").(bool)) + assert.Equal(t, fmt.Sprint(parent.Tag("response_code")), "Canceled") + assert.Nil(t, parent.Tag("error")) }