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

proposal: contrib/google.golang.org/grpc: add a WithErrorCheck option #2043

Open
BIwashi opened this issue Jun 14, 2023 · 2 comments
Open

proposal: contrib/google.golang.org/grpc: add a WithErrorCheck option #2043

BIwashi opened this issue Jun 14, 2023 · 2 comments
Labels
apm:ecosystem contrib/* related feature requests or bugs enhancement quick change/addition that does not need full team approval proposal/accepted Accepted proposals proposal more in depth change that requires full team approval

Comments

@BIwashi
Copy link

BIwashi commented Jun 14, 2023

Hello!
I would like to discuss the possibility of adding a WithErrorCheck option for gRPC.

There are cases where an application produces errors, but they should not be sent to DataDog as errors. While the NonErrorCodes 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.

The WithErrorCheck allows you to make decisions based on a combination of gRPC error codes and FullMethod in cases like this. Of course, it also allows you to freely set other conditions as needed.

For example, a user might want to consider a NotFound error as non-error for a specific RPC.

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...)

I must apologize, as I have already created a PR for this feature before submitting this issue. I sincerely apologize for not following the proper procedure. If you are willing, I would greatly appreciate it if you could review the PR I have created.

@BIwashi BIwashi added the enhancement quick change/addition that does not need full team approval label Jun 14, 2023
@knusbaum knusbaum changed the title Add a NonErrorFunc option for grpc proposal: contrib/google.golang.org/grpc: add a NonErrorFunc option Aug 10, 2023
@knusbaum knusbaum added apm:ecosystem contrib/* related feature requests or bugs proposal more in depth change that requires full team approval labels Aug 10, 2023
@knusbaum
Copy link
Contributor

Moving this to ecosystems for review.

@ajgajg1134
Copy link
Contributor

This looks good from our perspective with a few minor changes, we have a similar function across a number of contrib packages like was introduced here: #1315 named WithErrorCheck let's use that same name here (note that this flips the meaning of the return value).

@ajgajg1134 ajgajg1134 added the proposal/accepted Accepted proposals label Oct 31, 2023
@BIwashi BIwashi changed the title proposal: contrib/google.golang.org/grpc: add a NonErrorFunc option proposal: contrib/google.golang.org/grpc: add a WithErrorCheck option Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apm:ecosystem contrib/* related feature requests or bugs enhancement quick change/addition that does not need full team approval proposal/accepted Accepted proposals proposal more in depth change that requires full team approval
Projects
None yet
Development

No branches or pull requests

3 participants