Skip to content

fix(grpc): allow custom error_handler for client interceptor#3095

Merged
TonyCTHsu merged 2 commits into
DataDog:masterfrom
deliveroo:fix/grpc-client-error-handler
Sep 14, 2023
Merged

fix(grpc): allow custom error_handler for client interceptor#3095
TonyCTHsu merged 2 commits into
DataDog:masterfrom
deliveroo:fix/grpc-client-error-handler

Conversation

@rfwroo

@rfwroo rfwroo commented Aug 31, 2023

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Collaborator

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

@marcotc marcotc left a comment

Copy link
Copy Markdown
Member

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

TonyCTHsu commented Sep 1, 2023

Copy link
Copy Markdown
Collaborator

👋 @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

rfwroo commented Sep 1, 2023

Copy link
Copy Markdown
Contributor Author

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
Copy Markdown
Collaborator

👋 @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

rfwroo commented Sep 12, 2023

Copy link
Copy Markdown
Contributor Author

@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
Copy Markdown
Collaborator

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

codecov-commenter commented Sep 14, 2023

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.15%. Comparing base (88f4425) to head (0e08b4b).
⚠️ Report is 5908 commits behind head on master.

Additional details and impacted files
@@            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     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@rfwroo
rfwroo requested a review from TonyCTHsu September 14, 2023 07:42
@TonyCTHsu
TonyCTHsu merged commit 1be8def into DataDog:master Sep 14, 2023
@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.

4 participants