feat(spanner): support caller-owned OpenTelemetry client metrics - #20388
Conversation
There was a problem hiding this comment.
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.
27e5296 to
5912ac0
Compare
… 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.
| } | ||
|
|
||
| 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) { |
There was a problem hiding this comment.
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....
🤖 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>
Internal Reference: go/built-in-metric-custom-export
Java PR: googleapis/google-cloud-java#13741