Skip to content

refactor: use per-adapter SdkMeterProvider with bounded lifecycle cleanup - #439

Closed
sakthivelmanii wants to merge 1 commit into
googleapis:mainfrom
sakthivelmanii:refactor/per-adapter-builtin-metrics
Closed

sakthivelmanii wants to merge 1 commit into
googleapis:mainfrom
sakthivelmanii:refactor/per-adapter-builtin-metrics

Conversation

@sakthivelmanii

Copy link
Copy Markdown
Contributor

Problem Statement

  • Built-in metrics previously used a single JVM-wide SdkMeterProvider singleton initialized with the first adapter's project and instance ID and closed only via a JVM shutdown hook.
  • Running multiple sessions or listeners in the same JVM could not isolate metrics exporters per adapter, avoid client_uid/client_hash collisions, or flush and release exporter threads when individual adapters stopped or failed to start.
  • Launcher.shutdown() only caught IOException per adapter, allowing an IllegalStateException from stopping a never-started adapter to skip stopping remaining healthy listeners.

Solution

  • Added BuiltInMetricsProvider.createMetricsRecorder(...) (@InternalApi) to create a dedicated per-adapter SdkMeterProvider with a unique client_uid and matching client_hash per adapter, lazily caching GCP resource attribute detection so per-adapter creation does not re-probe the metadata server, while retaining getOrCreateOpenTelemetry(...) for binary compatibility.
  • Added an idempotent, 2-second bounded close() lifecycle method to BuiltInMetricsRecorder and wired cleanup into Adapter.stop(), Adapter.start() failure paths, SpannerCqlSessionBuilder, and Launcher.
  • Updated Launcher.shutdown() to catch Exception per adapter so partial startup failures still stop all healthy listeners cleanly while letting fatal JVM Errors propagate.

…anup

- Added BuiltInMetricsProvider.createMetricsRecorder(...) (@internalapi) to create a dedicated per-adapter SdkMeterProvider with a unique client_uid and matching client_hash per adapter, lazily caching GCP resource attribute detection while retaining getOrCreateOpenTelemetry(...) for binary compatibility.
- Added an idempotent, 2-second bounded close() lifecycle method to BuiltInMetricsRecorder and wired cleanup into Adapter.stop(), Adapter.start() failure paths, SpannerCqlSessionBuilder, and Launcher.
- Updated Launcher.shutdown() to catch Exception per adapter so partial startup failures still stop all healthy listeners cleanly while letting fatal JVM Errors propagate.
@sakthivelmanii sakthivelmanii self-assigned this Dec 4, 2026
@sakthivelmanii

Copy link
Copy Markdown
Contributor Author

Superseded by #440 (opened directly from the main repository so integration CI checks can run).

@sakthivelmanii
sakthivelmanii deleted the refactor/per-adapter-builtin-metrics branch December 4, 2026 05:54
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