@@ -192,7 +192,7 @@ protected override void Load(ContainerBuilder builder)
192192 . As < ISqlConnectionFactory > ( )
193193 . SingleInstance ( ) ;
194194
195- builder . Register ( c => new EntitiesContext ( CreateDbConnection ( galleryDbConnectionFactory ) , configuration . Current . ReadOnlyMode ) )
195+ builder . Register ( c => new EntitiesContext ( CreateDbConnection ( galleryDbConnectionFactory , telemetryService ) , configuration . Current . ReadOnlyMode ) )
196196 . AsSelf ( )
197197 . As < IEntitiesContext > ( )
198198 . As < DbContext > ( )
@@ -278,15 +278,15 @@ protected override void Load(ContainerBuilder builder)
278278 . As < IEntityRepository < PackageRename > > ( )
279279 . InstancePerLifetimeScope ( ) ;
280280
281- ConfigureGalleryReadOnlyReplicaEntitiesContext ( builder , loggerFactory , configuration , secretInjector ) ;
281+ ConfigureGalleryReadOnlyReplicaEntitiesContext ( builder , loggerFactory , configuration , secretInjector , telemetryService ) ;
282282
283283 var supportDbConnectionFactory = CreateDbConnectionFactory (
284284 loggerFactory ,
285285 nameof ( SupportRequestDbContext ) ,
286286 configuration . Current . SqlConnectionStringSupportRequest ,
287287 secretInjector ) ;
288288
289- builder . Register ( c => new SupportRequestDbContext ( CreateDbConnection ( supportDbConnectionFactory ) ) )
289+ builder . Register ( c => new SupportRequestDbContext ( CreateDbConnection ( supportDbConnectionFactory , telemetryService ) ) )
290290 . AsSelf ( )
291291 . As < ISupportRequestDbContext > ( )
292292 . InstancePerLifetimeScope ( ) ;
@@ -503,7 +503,7 @@ protected override void Load(ContainerBuilder builder)
503503 break ;
504504 }
505505
506- RegisterAsynchronousValidation ( builder , loggerFactory , configuration , secretInjector ) ;
506+ RegisterAsynchronousValidation ( builder , loggerFactory , configuration , secretInjector , telemetryService ) ;
507507
508508 RegisterAuditingServices ( builder , configuration . Current . StorageType ) ;
509509
@@ -963,28 +963,35 @@ private static ISqlConnectionFactory CreateDbConnectionFactory(
963963 return new AzureSqlConnectionFactory ( connectionString , secretInjector , logger ) ;
964964 }
965965
966- public static DbConnection CreateDbConnection ( ISqlConnectionFactory connectionFactory )
966+ public static DbConnection CreateDbConnection ( ISqlConnectionFactory connectionFactory , ITelemetryService telemetryService )
967967 {
968- if ( connectionFactory . TryCreate ( out var connection ) )
968+ using ( telemetryService . TrackSyncSqlConnectionCreationDuration ( ) )
969969 {
970- return connection ;
970+ if ( connectionFactory . TryCreate ( out var connection ) )
971+ {
972+ return connection ;
973+ }
974+ }
975+ using ( telemetryService . TrackAsyncSqlConnectionCreationDuration ( ) )
976+ {
977+ return Task . Run ( ( ) => connectionFactory . CreateAsync ( ) ) . Result ;
971978 }
972- return Task . Run ( ( ) => connectionFactory . CreateAsync ( ) ) . Result ;
973979 }
974980
975981 private static void ConfigureGalleryReadOnlyReplicaEntitiesContext (
976982 ContainerBuilder builder ,
977983 ILoggerFactory loggerFactory ,
978984 ConfigurationService configuration ,
979- ICachingSecretInjector secretInjector )
985+ ICachingSecretInjector secretInjector ,
986+ ITelemetryService telemetryService )
980987 {
981988 var galleryDbReadOnlyReplicaConnectionFactory = CreateDbConnectionFactory (
982989 loggerFactory ,
983990 nameof ( ReadOnlyEntitiesContext ) ,
984991 configuration . Current . SqlReadOnlyReplicaConnectionString ?? configuration . Current . SqlConnectionString ,
985992 secretInjector ) ;
986993
987- builder . Register ( c => new ReadOnlyEntitiesContext ( CreateDbConnection ( galleryDbReadOnlyReplicaConnectionFactory ) ) )
994+ builder . Register ( c => new ReadOnlyEntitiesContext ( CreateDbConnection ( galleryDbReadOnlyReplicaConnectionFactory , telemetryService ) ) )
988995 . As < IReadOnlyEntitiesContext > ( )
989996 . InstancePerLifetimeScope ( ) ;
990997
@@ -997,15 +1004,16 @@ private static void ConfigureValidationEntitiesContext(
9971004 ContainerBuilder builder ,
9981005 ILoggerFactory loggerFactory ,
9991006 ConfigurationService configuration ,
1000- ICachingSecretInjector secretInjector )
1007+ ICachingSecretInjector secretInjector ,
1008+ ITelemetryService telemetryService )
10011009 {
10021010 var validationDbConnectionFactory = CreateDbConnectionFactory (
10031011 loggerFactory ,
10041012 nameof ( ValidationEntitiesContext ) ,
10051013 configuration . Current . SqlConnectionStringValidation ,
10061014 secretInjector ) ;
10071015
1008- builder . Register ( c => new ValidationEntitiesContext ( CreateDbConnection ( validationDbConnectionFactory ) ) )
1016+ builder . Register ( c => new ValidationEntitiesContext ( CreateDbConnection ( validationDbConnectionFactory , telemetryService ) ) )
10091017 . AsSelf ( )
10101018 . InstancePerLifetimeScope ( ) ;
10111019
@@ -1026,7 +1034,8 @@ private void RegisterAsynchronousValidation(
10261034 ContainerBuilder builder ,
10271035 ILoggerFactory loggerFactory ,
10281036 ConfigurationService configuration ,
1029- ICachingSecretInjector secretInjector )
1037+ ICachingSecretInjector secretInjector ,
1038+ ITelemetryService telemetryService )
10301039 {
10311040 builder
10321041 . RegisterType < NuGet . Services . Validation . ServiceBusMessageSerializer > ( )
@@ -1052,7 +1061,7 @@ private void RegisterAsynchronousValidation(
10521061
10531062 if ( configuration . Current . AsynchronousPackageValidationEnabled )
10541063 {
1055- ConfigureValidationEntitiesContext ( builder , loggerFactory , configuration , secretInjector ) ;
1064+ ConfigureValidationEntitiesContext ( builder , loggerFactory , configuration , secretInjector , telemetryService ) ;
10561065
10571066 builder
10581067 . Register ( c =>
0 commit comments