Skip to content

Conversation

@rahul2393
Copy link
Contributor

  • Preserve the existing channel configurator when enabling grpc‑gcp so gRPC metrics instrumentation is not dropped.
  • Add a toggle to disable grpc‑gcp OpenTelemetry meter injection via SpannerOptions and
    SPANNER_DISABLE_GRPC_GCP_OTEL_METRICS.
  • Add unit tests covering configurator preservation and the new opt‑out behavior.

@rahul2393 rahul2393 requested review from a team as code owners February 3, 2026 07:45
@product-auto-label product-auto-label bot added size: m Pull request size is medium. api: spanner Issues related to the googleapis/java-spanner API. labels Feb 3, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @rahul2393, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses two key areas related to gRPC and metrics in the Spanner client library. It ensures that custom channel configurations are correctly maintained when grpc-gcp extensions are activated, preventing loss of existing gRPC instrumentation. Additionally, it provides users with explicit control over the automatic injection of OpenTelemetry metrics for grpc-gcp, allowing them to disable this feature if desired. These changes improve the flexibility and robustness of the client's gRPC integration and metrics handling.

Highlights

  • Channel Configurator Preservation: The existing ChannelConfigurator is now preserved when grpc-gcp is enabled, ensuring that other gRPC instrumentation (like metrics) is not inadvertently dropped.
  • OpenTelemetry Metrics Opt-Out: A new mechanism has been introduced to disable the automatic injection of OpenTelemetry meters for grpc-gcp metrics. This can be controlled via SpannerOptions or the SPANNER_DISABLE_GRPC_GCP_OTEL_METRICS environment variable.
  • Unit Tests: Comprehensive unit tests have been added to validate both the channel configurator preservation and the new OpenTelemetry metrics opt-out functionality.
Changelog
  • google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java
    • Added a new enableGrpcGcpOtelMetrics field to SpannerOptions and its Builder to control OpenTelemetry metrics injection.
    • Introduced isEnableGrpcGcpOtelMetrics() methods in SpannerEnvironment and SpannerEnvironmentImpl to read the new setting, defaulting to true and allowing override via SPANNER_DISABLE_GRPC_GCP_OTEL_METRICS environment variable.
    • Added a public setGrpcGcpOtelMetricsEnabled() method to the Builder for programmatic control.
    • Added a getter isGrpcGcpOtelMetricsEnabled() to SpannerOptions.
  • google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java
    • Modified the grpcGcpOptionsWithMetricsAndDcp method to only inject an OpenTelemetry meter if options.isGrpcGcpOtelMetricsEnabled() is true and no meter is already set.
    • Updated maybeEnableGrpcGcpExtension to explicitly retrieve and apply the base ChannelConfigurator from defaultChannelProviderBuilder before applying grpc-gcp specific configurations, ensuring its preservation.
  • google-cloud-spanner/src/test/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpcTest.java
    • Added testGrpcGcpExtensionPreservesChannelConfigurator to verify that the original channel configurator is called when grpc-gcp is enabled.
    • Added testGrpcGcpOtelMetricsDisabledSkipsMeterInjection to confirm that OpenTelemetry meters are not injected when the new opt-out setting is active.
    • Included necessary imports for new test classes and methods.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@rahul2393 rahul2393 changed the title fix; preserve channel configurator for grpc-gcp and add opt-out for gcp OTel metrics fix: preserve channel configurator for grpc-gcp and add opt-out for gcp OTel metrics Feb 3, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

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 aims to add an opt-out mechanism for grpc-gcp OpenTelemetry metrics. However, it introduces a critical Denial of Service (DoS) vulnerability due to an infinite recursion bug in the channel configurator logic within GapicSpannerRpc.java. The current implementation incorrectly attempts to retrieve the configurator from the builder inside the lambda, leading to a StackOverflowError and application crash. This can be remediated by capturing the existing configurator in a local variable before defining the new lambda.

@rahul2393 rahul2393 merged commit 2565137 into main Feb 3, 2026
33 checks passed
@rahul2393 rahul2393 deleted the fix-grpc-metrics branch February 3, 2026 08:50
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 googleapis/java-spanner API. size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants