Skip to content

feat(spanner): support caller-owned OpenTelemetry client metrics - #20388

Merged
rahul2393 merged 2 commits into
mainfrom
fm/spanner-go-clientmetrics-otel-b1
Aug 24, 2026
Merged

feat(spanner): support caller-owned OpenTelemetry client metrics#20388
rahul2393 merged 2 commits into
mainfrom
fm/spanner-go-clientmetrics-otel-b1

Conversation

@rahul2393

Copy link
Copy Markdown
Contributor

Internal Reference: go/built-in-metric-custom-export
Java PR: googleapis/google-cloud-java#13741

@rahul2393
rahul2393 requested review from a team as code owners August 17, 2026 14:02
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the Spanner API. label Aug 17, 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 the ability to export Spanner's built-in client metrics to a caller-owned OpenTelemetry pipeline via the new ClientMetricsProvider configuration option. To support this, the internal metrics tracing system was refactored to handle multiple metrics sinks (e.g., native Cloud Monitoring and OpenTelemetry) simultaneously. The feedback recommends improving resource cleanup within the newBuiltinMetricsTracerFactory constructor by using named return errors and a deferred block to automatically clean up the newly created meter provider and exporter if the initialization fails.

Comment thread spanner/metrics.go Outdated
Comment thread spanner/metrics.go Outdated
@rahul2393 rahul2393 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 17, 2026
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 17, 2026
@rahul2393
rahul2393 force-pushed the fm/spanner-go-clientmetrics-otel-b1 branch from 27e5296 to 5912ac0 Compare August 18, 2026 20:13
… setup fails

newBuiltinMetricsTracerFactory creates the Cloud Monitoring meter provider and
exporter before registering metric sinks. If a later sink registration failed,
the constructor returned the error without stopping the exporter or shutting
down the meter provider it had created. Use a named error return and a
deferred cleanup so the factory releases only the resources it owns on any
failure path; a caller-owned ClientMetricsProvider is never shut down.
Comment thread spanner/metrics.go
}

func newBuiltinMetricsTracerFactory(ctx context.Context, dbpath, compression string, isAFEBuiltInMetricEnabled, isEnableGRPCBuiltInMetrics bool, metricsProvider metric.MeterProvider, opts ...option.ClientOption) (*builtinMetricsTracerFactory, error) {
func newBuiltinMetricsTracerFactory(ctx context.Context, dbpath, compression string, isAFEBuiltInMetricEnabled, isEnableGRPCBuiltInMetrics bool, metricsProvider, clientMetricsProvider metric.MeterProvider, opts ...option.ClientOption) (tracerFactory *builtinMetricsTracerFactory, err error) {

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.

For a follow-up PR: This method could use a refactor and be split into smaller parts. It is not really easy to read as it is now....

@rahul2393
rahul2393 merged commit f1e77ce into main Aug 24, 2026
17 checks passed
@rahul2393
rahul2393 deleted the fm/spanner-go-clientmetrics-otel-b1 branch August 24, 2026 15:08
rahul2393 pushed a commit that referenced this pull request Aug 24, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.95.0](spanner/v1.94.0...spanner/v1.95.0)
(2026-08-24)


### Features

* **spanner:** Penalize channels that returned Unavailable or
ResourceExhausted in the dynamic channel pool picker
([#20390](#20390))
([e1feec4](e1feec4))
* **spanner:** Support caller-owned OpenTelemetry client metrics
([#20388](#20388))
([f1e77ce](f1e77ce))


### Bug Fixes

* **spanner:** Stop leaking endpointLatencyRegistry cleanup goroutine
([#20416](#20416))
([95bbcc7](95bbcc7)),
refs
[#14488](#14488)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the Spanner API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants