Skip to content

feat(spanner): support custom OpenTelemetry MeterProvider - #19304

Open
sakthivelmanii wants to merge 4 commits into
mainfrom
feat/omni-custom-meter-provider
Open

sakthivelmanii wants to merge 4 commits into
mainfrom
feat/omni-custom-meter-provider

Conversation

@sakthivelmanii

@sakthivelmanii sakthivelmanii commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

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 env-configured 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).
  • Disabled metrics for SPANNER_EMULATOR_HOST clients and for AnonymousCredentials + custom endpoint clients when a custom meter_provider is supplied, while preserving the existing process-wide built-in metrics path for AnonymousCredentials + custom endpoint clients when no meter_provider is provided.
  • 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.

…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.
@sakthivelmanii
sakthivelmanii requested a review from a team as a code owner December 2, 2026 12:02
@sakthivelmanii sakthivelmanii changed the title feat(spanner): support custom OpenTelemetry MeterProvider via observability_options feat(spanner): support custom OpenTelemetry MeterProvider Dec 2, 2026

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

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.

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

No deployments
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