Skip to content

Commit d7f84eb

Browse files
authored
Add scope trace for GenerateSspiClientContext (#2497)
1 parent c822b69 commit d7f84eb

File tree

10 files changed

+23
-19
lines changed

10 files changed

+23
-19
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Common/src/Microsoft/Data/ProviderBase/DbConnectionFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ abstract public DbProviderFactory ProviderFactory
4949

5050
public void ClearAllPools()
5151
{
52-
using (TryEventScope.Create("<prov.DbConnectionFactory.ClearAllPools|API"))
52+
using (TryEventScope.Create(nameof(DbConnectionFactory)))
5353
{
5454
Dictionary<DbConnectionPoolKey, DbConnectionPoolGroup> connectionPoolGroups = _connectionPoolGroups;
5555
foreach (KeyValuePair<DbConnectionPoolKey, DbConnectionPoolGroup> entry in connectionPoolGroups)

src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<NoWarn>$(NoWarn);IL2026;IL2057;IL2072;IL2075</NoWarn>
2121
</PropertyGroup>
2222
<PropertyGroup>
23-
<TargetFrameworkMonikerAssemblyAttributesPath>$([System.IO.Path]::Combine('$(IntermediateOutputPath)','$(TargetFramework)','$(TargetFrameworkMoniker).AssemblyAttributes$(DefaultLanguageSourceExtension)'))</TargetFrameworkMonikerAssemblyAttributesPath>
23+
<TargetFrameworkMonikerAssemblyAttributesPath>$([System.IO.Path]::Combine('$(IntermediateOutputPath)','$(TargetFrameworkMoniker).AssemblyAttributes$(DefaultLanguageSourceExtension)'))</TargetFrameworkMonikerAssemblyAttributesPath>
2424
</PropertyGroup>
2525
<ItemGroup>
2626
<EmbeddedFiles Include="$(GeneratedAssemblyInfoFile)" />

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNICommon.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ internal class SNICommon
151151
/// <returns>True if certificate is valid</returns>
152152
internal static bool ValidateSslServerCertificate(Guid connectionId, string targetServerName, string hostNameInCertificate, X509Certificate serverCert, string validationCertFileName, SslPolicyErrors policyErrors)
153153
{
154-
using (TrySNIEventScope.Create("SNICommon.ValidateSslServerCertificate | SNI | SCOPE | INFO | Entering Scope {0} "))
154+
using (TrySNIEventScope.Create(nameof(SNICommon)))
155155
{
156156
if (policyErrors == SslPolicyErrors.None)
157157
{
@@ -292,7 +292,7 @@ internal static bool ValidateSslServerCertificate(Guid connectionId, string targ
292292

293293
internal static IPAddress[] GetDnsIpAddresses(string serverName, TimeoutTimer timeout)
294294
{
295-
using (TrySNIEventScope.Create(nameof(GetDnsIpAddresses)))
295+
using (TrySNIEventScope.Create(nameof(SNICommon)))
296296
{
297297
int remainingTimeout = timeout.MillisecondsRemainingInt;
298298
SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNICommon), EventType.INFO,
@@ -310,7 +310,7 @@ internal static IPAddress[] GetDnsIpAddresses(string serverName, TimeoutTimer ti
310310

311311
internal static IPAddress[] GetDnsIpAddresses(string serverName)
312312
{
313-
using (TrySNIEventScope.Create(nameof(GetDnsIpAddresses)))
313+
using (TrySNIEventScope.Create(nameof(SNICommon)))
314314
{
315315
SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNICommon), EventType.INFO, "Getting DNS host entries for serverName {0}.", args0: serverName);
316316
return Dns.GetHostAddresses(serverName);

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIMarsHandle.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public SNIMarsHandle(SNIMarsConnection connection, ushort sessionId, object call
9494
/// <param name="flags">SMUX header flags</param>
9595
private void SendControlPacket(SNISMUXFlags flags)
9696
{
97-
using (TrySNIEventScope.Create("SNIMarsHandle.SendControlPacket | SNI | INFO | SCOPE | Entering Scope {0}"))
97+
using (TrySNIEventScope.Create(nameof(SNIMarsHandle)))
9898
{
9999
SNIPacket packet = RentPacket(headerSize: SNISMUXHeader.HEADER_LENGTH, dataSize: 0);
100100
#if DEBUG
@@ -195,7 +195,7 @@ public override uint Send(SNIPacket packet)
195195
private uint InternalSendAsync(SNIPacket packet)
196196
{
197197
Debug.Assert(packet.ReservedHeaderSize == SNISMUXHeader.HEADER_LENGTH, "mars handle attempting to send muxed packet without smux reservation in InternalSendAsync");
198-
using (TrySNIEventScope.Create("SNIMarsHandle.InternalSendAsync | SNI | INFO | SCOPE | Entering Scope {0}"))
198+
using (TrySNIEventScope.Create(nameof(SNIMarsHandle)))
199199
{
200200
lock (this)
201201
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,7 @@ internal void ThrowExceptionAndWarning(TdsParserStateObject stateObj, SqlCommand
14481448

14491449
internal SqlError ProcessSNIError(TdsParserStateObject stateObj)
14501450
{
1451-
using (TryEventScope.Create("<sc.TdsParser.ProcessSNIError|ERR>"))
1451+
using (TryEventScope.Create(nameof(TdsParser)))
14521452
{
14531453
#if DEBUG
14541454
// There is an exception here for MARS as its possible that another thread has closed the connection just as we see an error

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/ProviderBase/DbConnectionFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ internal int ObjectID
6565

6666
public void ClearAllPools()
6767
{
68-
using (TryEventScope.Create("<prov.DbConnectionFactory.ClearAllPools|API>"))
68+
using (TryEventScope.Create(nameof(DbConnectionFactory)))
6969
{
7070
Dictionary<DbConnectionPoolKey, DbConnectionPoolGroup> connectionPoolGroups = _connectionPoolGroups;
7171
foreach (KeyValuePair<DbConnectionPoolKey, DbConnectionPoolGroup> entry in connectionPoolGroups)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2759,7 +2759,7 @@ private void IssueSQLDebug(uint option, string machineName, uint pid, uint id, s
27592759
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnection.xml' path='docs/members[@name="SqlConnection"]/ChangePasswordConnectionStringNewPassword/*' />
27602760
public static void ChangePassword(string connectionString, string newPassword)
27612761
{
2762-
using (TryEventScope.Create("<sc.SqlConnection.ChangePassword|API>"))
2762+
using (TryEventScope.Create(nameof(SqlConnection)))
27632763
{
27642764
SqlClientEventSource.Log.TryCorrelationTraceEvent("<sc.SqlConnection.ChangePassword|API|Correlation> ActivityID {0}", ActivityCorrelator.Current);
27652765

@@ -2802,7 +2802,7 @@ public static void ChangePassword(string connectionString, string newPassword)
28022802
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnection.xml' path='/docs/members[@name="SqlConnection"]/ChangePasswordConnectionStringCredentialNewSecurePassword/*' />
28032803
public static void ChangePassword(string connectionString, SqlCredential credential, SecureString newSecurePassword)
28042804
{
2805-
using (TryEventScope.Create("<sc.SqlConnection.ChangePassword|API>"))
2805+
using (TryEventScope.Create(nameof(SqlConnection)))
28062806
{
28072807
SqlClientEventSource.Log.TryCorrelationTraceEvent("<sc.SqlConnection.ChangePassword|API|Correlation> ActivityID {0}", ActivityCorrelator.Current);
28082808

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SSPI/ManagedSSPIContextProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ internal override void GenerateSspiClientContext(ReadOnlyMemory<byte> received,
1616
_sspiClientContextStatus ??= new SspiClientContextStatus();
1717

1818
SNIProxy.GenSspiClientContext(_sspiClientContextStatus, received, ref sendBuff, _sniSpnBuffer);
19-
SqlClientEventSource.Log.TryTraceEvent("TdsParserStateObjectManaged.GenerateSspiClientContext | Info | Session Id {0}", _physicalStateObj.SessionId);
19+
SqlClientEventSource.Log.TryTraceEvent("{0}.{1} | Info | Session Id {2}", nameof(ManagedSSPIContextProvider), nameof(GenerateSspiClientContext), _physicalStateObj.SessionId);
2020
sendLength = (uint)(sendBuff != null ? sendBuff.Length : 0);
2121
}
2222
}

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SSPI/NegotiateSSPIContextProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ internal override void GenerateSspiClientContext(ReadOnlyMemory<byte> received,
2121
_negotiateAuth ??= new(new NegotiateAuthenticationClientOptions { Package = "Negotiate", TargetName = Encoding.Unicode.GetString(_sniSpnBuffer[i]) });
2222
sendBuff = _negotiateAuth.GetOutgoingBlob(received.Span, out statusCode)!;
2323
// Log session id, status code and the actual SPN used in the negotiation
24-
SqlClientEventSource.Log.TryTraceEvent("TdsParserStateObjectManaged.GenerateSspiClientContext | Info | Session Id {0}, StatusCode={1}, SPN={2}", _physicalStateObj.SessionId, statusCode, _negotiateAuth.TargetName);
24+
SqlClientEventSource.Log.TryTraceEvent("{0}.{1} | Info | Session Id {2}, StatusCode={3}, SPN={4}", nameof(NegotiateSSPIContextProvider),
25+
nameof(GenerateSspiClientContext), _physicalStateObj.SessionId, statusCode, _negotiateAuth.TargetName);
2526
if (statusCode == NegotiateAuthenticationStatusCode.Completed || statusCode == NegotiateAuthenticationStatusCode.ContinueNeeded)
2627
break; // Successful case, exit the loop with current SPN.
2728
else

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SSPI/SSPIContextProvider.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,16 @@ internal void SSPIData(ReadOnlyMemory<byte> receivedBuff, ref byte[] sendBuff, r
3434

3535
internal void SSPIData(ReadOnlyMemory<byte> receivedBuff, ref byte[] sendBuff, ref UInt32 sendLength, byte[][] sniSpnBuffer)
3636
{
37-
try
37+
using (TrySNIEventScope.Create(nameof(SSPIContextProvider)))
3838
{
39-
GenerateSspiClientContext(receivedBuff, ref sendBuff, ref sendLength, sniSpnBuffer);
40-
}
41-
catch (Exception e)
42-
{
43-
SSPIError(e.Message + Environment.NewLine + e.StackTrace, TdsEnums.GEN_CLIENT_CONTEXT);
39+
try
40+
{
41+
GenerateSspiClientContext(receivedBuff, ref sendBuff, ref sendLength, sniSpnBuffer);
42+
}
43+
catch (Exception e)
44+
{
45+
SSPIError(e.Message + Environment.NewLine + e.StackTrace, TdsEnums.GEN_CLIENT_CONTEXT);
46+
}
4447
}
4548
}
4649

0 commit comments

Comments
 (0)