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

Proof of concept: OpenTelemetry metrics #2409

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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 @@ -10,6 +10,7 @@
using Microsoft.Data.Common;
using System;
using Microsoft.Data.SqlClient;
using Microsoft.Data.SqlClient.Telemetry;

namespace Microsoft.Data.ProviderBase
{
Expand Down Expand Up @@ -90,6 +91,32 @@ public void ClearPool(DbConnectionPoolKey key)
}
}

public Dictionary<string, DbConnectionFactoryTelemetry> GetFactoryMetrics()
{
Dictionary<DbConnectionPoolKey, DbConnectionPoolGroup> connectionPoolGroups = _connectionPoolGroups;
Dictionary<string, DbConnectionFactoryTelemetry> telemetry = new(connectionPoolGroups.Count);

foreach (DbConnectionPoolGroup poolGroup in connectionPoolGroups.Values)
{
// This will ensure that the connection string has does not reveal its credentials
string connectionString = poolGroup.ConnectionOptions.UsersConnectionStringForTrace();

// This will return true if the connection string uses integrated authentication and a second connection has
// been opened in an impersonated context. The specification doesn't handle this well, so the only thing to
// do is to roll all of the contexts up into a single connection string.
if (telemetry.ContainsKey(connectionString))
{
telemetry[connectionString].AddConnectionPool(poolGroup.Telemetry);
}
else
{
telemetry.Add(connectionString, new DbConnectionFactoryTelemetry(poolGroup.Telemetry));
}
}

return telemetry;
}

internal virtual DbConnectionPoolProviderInfo CreateConnectionPoolProviderInfo(DbConnectionOptions connectionOptions)
{
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,24 @@
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Server\SqlRecordBuffer.cs">
<Link>Microsoft\Data\SqlClient\Server\SqlRecordBuffer.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Telemetry\ComponentTelemetry.cs">
<Link>Microsoft\Data\SqlClient\Telemetry\ComponentTelemetry.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Telemetry\MetricConstants.cs">
<Link>Microsoft\Data\SqlClient\Telemetry\MetricConstants.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Telemetry\SqlClientMetrics.cs">
<Link>Microsoft\Data\SqlClient\Telemetry\SqlClientMetrics.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Telemetry\SqlClientTelemetry.cs">
<Link>Microsoft\Data\SqlClient\Telemetry\SqlClientTelemetry.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Telemetry\DbConnectionFactoryTelemetry.cs">
<Link>Microsoft\Data\SqlClient\Telemetry\DbConnectionFactoryTelemetry.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\Telemetry\TelemetryInterfaces.cs">
<Link>Microsoft\Data\SqlClient\Telemetry\TelemetryInterfaces.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SqlTransaction.Common.cs">
<Link>Microsoft\Data\SqlClient\SqlTransaction.Common.cs</Link>
</Compile>
Expand Down Expand Up @@ -646,6 +664,7 @@
<Compile Include="Microsoft\Data\SqlClient\SNI\SslOverTdsStream.cs" />
<Compile Include="Microsoft\Data\SqlClient\SNI\SNICommon.cs" />
<Compile Include="Microsoft\Data\SqlClient\SNI\SSRP.cs" />
<Compile Include="Microsoft\Data\SqlClient\Telemetry\SqlClientMetrics.NetCoreApp.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlAppContextSwitchManager.NetCoreApp.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlAuthenticationProviderManager.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlBulkCopy.cs" />
Expand Down Expand Up @@ -991,7 +1010,6 @@
<ItemGroup Condition="'$(TargetGroup)' == 'netstandard'">
<PackageReference Condition="'$(TargetsWindows)' == 'true' and '$(IsUAPAssembly)' != 'true'" Include="Microsoft.Win32.Registry" Version="$(MicrosoftWin32RegistryVersion)" />
<PackageReference Include="System.Security.Principal.Windows" Version="$(SystemSecurityPrincipalWindowsVersion)" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="$(SystemDiagnosticsDiagnosticSourceVersion)" />
<PackageReference Include="System.Buffers" Version="$(SystemBuffersVersion)" />
<PackageReference Include="System.Runtime.Loader" Version="$(SystemRuntimeLoaderVersion)" />
<PackageReference Include="System.Security.Cryptography.Cng" Version="$(SystemSecurityCryptographyCngVersion)" />
Expand All @@ -1001,6 +1019,9 @@
<PackageReference Include="System.Security.Permissions" Version="$(SystemSecurityPermissionsVersion)" />
<PackageReference Include="System.Runtime.Caching" Version="$(SystemRuntimeCachingVersion)" />
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)' == 'netstandard' OR '$(TargetFramework)' == 'net6.0'">
<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="$(SystemDiagnosticsDiagnosticSourceVersion)" />
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)' == 'netcoreapp'">
<PackageReference Include="System.Configuration.ConfigurationManager" Version="$(SystemConfigurationConfigurationManagerVersion)" />
<PackageReference Include="System.Runtime.Caching" Version="$(SystemRuntimeCachingVersion)" />
Expand Down
Loading
Loading