GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(spanner): support user-provided OpenTelemetry for client metrics export by rahul2393 · Pull Request #13679 · googleapis/google-cloud-java

Conversation

@rahul2393

@rahul2393 rahul2393 commented Jul 7, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Summary

Adds Client Metrics: a new, opt-in feature that exports Spanner's client-side metrics to a caller-provided OpenTelemetry pipeline (OTLP, Prometheus, any exporter), including on Spanner Omni where the existing Cloud Monitoring metrics are unavailable.

Fully opt-in and fully decoupled from the existing built-in (Cloud Monitoring) metrics. Default behavior is unchanged: without a client-metrics provider, nothing new happens, and built-in metrics continue to export to Cloud Monitoring exactly as before.

Scope note: This change was split out of a larger PR into two focused PRs. This PR contains only the Client Metrics export feature. The optional endpoint metric attribute for location-aware routing is a separate follow-up: #13740.

Two independent features

  • Built-in metrics (existing, unchanged): export to Google Cloud Monitoring. Controlled by setBuiltInMetricsEnabled and the SPANNER_DISABLE_BUILTIN_METRICS environment variable, exactly as today. Not available on Spanner Omni.
  • Client metrics (new): export the client instruments to a caller-owned OpenTelemetry. Controlled solely by setClientMetricsProvider(...) — a CustomOpenTelemetryMetricsProvider turns it on; NoopMetricsProvider (or no provider) turns it off. Works on all instance types, Omni included.

The two are decoupled: setBuiltInMetricsEnabled and the env var affect only the built-in Cloud Monitoring sink and have no effect on client metrics; the client-metrics provider affects only the caller-owned sink and has no effect on built-in metrics. Under the hood these are the same client instruments, exported under the distinct spanner/client namespace — the difference is the export path, not the metrics.

Emulator handling

Client metrics are not recorded when Spanner is pointed at the emulator. To make that reliable when the emulator is configured programmatically (via setEmulatorHost(...)) and not only through the SPANNER_EMULATOR_HOST environment variable, this PR broadens emulator detection: SpannerOptions.isEmulatorEnabled() now also recognizes the builder-configured emulator host, and the connection-check error message is generalized to describe both the environment-variable and programmatic configuration paths. This gates both the client and Cloud Monitoring metrics sinks off against the emulator using a single detection predicate. Called out explicitly here for reviewer visibility.

Motivation

Client metrics currently export only to Cloud Monitoring, which is unavailable on Spanner Omni. Customers running on Omni (or who standardize on their own observability stack) had no way to receive these metrics. This lets them route the metrics to any OpenTelemetry exporter, independently of the built-in Cloud Monitoring configuration.

API

SdkMeterProviderBuilder meterProviderBuilder = SdkMeterProvider.builder();
SpannerMetrics.configureMeterProviderBuilder(meterProviderBuilder);
// ... attach your exporter to meterProviderBuilder ...
OpenTelemetry otel =
    OpenTelemetrySdk.builder().setMeterProvider(meterProviderBuilder.build()).build();

SpannerOptions options =
    SpannerOptions.newBuilder()
        .setClientMetricsProvider(new CustomOpenTelemetryMetricsProvider(otel))
        .build();

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gemini-code-assist[bot] reacted with eyes emoji
All reactions
  • 👀 1 reaction
@rahul2393
rahul2393 requested review from a team as code owners July 7, 2026 17:32
gemini-code-assist[bot]
gemini-code-assist Bot reviewed Jul 7, 2026
View reviewed changes

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

Copy link
Copy Markdown
Contributor

There was a problem hiding this 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 introduces the MetricsProvider interface and its implementations (DefaultMetricsProvider, NoopMetricsProvider, and CustomOpenTelemetryMetricsProvider) to allow customization of how built-in client-side metrics are collected and exported in the Cloud Spanner Java client. This enables recording metrics on a caller-provided OpenTelemetry instance rather than exporting them directly to Google Cloud Monitoring, which is particularly useful for Spanner Omni clients. Additionally, the changes add support for registering built-in metric views on a custom meter provider, introduce an endpoint attribute for location-aware routing, and include comprehensive integration and unit tests to validate these new features. There are no review comments, so I have no feedback to provide.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@rahul2393
rahul2393 force-pushed the feat/spanner-custom-otel-metrics branch from 124a9c7 to 383daa2 Compare July 8, 2026 07:18
@rahul2393

rahul2393 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

gemini-code-assist[bot] reacted with eyes emoji
All reactions
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gemini-code-assist[bot]
gemini-code-assist Bot reviewed Jul 8, 2026
View reviewed changes

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

Copy link
Copy Markdown
Contributor

There was a problem hiding this 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 introduces a customizable MetricsProvider interface for the Cloud Spanner Java client, allowing users to configure how built-in metrics are collected and exported. It adds support for a CustomOpenTelemetryMetricsProvider to record metrics on a user-provided OpenTelemetry instance, alongside the default Google Cloud Monitoring export and a NoopMetricsProvider to disable metrics entirely. The changes also include labeling attempt metrics with routed endpoints on the location-aware fastpath, and extensive integration tests verifying the dual-sink and gRPC-layer metrics behavior. Feedback on the code changes highlights a potential UnsupportedOperationException in BuiltInMetricsConstant.java due to mutating a set returned by Collectors.toSet(), with a suggestion to use Collectors.toCollection(HashSet::new) to guarantee mutability.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread ...nner/google-cloud-spanner/src/main/java/com/google/cloud/spanner/BuiltInMetricsConstant.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@rahul2393
rahul2393 requested review from olavloite and surbhigarg92 July 8, 2026 07:20
@rahul2393
rahul2393 force-pushed the feat/spanner-custom-otel-metrics branch from f7bd207 to 5a63c9e Compare July 8, 2026 09:17
@rahul2393

rahul2393 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Current failures in CI pipeline are because of #13584
cc: @lqiu96

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rahul2393
rahul2393 force-pushed the feat/spanner-custom-otel-metrics branch from 72b0be7 to 03c7825 Compare July 8, 2026 14:56
@lqiu96

lqiu96 commented Jul 8, 2026

Copy link
Copy Markdown
Member

Current failures in CI pipeline are because of #13584 cc: @lqiu96

Sorry, we will fix this upstream. I think you should be able to proceed without this check if you want

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rahul2393
rahul2393 force-pushed the feat/spanner-custom-otel-metrics branch from b5fa19a to 1add8f1 Compare July 8, 2026 17:16
sakthivelmanii
sakthivelmanii reviewed Jul 14, 2026
View reviewed changes
Comment thread ...nner/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java
throws IOException {
// Only do the check if the emulator environment variable has been set to localhost.
if (isEmulatorEnabled(options, emulatorHost)) {
String resolvedEmulatorHost = emulatorHost != null ? emulatorHost : options.getEndpoint();

@sakthivelmanii sakthivelmanii Jul 14, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Why are we doing this?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@rahul2393 rahul2393 Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Earlier only env was checked, now this is updated to also check if emulator is enabled programmatically via SpannerOptions, to log that in case it's set we are adding this

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
rahul2393 added a commit to rahul2393/google-cloud-java that referenced this pull request Jul 14, 2026
@rahul2393 @claude
feat(spanner): support user-provided OpenTelemetry for client metrics…
bfc4aea
… export

Adds the MetricsProvider family (Default/Noop/CustomOpenTelemetry),
SpannerOptions.Builder#setClientMetricsProvider, and
SpannerMetrics#configureMeterProviderBuilder so client metrics can be
recorded on a caller-owned OpenTelemetry in the spanner/client
namespace, decoupled from the Cloud Monitoring built-in metrics flag.
Also broadens the emulator gate (SpannerOptions#isEmulatorEnabled,
enablegRPCMetrics overload) so no client metrics are recorded against
the emulator.

Split from PR googleapis#13679 (client-metrics half).

Co-Authored-By: Claude Fable 5 <[email protected]>
@rahul2393
rahul2393 force-pushed the feat/spanner-custom-otel-metrics branch from af8fd4a to bfc4aea Compare July 14, 2026 05:57
@rahul2393 rahul2393 mentioned this pull request Jul 14, 2026
feat(spanner): add optional endpoint attribute to client metrics for location-aware routing #13740
Draft
@rahul2393 rahul2393 changed the title feat(spanner): support user-provided OpenTelemetry for built-in client metrics and endpoint attribute for location-aware routing feat(spanner): support user-provided OpenTelemetry for client metrics export Jul 14, 2026
@rahul2393
feat(spanner): support user-provided OpenTelemetry for client metrics…
818893b
… export

Adds the MetricsProvider family (Default/Noop/CustomOpenTelemetry),
SpannerOptions.Builder#setClientMetricsProvider, and
SpannerMetrics#configureMeterProviderBuilder so client metrics can be
recorded on a caller-owned OpenTelemetry in the spanner/client namespace,
decoupled from the Cloud Monitoring built-in metrics flag. Also broadens
the emulator gate (SpannerOptions#isEmulatorEnabled, enablegRPCMetrics
overload) so no client metrics are recorded against the emulator.
@rahul2393
rahul2393 force-pushed the feat/spanner-custom-otel-metrics branch from bfc4aea to 818893b Compare July 14, 2026 06:06
rahul2393 added a commit to rahul2393/google-cloud-java that referenced this pull request Jul 14, 2026
@rahul2393
feat(spanner): add optional endpoint attribute to client metrics for …
307e31a
…location-aware routing

Adds the ENDPOINT_KEY metric attribute: KeyAwareChannel labels each
attempt with the endpoint the location-aware fastpath routed it to, and
the custom-export attempt views allow the label through their attribute
filter. Cloud Monitoring views never include it.

Stacked follow-up to the client metrics export change (googleapis#13679); until
that merges this commit also carries the client metrics export work.
Merge after googleapis#13679 lands.
@rahul2393 rahul2393 closed this Jul 14, 2026
@zoola969 zoola969 mentioned this pull request Aug 19, 2026
(google-cloud-spanner) Built-in metrics fail when one process uses databases in different projects googleapis/google-cloud-python#18155
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@sakthivelmanii sakthivelmanii sakthivelmanii left review comments
@olavloite olavloite Awaiting requested review from olavloite
@surbhigarg92 surbhigarg92 Awaiting requested review from surbhigarg92
+1 more reviewer
@gemini-code-assist gemini-code-assist[bot] gemini-code-assist[bot] left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@rahul2393 @lqiu96 @sakthivelmanii
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.