@@ -98,7 +98,7 @@ def _constructor_test_helper(
9898 query_options = query_options ,
9999 directed_read_options = directed_read_options ,
100100 default_transaction_options = default_transaction_options ,
101- ** kwargs
101+ ** kwargs ,
102102 )
103103
104104 expected_creds = expected_creds or creds .with_scopes .return_value
@@ -329,6 +329,62 @@ def test_constructor_w_default_transaction_options(self):
329329 default_transaction_options = self .DEFAULT_TRANSACTION_OPTIONS ,
330330 )
331331
332+ def test_constructor_logs_options (self ):
333+ from google .cloud .spanner_v1 import client as MUT
334+
335+ creds = build_scoped_credentials ()
336+ observability_options = {"enable_extended_tracing" : True }
337+ with self .assertLogs (MUT .__name__ , level = "INFO" ) as cm :
338+ client = self ._make_one (
339+ project = self .PROJECT ,
340+ credentials = creds ,
341+ route_to_leader_enabled = False ,
342+ directed_read_options = self .DIRECTED_READ_OPTIONS ,
343+ default_transaction_options = self .DEFAULT_TRANSACTION_OPTIONS ,
344+ observability_options = observability_options ,
345+ )
346+ self .assertIsNotNone (client )
347+
348+ self .assertEqual (len (cm .output ), 1 )
349+ log_output = cm .output [0 ]
350+ self .assertIn ("Spanner options:" , log_output )
351+ self .assertIn (f"\n Project ID: { self .PROJECT } " , log_output )
352+ self .assertIn ("\n Host: spanner.googleapis.com" , log_output )
353+ self .assertIn ("\n Route to leader enabled: False" , log_output )
354+ self .assertIn (
355+ f"\n Directed read options: { self .DIRECTED_READ_OPTIONS } " , log_output
356+ )
357+ self .assertIn (
358+ f"\n Default transaction options: { self .DEFAULT_TRANSACTION_OPTIONS } " ,
359+ log_output ,
360+ )
361+ self .assertIn (f"\n Observability options: { observability_options } " , log_output )
362+ # SPANNER_DISABLE_BUILTIN_METRICS is "true" from class-level patch
363+ self .assertIn ("\n Built-in metrics enabled: False" , log_output )
364+
365+ # Test with custom host
366+ endpoint = "test.googleapis.com"
367+ with self .assertLogs (MUT .__name__ , level = "INFO" ) as cm :
368+ self ._make_one (
369+ project = self .PROJECT ,
370+ credentials = creds ,
371+ client_options = {"api_endpoint" : endpoint },
372+ )
373+
374+ self .assertEqual (len (cm .output ), 1 )
375+ log_output = cm .output [0 ]
376+ self .assertIn (f"\n Host: { endpoint } " , log_output )
377+
378+ # Test with emulator host
379+ emulator_host = "localhost:9010"
380+ with mock .patch .dict (os .environ , {MUT .EMULATOR_ENV_VAR : emulator_host }):
381+ with self .assertLogs (MUT .__name__ , level = "INFO" ) as cm :
382+ self ._make_one (project = self .PROJECT )
383+
384+ self .assertEqual (len (cm .output ), 1 )
385+ log_output = cm .output [0 ]
386+ self .assertIn (f"\n Host: { emulator_host } " , log_output )
387+
332388 @mock .patch ("google.cloud.spanner_v1.client._get_spanner_emulator_host" )
333389 def test_instance_admin_api (self , mock_em ):
334390 from google .cloud .spanner_v1 .client import SPANNER_ADMIN_SCOPE
0 commit comments