1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use crateDatabase;
use crateSharedState;
/// An in-progress database transaction instrumented for OpenTelemetry.
///
/// Wraps a `sqlx::Transaction` and propagates the connection-level attributes and metric
/// instruments. Pass `&mut transaction` directly to `SQLx` query builders – the
/// `sqlx::Executor` impl on `&mut Transaction` produces the same per-operation spans and
/// metrics as the parent pool.
///
/// Started by [`Pool::begin`](crate::Pool::begin). Call [`commit`](Self::commit) or
/// [`rollback`](Self::rollback) to finish the transaction; dropping the value without
/// committing rolls it back implicitly. Use [`with_annotations`](Self::with_annotations) /
/// [`with_operation`](Self::with_operation) to attach per-query semantic-convention
/// attributes.
///
/// # Example
///
/// ```no_run
/// # #[cfg(feature = "sqlite")]
/// # async fn _doc() -> Result<(), sqlx::Error> {
/// # use sqlx_otel::PoolBuilder;
/// # let pool = PoolBuilder::from(sqlx::SqlitePool::connect(":memory:").await?).build();
/// let mut tx = pool.begin().await?;
/// sqlx::query("INSERT INTO orders (id) VALUES (1)")
/// .execute(&mut tx)
/// .await?;
/// tx.commit().await?;
/// # Ok(())
/// # }
/// ```