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(grpc): allow custom error_handler for client interceptor #3095

Merged
merged 2 commits into from
Sep 14, 2023

Conversation

rfwroo
Copy link
Contributor

@rfwroo rfwroo commented Aug 31, 2023

What does this PR do?

In #1583, the option of passing a custom error_handler to gRPC interceptors was added. This is useful for e.g. selectively marking certain gRPC status codes as an APM error.

However, the change was implemented only for gRPC server interceptors. This patch:

  • updates DatadogInterceptor::Client to pass the error_handler into the Tracing.trace call
  • updates DatadogInterceptor::Base to read the error_handler from the interceptor itself (i.e. what's passed here) instead of the default/global configuration. It's not clear why this wasn't needed for the Server interceptor.

Motivation:

To allow grpc.client spans to be selectively marked as errors based on gRPC status codes.

Additional Notes:

N/A

How to test the change?

Example:

interceptor = Datadog::Tracing::Contrib::GRPC::DatadogInterceptor::Client.new do |c|
  c.error_handler = proc { |span, error| span.set_error(error) unless error.is_a?(GRPC::NotFound) }
end

# then pass interceptor into gRPC stub

For Datadog employees:

  • If this PR touches code that signs or publishes builds or packages, or handles
    credentials of any kind, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.

Unsure? Have a question? Request a review!

@rfwroo rfwroo requested a review from a team August 31, 2023 09:46
@github-actions github-actions bot added integrations Involves tracing integrations tracing labels Aug 31, 2023
@rfwroo rfwroo force-pushed the fix/grpc-client-error-handler branch from 74b8a59 to 22d20fb Compare August 31, 2023 09:47
@rfwroo rfwroo changed the title fix(grpc): pass error_handler from config to interceptor fix(grpc): allow custom error_handler for client interceptor Aug 31, 2023
@TonyCTHsu
Copy link
Contributor

👋 @rfwroo , this looks promising. Let me take some time to play with and give feedback about this 😄

Copy link
Member

@marcotc marcotc left a comment

Choose a reason for hiding this comment

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

Thank you so much, @rfwroo! 🙇

@TonyCTHsu
Copy link
Contributor

TonyCTHsu commented Sep 1, 2023

👋 @rfwroo , do you think it make sense to add a new configuration settings for the client's error handler instead of sharing the same error handler?

@rfwroo
Copy link
Contributor Author

rfwroo commented Sep 1, 2023

Hey @TonyCTHsu,

do you think it make sense to add a new configuration settings for the client's error handler instead of sharing the same error handler?

Assuming that you mean the global error handler (i.e. datadog_configuration[:error_handler] from here)?

Allowing a global error handler for each span kind sounds neat 👍

I could follow up with a separate PR if you're happy to merge this as-is?

@TonyCTHsu
Copy link
Contributor

👋 @rfwroo, Sorry for my late reply.

Currently, there is only one error_handler configuration for the grpc integration. The error_handler method, is defined in the parent object DatadogInterceptor::Base and is only used by server interceptor

Applying global error handler to client interceptor is NOT actually adding a new function, it changes the existing behaviour for users already have error handler defined, which could be an undesired side-effect.

In order to have a smoother upgrade to other users, could you implement a new configuration option client_error_handler instead of sharing the same error handler? We could make it explicit that the error_handler would be only applying to server from the document.

@rfwroo
Copy link
Contributor Author

rfwroo commented Sep 12, 2023

@TonyCTHsu that sounds good.

We could make it explicit that the error_handler would be only applying to server from the document.

Would it make sense to also add a new server_error_handler configuration option, and deprecate the existing error_handler option instead?

@TonyCTHsu
Copy link
Contributor

Would it make sense to also add a new server_error_handler configuration option, and deprecate the existing error_handler option instead?

We want to avoid changes for the existing user, so deprecating without removing it makes sense to me. 😄

@codecov-commenter
Copy link

Codecov Report

Merging #3095 (0e08b4b) into master (88f4425) will decrease coverage by 0.01%.
Report is 171 commits behind head on master.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #3095      +/-   ##
==========================================
- Coverage   98.15%   98.15%   -0.01%     
==========================================
  Files        1323     1324       +1     
  Lines       75048    75103      +55     
  Branches     3422     3427       +5     
==========================================
+ Hits        73665    73718      +53     
- Misses       1383     1385       +2     

see 11 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@TonyCTHsu TonyCTHsu merged commit 1be8def into DataDog:master Sep 14, 2023
46 of 56 checks passed
@github-actions github-actions bot added this to the 1.15.0 milestone Sep 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrations Involves tracing integrations tracing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants