@@ -29,10 +29,20 @@ private async Task CommitAsync(IOBehavior ioBehavior, CancellationToken cancella
2929 {
3030 VerifyValid ( ) ;
3131
32- using ( var cmd = new MySqlCommand ( "commit" , Connection , this ) )
33- await cmd . ExecuteNonQueryAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
34- Connection ! . CurrentTransaction = null ;
35- Connection = null ;
32+ using var activity = Connection ! . Session . StartActivity ( "Commit" ) ;
33+ try
34+ {
35+ using ( var cmd = new MySqlCommand ( "commit" , Connection , this ) { NoActivity = true } )
36+ await cmd . ExecuteNonQueryAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
37+ Connection ! . CurrentTransaction = null ;
38+ Connection = null ;
39+ activity . SetSuccess ( ) ;
40+ }
41+ catch ( Exception ex ) when ( activity is { IsAllDataRequested : true } )
42+ {
43+ activity . SetException ( ex ) ;
44+ throw ;
45+ }
3646 }
3747
3848 /// <summary>
@@ -55,8 +65,7 @@ private async Task RollbackAsync(IOBehavior ioBehavior, CancellationToken cancel
5565 {
5666 VerifyValid ( ) ;
5767
58- using ( var cmd = new MySqlCommand ( "rollback" , Connection , this ) )
59- await cmd . ExecuteNonQueryAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
68+ await DoRollback ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
6069 Connection ! . CurrentTransaction = null ;
6170 Connection = null ;
6271 }
@@ -146,7 +155,7 @@ private async Task ExecuteSavepointAsync(string command, string savepointName, I
146155 if ( savepointName . Length == 0 )
147156 throw new ArgumentException ( "savepointName must not be empty" , nameof ( savepointName ) ) ;
148157
149- using var cmd = new MySqlCommand ( command + "savepoint " + QuoteIdentifier ( savepointName ) , Connection , this ) ;
158+ using var cmd = new MySqlCommand ( command + "savepoint " + QuoteIdentifier ( savepointName ) , Connection , this ) { NoActivity = true } ;
150159 await cmd . ExecuteNonQueryAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
151160 }
152161
@@ -224,8 +233,7 @@ private async Task DoDisposeAsync(IOBehavior ioBehavior, CancellationToken cance
224233 {
225234 try
226235 {
227- using var cmd = new MySqlCommand ( "rollback" , Connection , this ) ;
228- await cmd . ExecuteNonQueryAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
236+ await DoRollback ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
229237 }
230238 catch ( IOException )
231239 {
@@ -245,6 +253,22 @@ internal MySqlTransaction(MySqlConnection connection, IsolationLevel isolationLe
245253 IsolationLevel = isolationLevel ;
246254 }
247255
256+ private async Task DoRollback ( IOBehavior ioBehavior , CancellationToken cancellationToken )
257+ {
258+ using var activity = Connection ! . Session . StartActivity ( "Rollback" ) ;
259+ try
260+ {
261+ using var cmd = new MySqlCommand ( "rollback" , Connection , this ) { NoActivity = true } ;
262+ await cmd . ExecuteNonQueryAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
263+ activity . SetSuccess ( ) ;
264+ }
265+ catch ( Exception ex ) when ( activity is { IsAllDataRequested : true } )
266+ {
267+ activity . SetException ( ex ) ;
268+ throw ;
269+ }
270+ }
271+
248272 private void VerifyValid ( )
249273 {
250274 if ( m_isDisposed )
0 commit comments