Skip to content

Commit

Permalink
Merge pull request #317 from nr-swilloughby/grpc_error_msg
Browse files Browse the repository at this point in the history
fix issue 221: grpc error reporting
  • Loading branch information
nr-swilloughby authored May 29, 2021
2 parents cf40b89 + bdc4b94 commit 428af9a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 5 deletions.
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.
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 {
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 {
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

0 comments on commit 428af9a

Please sign in to comment.