Skip to content

feat(BuiltInMetrics): Add built in metrics library - #15871

Draft
robertvoinescu-work wants to merge 2 commits into
googleapis:mainfrom
robertvoinescu-work:spanner/builtInMetricsOtlp
Draft

robertvoinescu-work wants to merge 2 commits into
googleapis:mainfrom
robertvoinescu-work:spanner/builtInMetricsOtlp

Conversation

@robertvoinescu-work

Copy link
Copy Markdown
Contributor

b/404948213

Test Validation
image

@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 Google.Cloud.BuiltInMetrics package, which enables and exports Google Cloud client built-in metrics telemetry via OpenTelemetry, specifically configuring and testing Spanner-related metrics. Feedback on the changes highlights two key issues: first, a critical issue where static configuration of the OAuth2 access token at startup will cause export failures after one hour, which can be resolved by dynamically injecting the token using a custom DelegatingHandler; second, a scoping issue where calling AddView globally without specifying the meter name could cause unexpected side-effects on other metrics, which should be resolved by scoping the views to the Spanner meter.

@robertvoinescu-work
robertvoinescu-work force-pushed the spanner/builtInMetricsOtlp branch 3 times, most recently from 1a50487 to 69c472f Compare August 31, 2026 21:23
@robertvoinescu-work

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 Google.Cloud.BuiltInMetrics package, which provides OpenTelemetry exporter configuration and setup for Google Cloud client built-in metrics, with an initial implementation for Google Cloud Spanner. The feedback suggests several improvements: resolving a potential authorization issue by calling GetAccessTokenForRequestAsync directly on the scoped credential rather than its underlying credential, adding a null check in AuthHeaderHandler, exposing the AddGoogleCloudBuiltInMetrics and AddGoogleCloudBuiltInMetricsAsync extension methods as public, and catching InvalidArgument RPC exceptions in integration tests to handle initial metric ingestion delays more robustly.

Comment thread apis/Google.Cloud.BuiltInMetrics/Google.Cloud.BuiltInMetrics/BuiltInMetrics.cs Outdated
@robertvoinescu-work
robertvoinescu-work force-pushed the spanner/builtInMetricsOtlp branch from 69c472f to bbc5d66 Compare August 31, 2026 21:37
@robertvoinescu-work

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 new Google.Cloud.BuiltInMetrics package, which configures and exports Google Cloud client built-in metrics (such as Spanner telemetry) to Google Cloud Monitoring using OpenTelemetry and OTLP. It includes the core implementation, unit tests, integration tests, and updates to repository configuration files. The feedback suggests adding a safety check in AuthHeaderHandler to ensure the retrieved access token is not null or empty before setting the authorization header, preventing potential exceptions.

@robertvoinescu-work

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 Google.Cloud.BuiltInMetrics project to support OpenTelemetry collection and exporting of Google Cloud client built-in metrics, along with corresponding unit and integration tests. Key feedback includes resolving a compilation issue on the net462 target framework by avoiding Environment.ProcessId, exposing the internal extension methods AddGoogleCloudBuiltInMetrics and AddGoogleCloudBuiltInMetricsAsync as public to allow integration with existing builders, and replacing the unnecessary Google.Api.Gax.Grpc dependency with Google.Api.Gax in both the project configuration and apis.json metadata.

Comment thread generator-input/apis.json Outdated
@robertvoinescu-work
robertvoinescu-work force-pushed the spanner/builtInMetricsOtlp branch 2 times, most recently from 8085440 to 6b52859 Compare September 1, 2026 19:54
/// <summary>
/// Defines service-specific metrics configuration for OpenTelemetry collection.
/// </summary>
internal interface IServiceMetricsConfiguration

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is we can eventually extend for any other service that requires built in metrics simply by implementing this and adding a reference in BuiltInMetrics.ConfigureOtlpExporter

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