Verify spans are available for SQL transactions (converted to project)
This issue has been converted to a project Verify spans are available for SQL transactions [Python]
In HTTP Requests within SQL Transactions we would like to detect when HTTP client requests are being made during a SQL transaction however to do this correctly, we need to verify that we have spans available from each backend SDK for database transactions. Some SDKs are known to not send this information (ex: Django) so we'd like to audit where it is/isn't available and get it added where it's not available.
These are generally BEGIN, COMMIT, and ROLLBACK however if we are doing any special casing in SDKs there are nuances depending on the SQL dialect (ex: MySQL supports START TRANSACTION in addition to BEGIN). The linked milestone above has more details in the FAQ section.
Hi @mrduncan,
The Python ecosystem has many database drivers, often with multiple popular drivers per database system. Many users only implicitly rely on the drivers through frameworks like Django. We could instrument more packages and we could add additional instrumentation to packages where we trace queries and not yet transactions.
I have surveyed the integrations we support to see if transactions are recorded as spans or we only record queries.
- For asyncpg, a PostgreSQL driver, we can see transactions:
-
The PyMongo integration only traces queries at the moment.
-
SQLAlchemy abstracts many database drivers. You can trace transactions with SQLAlchemy if you, for example, use an asynchronous API and PostgreSQL, in which case asyncpg is used under the hood.
-
Django comes with its own ORM. The trace for retrieving data for a webpage looks something like this.
Similar to SQLAlchemy, in Django traces may be different depending on the API used in the library. In the case of higher-level frameworks like SQLAlchemy or Django, users may or may not see database transactions depending on the library that they delegate to. There is a relevant discussion in https://github.com/getsentry/sentry-python/issues/2427.
To trace BEGIN, COMMIT, and ROLLBACK directly it may be easier to instrument more database drivers. We could also add instrumentation for the higher-level transaction API in SQLAlchemy, which ultimately can issue the transaction commands to different database systems.
Thanks for the research @alexander-alderman-webb! Is there a straightforward way to convert those db spans into db.sql.transaction.{begin,commit,rollback}?
@cleptric this seems like more evidence that we should track begin/commit/rollback independently across the board rather than a single span covering the transaction itself as discussed in https://github.com/getsentry/sentry-symfony/issues/916#issuecomment-3271298448