feat(Spanner): migrate the metrics exporter from a custom one to a native OTLP one. by Hectorhammett · Pull Request #9505 · googleapis/google-cloud-php · GitHub
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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