Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue 221: grpc error reporting #317

Merged
merged 3 commits into from
May 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions v3/integrations/nrgrpc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ module github.com/newrelic/go-agent/v3/integrations/nrgrpc
go 1.11

require (
github.com/golang/lint v0.0.0-20180702182130-06c8688daad7 // indirect
// protobuf v1.3.0 is the earliest version using modules, we use v1.3.1
// because all dependencies were removed in this version.
github.com/golang/protobuf v1.3.1
github.com/newrelic/go-agent/v3 v3.0.0
github.com/golang/protobuf v1.3.3
github.com/kisielk/gotool v1.0.0 // indirect
github.com/newrelic/go-agent/v3 v3.12.0
// v1.15.0 is the earliest version of grpc using modules.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we should remove or change this comment.

google.golang.org/grpc v1.15.0
google.golang.org/grpc v1.27.0
)
10 changes: 8 additions & 2 deletions v3/integrations/nrgrpc/nrgrpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func startTransaction(ctx context.Context, app *newrelic.Application, fullMethod
// https://github.com/newrelic/go-agent/blob/master/v3/integrations/nrgrpc/example/server/server.go
//
func UnaryServerInterceptor(app *newrelic.Application) grpc.UnaryServerInterceptor {
if nil == app {
if app == nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love the new non-Yoda conditions!

return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
return handler(ctx, req)
}
Expand All @@ -82,6 +82,9 @@ func UnaryServerInterceptor(app *newrelic.Application) grpc.UnaryServerIntercept
ctx = newrelic.NewContext(ctx, txn)
resp, err = handler(ctx, req)
txn.SetWebResponse(nil).WriteHeader(int(status.Code(err)))
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the right thing to do! Do we have an example of this in the UI?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'll add it to the original issue's conversation.

txn.NoticeError(err)
}
return
}
}
Expand Down Expand Up @@ -130,7 +133,7 @@ func newWrappedServerStream(stream grpc.ServerStream, txn *newrelic.Transaction)
// https://github.com/newrelic/go-agent/blob/master/v3/integrations/nrgrpc/example/server/server.go
//
func StreamServerInterceptor(app *newrelic.Application) grpc.StreamServerInterceptor {
if nil == app {
if app == nil {
return func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
return handler(srv, ss)
}
Expand All @@ -142,6 +145,9 @@ func StreamServerInterceptor(app *newrelic.Application) grpc.StreamServerInterce

err := handler(srv, newWrappedServerStream(ss, txn))
txn.SetWebResponse(nil).WriteHeader(int(status.Code(err)))
if err != nil {
txn.NoticeError(err)
}
return err
}
}
42 changes: 42 additions & 0 deletions v3/integrations/nrgrpc/nrgrpc_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,27 @@ func TestUnaryServerInterceptorError(t *testing.T) {
"request.uri": "grpc://bufnet/TestApplication/DoUnaryUnaryError",
},
UserAttributes: map[string]interface{}{},
}, {
Intrinsics: map[string]interface{}{
"error.class": internal.MatchAnything,
"error.message": "rpc error: code = DataLoss desc = oooooops!",
"guid": internal.MatchAnything,
"priority": internal.MatchAnything,
"sampled": internal.MatchAnything,
"spanId": internal.MatchAnything,
"traceId": internal.MatchAnything,
"transactionName": "WebTransaction/Go/TestApplication/DoUnaryUnaryError",
},
AgentAttributes: map[string]interface{}{
"httpResponseCode": 15,
"http.statusCode": 15,
"request.headers.User-Agent": internal.MatchAnything,
"request.headers.userAgent": internal.MatchAnything,
"request.headers.contentType": "application/grpc",
"request.method": "TestApplication/DoUnaryUnaryError",
"request.uri": "grpc://bufnet/TestApplication/DoUnaryUnaryError",
},
UserAttributes: map[string]interface{}{},
}})
}

Expand Down Expand Up @@ -613,6 +634,27 @@ func TestStreamServerInterceptorError(t *testing.T) {
"request.uri": "grpc://bufnet/TestApplication/DoUnaryStreamError",
},
UserAttributes: map[string]interface{}{},
}, {
Intrinsics: map[string]interface{}{
"error.class": internal.MatchAnything,
"error.message": "rpc error: code = DataLoss desc = oooooops!",
"guid": internal.MatchAnything,
"priority": internal.MatchAnything,
"sampled": internal.MatchAnything,
"spanId": internal.MatchAnything,
"traceId": internal.MatchAnything,
"transactionName": "WebTransaction/Go/TestApplication/DoUnaryStreamError",
},
AgentAttributes: map[string]interface{}{
"httpResponseCode": 15,
"http.statusCode": 15,
"request.headers.User-Agent": internal.MatchAnything,
"request.headers.userAgent": internal.MatchAnything,
"request.headers.contentType": "application/grpc",
"request.method": "TestApplication/DoUnaryStreamError",
"request.uri": "grpc://bufnet/TestApplication/DoUnaryStreamError",
},
UserAttributes: map[string]interface{}{},
}})
}

Expand Down