|
| 1 | +--- |
| 2 | +title: SQL Transactions |
| 3 | +--- |
| 4 | + |
| 5 | +<Alert> |
| 6 | + This document uses key words such as "MUST", "SHOULD", and "MAY" as defined in [RFC 2119](https://www.ietf.org/rfc/rfc2119.txt) to indicate requirement levels. |
| 7 | +</Alert> |
| 8 | + |
| 9 | +The SDK SHOULD auto-instrument all database transactions for SQL databases like PostgreSQL and MySQL. |
| 10 | +Each BEGIN, COMMIT, and ROLLBACK, or equivalent statement in the database system MUST result in an individual span. |
| 11 | +Spans for other transaction-level statements, such as SAVEPOINT, are RECOMMENDED and, when implemented, MUST also correspond to an individual SQL statement. |
| 12 | +Transaction statements SHOULD produce spans whether they are issued through a database driver or through an ORM. |
| 13 | + |
| 14 | +### Span Data |
| 15 | + |
| 16 | +Refer to <Link to="https://getsentry.github.io/sentry-conventions/generated/attributes/db.html">Database Span Data Conventions</Link> for a full list of attributes that database spans should have. |
| 17 | +The SDK SHOULD set the |
| 18 | + |
| 19 | +- db.system.name |
| 20 | +- db.operation.name |
| 21 | + |
| 22 | +attributes for transaction statement spans. |
| 23 | +Equivalent deprecated attributes MAY be used for backward compatibility, but they SHOULD be marked for deprecation. |
| 24 | + |
| 25 | +The operation names for BEGIN, COMMIT and ROLLBACK statements MUST be "BEGIN", "COMMIT", and "ROLLBACK", respectively. |
| 26 | +For synonyms, like BEGIN TRANSACTION for BEGIN, the operation name MAY reflect the synonym. In this example, "BEGIN TRANSACTION" MAY be used. |
| 27 | +Some statements, like SAVEPOINT, ROLLBACK TO SAVEPOINT and RELEASE SAVEPOINT, take arguments. |
| 28 | +The operation name for statements that accept arguments MUST be the statement without the arguments. For the examples above, the operation names are "SAVEPOINT", "ROLLBACK TO SAVEPOINT", and "RELEASE SAVEPOINT", respectively. |
| 29 | + |
| 30 | +For other transaction-level statements like MySQL's START TRANSACTION, the SDK SHOULD represent the literal statement as closely as possible, omitting control-flow characters like semicolons. |
| 31 | +SQLite's transaction statements can include modifiers. For instance, BEGIN DEFERRED is a modified BEGIN statement. In this case, the operation name MAY be either "BEGIN" or "BEGIN DEFERRED". |
| 32 | +The same rule applies to analogous modified statements. |
0 commit comments