-
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
MySQL duplicate key being reported as an error, even though it's expected #3256
Comments
👋 @dextorer , I believe this behaviour is expected. From the graph, the blue span is generated by |
Thank you for confirming this behavior. I think we had the wrong assumption that instrumentations would be "aware" of each other and, in this specific case, not log an error if a higher-layer instrumentation is catching that exception; but as you confirmed, they are completely independent. This makes sense, depending on the angle you look at it. From a user perspective, it is perfectly reasonable to choose which instrumentations to add, without dependencies between them. Want to monitor MySQL? Add the At the same time, this approach has the potential of generating noise, since we usually rescue from exceptions on the framework level (Rails/Grape). In this case, the framework itself rescues from the MySQL exception, which seems to be an even stronger indicator that it is reasonable to expect a MySQL exception not to show up. I don't have a solution to suggest, I just want to offer the two perspectives. If we don't see a clear next action (aside from maybe documenting this somewhere), I'm happy for this issue to be closed as informative. |
👋 @dextorer , thanks for sharing your perspectives. We are well aware of such kind of dependent behaviour between instrumentations. This is not limited to ORM (ActiveRecord) and its DB driver (mysql2). Another example would be Elasticsearch gem and its http client(Faraday or Typhoeus). I totally agree with your perspective and I believe this is a tricky balance. It is important for us to provide the fine granular visibility for each instrumentation but that could potentially lead to bad signal/noise ratio. Right now, it tells the truth about what is actually happening for your application or how it truly behaves. I supposed the noise is still manageable and engineers can make sense of the graph after understanding the dependent behaviour between instrumentations. I would love to figure out ways to improve the S/N ratio for such scenario, but my honest answer would be that it is not trivia and the task itself is not prioritized at the moment. |
Current behaviour
We're seeing MySQL errors being reported by
ddtrace
when using Rails'create_or_find_by!
method. Quoting from the documentation:The exception is caught at the Rails level, as we can observe from the source code:
Yet,
ddtrace
reports this as an error.Expected behaviour
ddtrace
should not report theMysql2::Error:Duplicate entry
error, because that exception is caught at the Rails level (or, more generally speaking, because it's an expected behavior).Steps to reproduce
create_or_find_by!
create_or_find_by!
functionAdditional information
I checked the MySQL output when running the service locally:
As you can see, the behavior is precisely what we expect from
create_or_find_by!
: it tries to create a record (INSERT INTO
), fails (ROLLBACK
), then goes on to finding it (SELECT
).Environment
ddtrace version::
1.11.1
Configuration block (
Datadog.configure ...
):Ruby version:
3.1.4
Operating system:
MacOS, Linux (irrelevant)
Relevant library versions:
N/A
The text was updated successfully, but these errors were encountered: