@@ -29,10 +29,20 @@ private async Task CommitAsync(IOBehavior ioBehavior, CancellationToken cancella
29
29
{
30
30
VerifyValid ( ) ;
31
31
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
+ }
36
46
}
37
47
38
48
/// <summary>
@@ -55,8 +65,7 @@ private async Task RollbackAsync(IOBehavior ioBehavior, CancellationToken cancel
55
65
{
56
66
VerifyValid ( ) ;
57
67
58
- using ( var cmd = new MySqlCommand ( "rollback" , Connection , this ) )
59
- await cmd . ExecuteNonQueryAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
68
+ await DoRollback ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
60
69
Connection ! . CurrentTransaction = null ;
61
70
Connection = null ;
62
71
}
@@ -146,7 +155,7 @@ private async Task ExecuteSavepointAsync(string command, string savepointName, I
146
155
if ( savepointName . Length == 0 )
147
156
throw new ArgumentException ( "savepointName must not be empty" , nameof ( savepointName ) ) ;
148
157
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 } ;
150
159
await cmd . ExecuteNonQueryAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
151
160
}
152
161
@@ -224,8 +233,7 @@ private async Task DoDisposeAsync(IOBehavior ioBehavior, CancellationToken cance
224
233
{
225
234
try
226
235
{
227
- using var cmd = new MySqlCommand ( "rollback" , Connection , this ) ;
228
- await cmd . ExecuteNonQueryAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
236
+ await DoRollback ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
229
237
}
230
238
catch ( IOException )
231
239
{
@@ -245,6 +253,22 @@ internal MySqlTransaction(MySqlConnection connection, IsolationLevel isolationLe
245
253
IsolationLevel = isolationLevel ;
246
254
}
247
255
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
+
248
272
private void VerifyValid ( )
249
273
{
250
274
if ( m_isDisposed )
0 commit comments