-
Notifications
You must be signed in to change notification settings - Fork 375
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
Add ability to configure pg error_handler #3303
Add ability to configure pg error_handler #3303
Conversation
@@ -81,10 +81,12 @@ def sync_exec_prepared(statement_name, params, *args, &block) | |||
|
|||
def trace(name, sql: nil, statement_name: nil, block: nil) | |||
service = Datadog.configuration_for(self, :service_name) || datadog_configuration[:service_name] | |||
error_handler = datadog_configuration[:error_handler] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please let me know if there is another standard way to get the error handler here.
@@ -25,6 +25,11 @@ class Settings < Contrib::Configuration::Settings | |||
o.default false | |||
end | |||
|
|||
option :error_handler do |o| | |||
o.type :proc | |||
o.default_proc(&Tracing::SpanOperation::Events::DEFAULT_ON_ERROR) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Best I can tell this is the literal constant that represented the existing default behavior, so I wanted to reference it explicitly here to maintain existing behavior.
fd65189
to
243664c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor grammar nit, otherwise approved.
Merged your suggestion, thanks @urseberry ! Let me know if there's anything else I can help with to get this merged and released. Thanks for your prompt review! |
a9843f3
to
243664c
Compare
Hey @urseberry wanted to bump this one! Let me know if there's anything else ya need 🙏🏼 |
Thanks, Alex! I already approved on behalf of Documentation, but you also need an engineer to review and approve. It's in their queue and I'm sure someone will get to your PR soon. |
Thanks @marcotc for the merge! No rush, but just curious to have a sense of release cadence! |
@alexevanczuk We released 1.18.0 today and this has been included. Thank you for your contribution! |
Thanks so much @ekump ! |
What does this PR do?
This PR allows the client to configure an
error_handler
for thepg
integration, which does not currently support anerror_handler
as many of the other integrations.Motivation:
Application level rescuing
Take the following ruby code snippet:
In this example, the
pg
integration reports anPG::UniqueViolation
error to datadog. This error is pure noise, because our application code catches the exception generated by the postgres ruby gem. Since we're rescuing this, it conceptually makes sense to also not report the postgres error.Application level handling of all errors
Consider this code snippet:
insert_non_unique_record
Even though this is not rescued as above, the
PG::UniqueViolation
will propagate through the stack and eventually be caught by the overall Datadog middleware for web or async transactions and be reported to Datadog. To avoid double reporting of errors, we'd like to ignore these.Console level mistakes
Consider I'm in console and I make an error in my postgres query. This will be reported to datadog. I might want to ignore errors from console or just ignore all errors unless other parts of the stack rescue errors in console and report or log them.
Additional Notes
Let me know if there's other best practices for implementing this change.
For what it's worth – I also tried to ignore this through some other various hacks.
I tried this:
But this did not work. It looked like it did not actually clear the error span tag or the error status from the trace.
I'd love some other way to be able to more forcibly override any integration to remove errors from certain spans where they do not apply, but it does not appear there is a public API to do this yet.
How to test the change?
I followed patterns in the
faraday/middleware_spec.rb
to add tests to cover this.For Datadog employees:
credentials of any kind, I've requested a review from
@DataDog/security-design-and-guidance
.Unsure? Have a question? Request a review!