Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Transaction Id" and "Client Version" in Diagnostic Source traces #515

Merged
merged 5 commits into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal static class SqlClientDiagnosticListenerExtensions
public const string SqlAfterRollbackTransaction = SqlClientPrefix + nameof(WriteTransactionRollbackAfter);
public const string SqlErrorRollbackTransaction = SqlClientPrefix + nameof(WriteTransactionRollbackError);

public static Guid WriteCommandBefore(this DiagnosticListener @this, SqlCommand sqlCommand, [CallerMemberName] string operation = "")
public static Guid WriteCommandBefore(this DiagnosticListener @this, SqlCommand sqlCommand, SqlTransaction transaction, [CallerMemberName] string operation = "")
{
if (@this.IsEnabled(SqlBeforeExecuteCommand))
{
Expand All @@ -52,6 +52,7 @@ public static Guid WriteCommandBefore(this DiagnosticListener @this, SqlCommand
Operation = operation,
ConnectionId = sqlCommand.Connection?.ClientConnectionId,
Command = sqlCommand,
transaction?.InternalTransaction?.TransactionId,
Timestamp = Stopwatch.GetTimestamp()
});

Expand All @@ -61,7 +62,7 @@ public static Guid WriteCommandBefore(this DiagnosticListener @this, SqlCommand
return Guid.Empty;
}

public static void WriteCommandAfter(this DiagnosticListener @this, Guid operationId, SqlCommand sqlCommand, [CallerMemberName] string operation = "")
public static void WriteCommandAfter(this DiagnosticListener @this, Guid operationId, SqlCommand sqlCommand, SqlTransaction transaction, [CallerMemberName] string operation = "")
{
if (@this.IsEnabled(SqlAfterExecuteCommand))
{
Expand All @@ -73,13 +74,14 @@ public static void WriteCommandAfter(this DiagnosticListener @this, Guid operati
Operation = operation,
ConnectionId = sqlCommand.Connection?.ClientConnectionId,
Command = sqlCommand,
transaction?.InternalTransaction?.TransactionId,
Statistics = sqlCommand.Statistics?.GetDictionary(),
Timestamp = Stopwatch.GetTimestamp()
});
}
}

public static void WriteCommandError(this DiagnosticListener @this, Guid operationId, SqlCommand sqlCommand, Exception ex, [CallerMemberName] string operation = "")
public static void WriteCommandError(this DiagnosticListener @this, Guid operationId, SqlCommand sqlCommand, SqlTransaction transaction, Exception ex, [CallerMemberName] string operation = "")
{
if (@this.IsEnabled(SqlErrorExecuteCommand))
{
Expand All @@ -91,6 +93,7 @@ public static void WriteCommandError(this DiagnosticListener @this, Guid operati
Operation = operation,
ConnectionId = sqlCommand.Connection?.ClientConnectionId,
Command = sqlCommand,
transaction?.InternalTransaction?.TransactionId,
Exception = ex,
Timestamp = Stopwatch.GetTimestamp()
});
Expand All @@ -110,6 +113,7 @@ public static Guid WriteConnectionOpenBefore(this DiagnosticListener @this, SqlC
OperationId = operationId,
Operation = operation,
Connection = sqlConnection,
ClientVersion = ThisAssembly.InformationalVersion,
Timestamp = Stopwatch.GetTimestamp()
});

Expand All @@ -131,6 +135,7 @@ public static void WriteConnectionOpenAfter(this DiagnosticListener @this, Guid
Operation = operation,
ConnectionId = sqlConnection.ClientConnectionId,
Connection = sqlConnection,
ClientVersion = ThisAssembly.InformationalVersion,
Statistics = sqlConnection.Statistics?.GetDictionary(),
Timestamp = Stopwatch.GetTimestamp()
});
Expand All @@ -149,6 +154,7 @@ public static void WriteConnectionOpenError(this DiagnosticListener @this, Guid
Operation = operation,
ConnectionId = sqlConnection.ClientConnectionId,
Connection = sqlConnection,
ClientVersion = ThisAssembly.InformationalVersion,
Exception = ex,
Timestamp = Stopwatch.GetTimestamp()
});
Expand Down Expand Up @@ -216,7 +222,7 @@ public static void WriteConnectionCloseError(this DiagnosticListener @this, Guid
}
}

public static Guid WriteTransactionCommitBefore(this DiagnosticListener @this, IsolationLevel isolationLevel, SqlConnection connection, [CallerMemberName] string operation = "")
public static Guid WriteTransactionCommitBefore(this DiagnosticListener @this, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, [CallerMemberName] string operation = "")
{
if (@this.IsEnabled(SqlBeforeCommitTransaction))
{
Expand All @@ -230,6 +236,7 @@ public static Guid WriteTransactionCommitBefore(this DiagnosticListener @this, I
Operation = operation,
IsolationLevel = isolationLevel,
Connection = connection,
transaction?.TransactionId,
Timestamp = Stopwatch.GetTimestamp()
});

Expand All @@ -239,7 +246,7 @@ public static Guid WriteTransactionCommitBefore(this DiagnosticListener @this, I
return Guid.Empty;
}

public static void WriteTransactionCommitAfter(this DiagnosticListener @this, Guid operationId, IsolationLevel isolationLevel, SqlConnection connection, [CallerMemberName] string operation = "")
public static void WriteTransactionCommitAfter(this DiagnosticListener @this, Guid operationId, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, [CallerMemberName] string operation = "")
{
if (@this.IsEnabled(SqlAfterCommitTransaction))
{
Expand All @@ -251,12 +258,13 @@ public static void WriteTransactionCommitAfter(this DiagnosticListener @this, Gu
Operation = operation,
IsolationLevel = isolationLevel,
Connection = connection,
transaction?.TransactionId,
Timestamp = Stopwatch.GetTimestamp()
});
}
}

public static void WriteTransactionCommitError(this DiagnosticListener @this, Guid operationId, IsolationLevel isolationLevel, SqlConnection connection, Exception ex, [CallerMemberName] string operation = "")
public static void WriteTransactionCommitError(this DiagnosticListener @this, Guid operationId, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, Exception ex, [CallerMemberName] string operation = "")
{
if (@this.IsEnabled(SqlErrorCommitTransaction))
{
Expand All @@ -268,13 +276,14 @@ public static void WriteTransactionCommitError(this DiagnosticListener @this, Gu
Operation = operation,
IsolationLevel = isolationLevel,
Connection = connection,
transaction?.TransactionId,
Exception = ex,
Timestamp = Stopwatch.GetTimestamp()
});
}
}

public static Guid WriteTransactionRollbackBefore(this DiagnosticListener @this, IsolationLevel isolationLevel, SqlConnection connection, string transactionName, [CallerMemberName] string operation = "")
public static Guid WriteTransactionRollbackBefore(this DiagnosticListener @this, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, string transactionName = null, [CallerMemberName] string operation = "")
{
if (@this.IsEnabled(SqlBeforeRollbackTransaction))
{
Expand All @@ -288,6 +297,7 @@ public static Guid WriteTransactionRollbackBefore(this DiagnosticListener @this,
Operation = operation,
IsolationLevel = isolationLevel,
Connection = connection,
transaction?.TransactionId,
TransactionName = transactionName,
Timestamp = Stopwatch.GetTimestamp()
});
Expand All @@ -298,7 +308,7 @@ public static Guid WriteTransactionRollbackBefore(this DiagnosticListener @this,
return Guid.Empty;
}

public static void WriteTransactionRollbackAfter(this DiagnosticListener @this, Guid operationId, IsolationLevel isolationLevel, SqlConnection connection, string transactionName, [CallerMemberName] string operation = "")
public static void WriteTransactionRollbackAfter(this DiagnosticListener @this, Guid operationId, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, string transactionName = null, [CallerMemberName] string operation = "")
{
if (@this.IsEnabled(SqlAfterRollbackTransaction))
{
Expand All @@ -310,13 +320,14 @@ public static void WriteTransactionRollbackAfter(this DiagnosticListener @this,
Operation = operation,
IsolationLevel = isolationLevel,
Connection = connection,
transaction?.TransactionId,
TransactionName = transactionName,
Timestamp = Stopwatch.GetTimestamp()
});
}
}

public static void WriteTransactionRollbackError(this DiagnosticListener @this, Guid operationId, IsolationLevel isolationLevel, SqlConnection connection, string transactionName, Exception ex, [CallerMemberName] string operation = "")
public static void WriteTransactionRollbackError(this DiagnosticListener @this, Guid operationId, IsolationLevel isolationLevel, SqlConnection connection, SqlInternalTransaction transaction, Exception ex, string transactionName = null, [CallerMemberName] string operation = "")
{
if (@this.IsEnabled(SqlErrorRollbackTransaction))
{
Expand All @@ -328,6 +339,7 @@ public static void WriteTransactionRollbackError(this DiagnosticListener @this,
Operation = operation,
IsolationLevel = isolationLevel,
Connection = connection,
transaction?.TransactionId,
TransactionName = transactionName,
Exception = ex,
Timestamp = Stopwatch.GetTimestamp()
Expand Down
Loading