Open
Description
Tracer Version(s)
2.18.1
Python Version(s)
Python 3.12.11
Pip Version(s)
pip 25.0.1
Bug Report
A typical concurrency-safe pattern for ensuring an object exists in the database works like this:
- Create a transaction savepoint
- Run a SELECT
- If SELECT returns no rows, attempt an INSERT
- If INSERT violates a unique index, attempt a second SELECT
Now, ddtrace
instrumentation hooks into the psycopg
driver, reports that failing INSERT as an error span, and Datadog proceeds to open an issue under error reporting (and charging us for it). This is a handled problem, the Python code surrounding it handles it gracefully, and it is a common enough pattern that it's part of the Django ORM.
The only workaround I found is to disable the database instrumentation completely, which is not something I want to do.
Reproduction Code
- Create a database table with a unique index.
- Write Python code that attempts to insert the same value twice.
- Run said Python code with
ddtrace
instrumentation enabled. - Observe that an issue is created in the Errors tab in Datadog.
Error Logs
No response
Libraries in Use
Django==5.2.1
psycopg==3.2.6
Operating System
No response