@@ -127,6 +127,29 @@ public async Task ConnectionMax()
127127 Assert . That ( tags [ "db.client.connection.pool.name" ] , Is . EqualTo ( dataSource . Name ) ) ;
128128 }
129129
130+ [ Test ]
131+ public async Task Pool_name_defaults_to_application_name ( )
132+ {
133+ var exportedItems = new List < Metric > ( ) ;
134+ using var meterProvider = Sdk . CreateMeterProviderBuilder ( )
135+ . AddMeter ( "Npgsql" )
136+ . AddInMemoryExporter ( exportedItems )
137+ . Build ( ) ;
138+
139+ var applicationName = "MetricsDataSource" + Interlocked . Increment ( ref _dataSourceCounter ) ;
140+ var dataSourceBuilder = base . CreateDataSourceBuilder ( ) ;
141+ dataSourceBuilder . ConnectionStringBuilder . ApplicationName = applicationName ;
142+ // Do not set the data source name - this makes the pool name default to the Application Name
143+ await using var dataSource = dataSourceBuilder . Build ( ) ;
144+
145+ meterProvider . ForceFlush ( ) ;
146+
147+ var metric = exportedItems . Single ( m => m . Name == "db.client.connection.max" ) ;
148+ var point = GetFilteredPoints ( metric . GetMetricPoints ( ) , dataSource . Name ) . First ( ) ;
149+ var tags = ToDictionary ( point . Tags ) ;
150+ Assert . That ( tags [ "db.client.connection.pool.name" ] , Is . EqualTo ( applicationName ) ) ;
151+ }
152+
130153 [ Test ]
131154 public async Task Password_does_not_leak_via_datasource_name ( [ Values ] bool persistSecurityInfo )
132155 {
@@ -137,10 +160,9 @@ public async Task Password_does_not_leak_via_datasource_name([Values] bool persi
137160 . Build ( ) ;
138161
139162 var dataSourceBuilder = base . CreateDataSourceBuilder ( ) ;
140- dataSourceBuilder . ConnectionStringBuilder . ApplicationName = "MetricsDataSource" + Interlocked . Increment ( ref _dataSourceCounter ) ;
141163 dataSourceBuilder . ConnectionStringBuilder . PersistSecurityInfo = persistSecurityInfo ;
142- // Do not set the data source name - this makes it default to the connection string, but without
143- // the password (even when Persist Security Info is true)
164+ // Do not set the data source name or the application name - this makes the pool name default to the
165+ // connection string, but without the password (even when Persist Security Info is true)
144166 await using var dataSource = dataSourceBuilder . Build ( ) ;
145167
146168 meterProvider . ForceFlush ( ) ;
0 commit comments