contrib/google.golang.org/grpc: add `WithErrorCheck` option
What does this PR do?
This PR adds a new option called WithErrorCheck which allows users to set a custom function to determine whether an error should not be considered as an error for tracing purposes before sending it to DataDog.
Motivation
There are cases where an application produces errors, but they should not be sent to DataDog as errors. While the WithErrorCheck option allows for not treating specific gRPC status codes as errors, there are use cases where a more granular decision is needed based on the specific error, rather than just the status code.
For example, a user might want to consider a NotFound error as non-error for a specific RPC.
example
opts = []rpc.Option{
...
rpc.WithUnaryInterceptors(
ddgrpc.UnaryServerInterceptor(
ddgrpc.WithErrorCheck(func(method string, err error) bool {
if err == nil {
return true
}
errCode := status.Code(err)
if errCode == codes.NotFound && method == "/example.ExampleService/GetInfo" {
return true
}
return false
}),
),
),
...
}
...
rpcServer = rpc.NewServer(rpcHandler, opts...)
Describe how to test/QA your changes
Unit tests are included.
Reviewer's Checklist
- [x] Changed code has unit tests for its functionality.
- [ ] If this interacts with the agent in a new way, a system test has been added.
@dianashevchenko
I added unit tests for the NonErrorFunc option!
https://github.com/DataDog/dd-trace-go/pull/2035/commits/50c90b20490aa876cdbcaebc1cd02038953e7d63
How does this implementation look to you? I would appreciate your feedback.
I apologize for the delay in making the corrections. It would be much appreciated if you could take the time to review the revisions again. Thanks. @dianashevchenko cc @ajgajg1134