Skip to content

feat(Spanner): migrate the metrics exporter from a custom one to a native OTLP one. - #9505

Open
Hectorhammett wants to merge 3 commits into
mainfrom
otel-migration
Open

feat(Spanner): migrate the metrics exporter from a custom one to a native OTLP one.#9505
Hectorhammett wants to merge 3 commits into
mainfrom
otel-migration

Conversation

@Hectorhammett

Copy link
Copy Markdown
Collaborator

Summary

In the past when we introduced client metrics, we implemented a custom exporter (MetricServiceClient) to translate metrics into Google Cloud Monitoring TimeSeries objects because GCP did not yet support the native OTLP protocol.

Google Cloud now natively supports OTLP metric ingestion at https://telemetry.googleapis.com/v1/metrics. This PR updates the Spanner PHP SDK built-in metrics exporter to use standard OTLP HTTP export and adds support for configurable metrics credentials.

Key Changes

  • OTLP Exporter Migration: Replaced legacy MetricServiceClient GCM translation in MetricsExporter with standard OTLP HTTP exporter (OpenTelemetry\Contrib\Otlp\MetricExporter) targeting https://telemetry.googleapis.com/v1/metrics.
  • Configurable & Re-scoped Credentials:
    • Added support for dedicated $options['metricsCredentials'] in SpannerClient.
    • Automatically re-scopes credentials to https://www.googleapis.com/auth/monitoring.write and https://www.googleapis.com/auth/cloud-platform using CredentialsWrapper to prevent OAuth scope mismatch errors.
    • Falls back gracefully to main client credentials or Application Default Credentials (ADC).
  • Guzzle Authorization Middleware: Dynamically attaches Authorization: Bearer <token> and x-goog-user-project headers to outgoing OTLP HTTP requests via Guzzle middleware.

@Hectorhammett
Hectorhammett requested a review from a team as a code owner August 19, 2026 02:10
@Hectorhammett Hectorhammett added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Aug 19, 2026
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the Spanner API. label Aug 19, 2026
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. do not merge Indicates a pull request not ready for merge, due to either quality or timing.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant