Skip to content

Commit a93f86a

Browse files
authored
Fix | Revert Event source changes on TryBeginExecuteEvent and WriteEndExecuteEvent to address the failure on other MS products. (#1258)
1 parent 831287f commit a93f86a

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6581,7 +6581,7 @@ public SqlCommand Clone()
65816581

65826582
private void WriteBeginExecuteEvent()
65836583
{
6584-
SqlClientEventSource.Log.TryBeginExecuteEvent(ObjectID, Connection?.ClientConnectionId, CommandText);
6584+
SqlClientEventSource.Log.TryBeginExecuteEvent(ObjectID, Connection?.DataSource, Connection?.Database, CommandText, Connection?.ClientConnectionId);
65856585
}
65866586

65876587
private void WriteEndExecuteEvent(bool success, int? sqlExceptionNumber, bool synchronous)
@@ -6602,7 +6602,7 @@ private void WriteEndExecuteEvent(bool success, int? sqlExceptionNumber, bool sy
66026602

66036603
int compositeState = successFlag | isSqlExceptionFlag | synchronousFlag;
66046604

6605-
SqlClientEventSource.Log.TryEndExecuteEvent(ObjectID, Connection?.ClientConnectionId, compositeState, sqlExceptionNumber.GetValueOrDefault());
6605+
SqlClientEventSource.Log.TryEndExecuteEvent(ObjectID, compositeState, sqlExceptionNumber.GetValueOrDefault(), Connection?.ClientConnectionId);
66066606
}
66076607
}
66086608
}

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlCommand.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ protected override DbParameterCollection DbParameterCollection
915915
return Parameters;
916916
}
917917
}
918-
918+
919919
internal static void CancelIgnoreFailureCallback(object state)
920920
{
921921
SqlCommand command = (SqlCommand)state;
@@ -3012,9 +3012,9 @@ protected override Task<DbDataReader> ExecuteDbDataReaderAsync(CommandBehavior b
30123012
throw result.Exception.InnerException;
30133013
}
30143014
return result.Result;
3015-
},
3016-
CancellationToken.None,
3017-
TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.NotOnCanceled,
3015+
},
3016+
CancellationToken.None,
3017+
TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.NotOnCanceled,
30183018
TaskScheduler.Default
30193019
);
30203020
}
@@ -7611,7 +7611,7 @@ private SmiRequestExecutor SetUpSmiRequest(SqlInternalConnectionSmi innerConnect
76117611

76127612
private void WriteBeginExecuteEvent()
76137613
{
7614-
SqlClientEventSource.Log.TryBeginExecuteEvent(ObjectID, Connection?.ClientConnectionId, CommandText);
7614+
SqlClientEventSource.Log.TryBeginExecuteEvent(ObjectID, Connection?.DataSource, Connection?.Database, CommandText, Connection?.ClientConnectionId);
76157615
}
76167616

76177617
/// <summary>
@@ -7638,7 +7638,7 @@ private void WriteEndExecuteEvent(bool success, int? sqlExceptionNumber, bool sy
76387638

76397639
int compositeState = successFlag | isSqlExceptionFlag | synchronousFlag;
76407640

7641-
SqlClientEventSource.Log.TryEndExecuteEvent(ObjectID, Connection?.ClientConnectionId, compositeState, sqlExceptionNumber.GetValueOrDefault());
7641+
SqlClientEventSource.Log.TryEndExecuteEvent(ObjectID, compositeState, sqlExceptionNumber.GetValueOrDefault(), Connection?.ClientConnectionId);
76427642
}
76437643
}
76447644

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlClientEventSource.cs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ internal virtual void ReclaimedConnectionRequest() { /*no-op*/ }
6868
#endregion
6969
}
7070

71+
// Any changes to event writers might be considered as a breaking change.
72+
// Other libraries such as OpenTelemetry and ApplicationInsight have based part of their code on BeginExecute and EndExecute arguments number.
7173
[EventSource(Name = "Microsoft.Data.SqlClient.EventSource")]
7274
internal partial class SqlClientEventSource : SqlClientEventSourceBase
7375
{
@@ -510,22 +512,20 @@ internal void TryScopeLeaveEvent(long scopeId)
510512

511513
#region Execution Trace
512514
[NonEvent]
513-
internal void TryBeginExecuteEvent(int objectId, Guid? connectionId, string commandText, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "")
515+
internal void TryBeginExecuteEvent(int objectId, string dataSource, string database, string commandText, Guid? connectionId, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "")
514516
{
515517
if (Log.IsExecutionTraceEnabled())
516518
{
517-
BeginExecute(GetFormattedMessage(SqlCommand_ClassName, memberName, EventType.INFO,
518-
string.Format("Object Id {0}, Client Connection Id {1}, Command Text {2}", objectId, connectionId, commandText)));
519+
BeginExecute(objectId, dataSource, database, commandText, GetFormattedMessage(SqlCommand_ClassName, memberName, EventType.INFO, $"Object Id {objectId}, Client connection Id {connectionId}, Command Text {commandText}"));
519520
}
520521
}
521522

522523
[NonEvent]
523-
internal void TryEndExecuteEvent(int objectId, Guid? connectionId, int compositeState, int sqlExceptionNumber, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "")
524+
internal void TryEndExecuteEvent(int objectId, int compositeState, int sqlExceptionNumber, Guid? connectionId, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "")
524525
{
525526
if (Log.IsExecutionTraceEnabled())
526527
{
527-
EndExecute(GetFormattedMessage(SqlCommand_ClassName, memberName, EventType.INFO,
528-
string.Format("Object Id {0}, Client Connection Id {1}, Composite State {2}, Sql Exception Number {3}", objectId, connectionId, compositeState, sqlExceptionNumber)));
528+
EndExecute(objectId, compositeState, sqlExceptionNumber, GetFormattedMessage(SqlCommand_ClassName, memberName, EventType.INFO, $"Object Id {objectId}, Client Connection Id {connectionId}, Composite State {compositeState}, Sql Exception Number {sqlExceptionNumber}"));
529529
}
530530
}
531531
#endregion
@@ -995,13 +995,22 @@ internal void TrySNIScopeLeaveEvent(long scopeId)
995995
#endregion
996996

997997
#region Write Events
998+
// Do not change the first 4 arguments in this Event writer as OpenTelemetry and ApplicationInsight are relating to the same format,
999+
// unless you have checked with them and they are able to change their design. Additional items could be added at the end.
9981000
[Event(BeginExecuteEventId, Keywords = Keywords.ExecutionTrace, Task = Tasks.ExecuteCommand, Opcode = EventOpcode.Start)]
999-
internal void BeginExecute(string message) =>
1000-
WriteEvent(BeginExecuteEventId, message);
1001+
internal void BeginExecute(int objectId, string dataSource, string database, string commandText, string message)
1002+
{
1003+
WriteEvent(BeginExecuteEventId, objectId, dataSource, database, commandText, message);
1004+
}
10011005

1006+
// Do not change the first 3 arguments in this Event writer as OpenTelemetry and ApplicationInsight are relating to the same format,
1007+
// unless you have checked with them and they are able to change their design. Additional items could be added at the end.
10021008
[Event(EndExecuteEventId, Keywords = Keywords.ExecutionTrace, Task = Tasks.ExecuteCommand, Opcode = EventOpcode.Stop)]
1003-
internal void EndExecute(string message) =>
1004-
WriteEvent(EndExecuteEventId, message);
1009+
internal void EndExecute(int objectId, int compositestate, int sqlExceptionNumber, string message)
1010+
{
1011+
1012+
WriteEvent(EndExecuteEventId, objectId, compositestate, sqlExceptionNumber, message);
1013+
}
10051014

10061015
[Event(TraceEventId, Level = EventLevel.Informational, Keywords = Keywords.Trace)]
10071016
internal void Trace(string message) =>
@@ -1106,7 +1115,7 @@ internal static class EventType
11061115
public const string INFO = " | INFO | ";
11071116
public const string ERR = " | ERR | ";
11081117
}
1109-
1118+
11101119
internal readonly struct TrySNIEventScope : IDisposable
11111120
{
11121121
private readonly long _scopeId;

0 commit comments

Comments
 (0)