Repository navigation
feat(spanner): support custom OpenTelemetry MeterProvider - #19304
Open
sakthivelmanii wants to merge 4 commits into
Open
sakthivelmanii wants to merge 4 commits into
sakthivelmanii wants to merge 4 commits into
Conversation
…bility_options
## Problem Statement
- `google-cloud-spanner` only exported built-in Client Side Metrics (CSM) through the process-global OpenTelemetry `MeterProvider` configured for Google Cloud Monitoring, with no way for Cloud Spanner or Spanner Omni users to supply their own OpenTelemetry `MeterProvider` (for example, an OTLP exporter or a Cloud Monitoring exporter with dedicated credentials).
- Creating a Spanner Omni client (`instance_type="omni"`) disabled the process-global metrics factory, breaking CSM export for sibling Cloud Spanner clients in the same process, and left Spanner Omni data transports without metrics interception.
## Solution
- Added support for `observability_options={"meter_provider": meter_provider}` on sync and async `Client` instances, with eager validation (`TypeError` if `meter_provider` lacks a callable `get_meter` method).
- Isolated per-client metrics recording using client-scoped factories (sharing process-level `client_uid` and `client_hash`) so Omni and Emulator clients no longer mutate the process-global metrics state or interfere with sibling Cloud Spanner clients.
- Kept default Cloud Monitoring CSM export disabled on Spanner Omni while allowing a custom `meter_provider` to act as the sole sink (independent of `disable_builtin_metrics` / `SPANNER_DISABLE_BUILTIN_METRICS`).
- Supported additive recording to both default CSM (Cloud Monitoring) and a custom `meter_provider` on Cloud Spanner (with identity deduplication and warn-once per-sink error isolation), while keeping both disabled on the Spanner Emulator.
- Attached metrics interception to Spanner Omni sync and async data transports (omitted on admin transports) and gated interception on the active tracer's `enabled` state.
- Documented custom `meter_provider` configuration and added unit tests covering Spanner Omni, Cloud Spanner, and Emulator modes.
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces support for custom OpenTelemetry MeterProvider configurations in both the synchronous and asynchronous Google Cloud Spanner clients. Users can now pass a custom meter_provider via observability_options to export built-in client metrics to their own OpenTelemetry exporters. The changes include updates to the metrics tracer factory to support client-scoped factories, integration of metrics interceptors in Spanner Omni transports, and comprehensive unit tests validating the isolation, additive behavior, and error handling of the custom meter providers. I have no feedback to provide.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem Statement
google-cloud-spanneronly exported built-in Client Side Metrics (CSM) through the process-global OpenTelemetryMeterProviderconfigured for Google Cloud Monitoring, with no way for Cloud Spanner or Spanner Omni users to supply their own OpenTelemetryMeterProvider(for example, an OTLP exporter or a Cloud Monitoring exporter with dedicated credentials).instance_type="omni") disabled the process-global metrics factory, breaking CSM export for sibling Cloud Spanner clients in the same process, and left Spanner Omni data transports without metrics interception.Solution
observability_options={"meter_provider": meter_provider}on sync and asyncClientinstances, with eager validation (TypeErrorifmeter_providerlacks a callableget_metermethod).client_uidandclient_hash) so Omni and env-configured Emulator clients no longer mutate the process-global metrics state or interfere with sibling Cloud Spanner clients.meter_providerto act as the sole sink (independent ofdisable_builtin_metrics/SPANNER_DISABLE_BUILTIN_METRICS).meter_provideron Cloud Spanner (with identity deduplication and warn-once per-sink error isolation).SPANNER_EMULATOR_HOSTclients and forAnonymousCredentials+ custom endpoint clients when a custommeter_provideris supplied, while preserving the existing process-wide built-in metrics path forAnonymousCredentials+ custom endpoint clients when nometer_provideris provided.enabledstate.meter_providerconfiguration and added unit tests covering Spanner Omni, Cloud Spanner, and Emulator modes.