Skip to content

feat(spanner): log client configuration at startup#17040

Draft
sinhasubham wants to merge 1 commit into
mainfrom
client_config
Draft

feat(spanner): log client configuration at startup#17040
sinhasubham wants to merge 1 commit into
mainfrom
client_config

Conversation

@sinhasubham
Copy link
Copy Markdown
Contributor

This is an already reviewed change as part of this PR in old repo.

This change introduces logging for Spanner client options upon initialization.

This allows customers to easily capture and inspect the configuration being used, which is valuable for debugging and verification.

This feature mirrors the existing logSpannerOptions functionality in the Java client, improving consistency across client libraries. googleapis/java-spanner#4141

@sinhasubham sinhasubham changed the title Client config feat(spanner): log client configuration at startup May 12, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request replaces pickle with json in partition_helper.py to improve security and introduces a feature to log Spanner client options via an environment variable. Review feedback recommends internalizing the host attribute to _host to avoid naming conflicts and suggests using public properties instead of private attributes for logging to improve consistency.

Comment on lines +321 to +327
self.host = "spanner.googleapis.com"
if self._emulator_host:
self.host = self._emulator_host
elif self._experimental_host:
self.host = self._experimental_host
elif self._client_options and self._client_options.api_endpoint:
self.host = self._client_options.api_endpoint
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The attribute host is quite generic and might conflict with future changes in base classes or subclasses. Since it is primarily used for logging client options here, it should be prefixed with an underscore to indicate it is internal.

Suggested change
self.host = "spanner.googleapis.com"
if self._emulator_host:
self.host = self._emulator_host
elif self._experimental_host:
self.host = self._experimental_host
elif self._client_options and self._client_options.api_endpoint:
self.host = self._client_options.api_endpoint
self._host = "spanner.googleapis.com"
if self._emulator_host:
self._host = self._emulator_host
elif self._experimental_host:
self._host = self._experimental_host
elif self._client_options and self._client_options.api_endpoint:
self._host = self._client_options.api_endpoint

Comment on lines +334 to +342
"Spanner options: \n Project ID: %s\n Host: %s\n Route to leader enabled: %s\n Directed read options: %s\n Default transaction options: %s\n Observability options: %s\n Built-in metrics enabled: %s",
self.project,
self.host,
self.route_to_leader_enabled,
self._directed_read_options,
self._default_transaction_options,
self._observability_options,
_get_spanner_enable_builtin_metrics_env(),
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better readability and consistency with the asynchronous client implementation, consider breaking the log format string into multiple lines. Additionally, prefer using public properties instead of private attributes (e.g., directed_read_options instead of _directed_read_options) where available.

        log.info(
            "Spanner options: \n"
            "  Project ID: %s\n"
            "  Host: %s\n"
            "  Route to leader enabled: %s\n"
            "  Directed read options: %s\n"
            "  Default transaction options: %s\n"
            "  Observability options: %s\n"
            "  Built-in metrics enabled: %s",
            self.project,
            self._host,
            self.route_to_leader_enabled,
            self.directed_read_options,
            self.default_transaction_options,
            self.observability_options,
            _get_spanner_enable_builtin_metrics_env(),
        )

Comment on lines +372 to +378
self.host = "spanner.googleapis.com"
if self._emulator_host:
self.host = self._emulator_host
elif self._experimental_host:
self.host = self._experimental_host
elif self._client_options and self._client_options.api_endpoint:
self.host = self._client_options.api_endpoint
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The attribute host is quite generic and might conflict with future changes in base classes or subclasses. Since it is primarily used for logging client options here, it should be prefixed with an underscore to indicate it is internal.

Suggested change
self.host = "spanner.googleapis.com"
if self._emulator_host:
self.host = self._emulator_host
elif self._experimental_host:
self.host = self._experimental_host
elif self._client_options and self._client_options.api_endpoint:
self.host = self._client_options.api_endpoint
self._host = "spanner.googleapis.com"
if self._emulator_host:
self._host = self._emulator_host
elif self._experimental_host:
self._host = self._experimental_host
elif self._client_options and self._client_options.api_endpoint:
self._host = self._client_options.api_endpoint

Comment on lines +395 to +399
self.host,
self.route_to_leader_enabled,
self._directed_read_options,
self._default_transaction_options,
self._observability_options,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Prefer using public properties instead of private attributes (e.g., directed_read_options instead of _directed_read_options) where available for logging.

Suggested change
self.host,
self.route_to_leader_enabled,
self._directed_read_options,
self._default_transaction_options,
self._observability_options,
self._host,
self.route_to_leader_enabled,
self.directed_read_options,
self.default_transaction_options,
self.observability_options,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant