Skip to content

feat: Switch Eef metrics to using built in open telemetry#4385

Open
kinsaurralde wants to merge 4 commits intogoogleapis:mainfrom
kinsaurralde:eef_metrics
Open

feat: Switch Eef metrics to using built in open telemetry#4385
kinsaurralde wants to merge 4 commits intogoogleapis:mainfrom
kinsaurralde:eef_metrics

Conversation

@kinsaurralde
Copy link
Contributor

Switching to built in open telemetry since the eef metrics are internal metrics

@kinsaurralde kinsaurralde requested review from a team as code owners March 16, 2026 17:23
@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 Mar 16, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 refactors the internal EEF metrics collection within the Spanner client library to leverage the existing built-in OpenTelemetry infrastructure. This change streamlines metric reporting by consolidating internal metrics under a unified observability framework, improving consistency and reducing the need for custom metric handling.

Highlights

  • OpenTelemetry Integration: Switched the internal EEF (Enhanced Error Handling) metrics to use the built-in OpenTelemetry system, aligning with the project's observability strategy.
  • New Metric Definitions: Introduced new constants for gRPC-GCP specific metrics, including eef.fallback_count and eef.call_status, along with their associated OpenTelemetry attribute keys and view configurations.
  • Metric View Configuration: Implemented a new defineGrpcGcpView method to properly configure OpenTelemetry views for the new gRPC-GCP metrics, ensuring correct aggregation and attribute filtering.
  • Built-in OpenTelemetry Access: Added a public method getBuiltInOpenTelemetry to SpannerOptions to provide access to the internal OpenTelemetry instance for consistent metric reporting.
  • Fallback Metrics Update: Modified GapicSpannerRpc to utilize the newly exposed built-in OpenTelemetry instance for GcpFallbackOpenTelemetry metrics, ensuring these internal metrics are reported through the standard OpenTelemetry pipeline.
Changelog
  • google-cloud-spanner/src/main/java/com/google/cloud/spanner/BuiltInMetricsConstant.java
    • Added a new constant for the gRPC-GCP meter name.
    • Introduced constants for EEF fallback count and call status metric names.
    • Defined new AttributeKey constants for channel names and status codes.
    • Created sets for gRPC-GCP EEF fallback count and call status attributes.
    • Defined a map for gRPC-GCP metric additional attributes and a collection of gRPC-GCP metrics to enable.
    • Invoked the new defineGrpcGcpView method within getAllViews.
    • Added the defineGrpcGcpView method to configure OpenTelemetry views for gRPC-GCP metrics.
  • google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerCloudMonitoringExporterUtils.java
    • Imported the new GRPC_GCP_METER_NAME constant.
    • Updated the metric data filtering logic to include the GRPC_GCP_METER_NAME.
  • google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerOptions.java
    • Added a new public method getBuiltInOpenTelemetry to retrieve the internal OpenTelemetry instance.
  • google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java
    • Imported the OpenTelemetry class.
    • Added a new @VisibleForTesting method getFallbackOpenTelemetry to conditionally return the built-in OpenTelemetry instance.
    • Modified the interceptCall method to use getFallbackOpenTelemetry(options) when initializing GcpFallbackOpenTelemetry.
  • google-cloud-spanner/src/test/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpcTest.java
    • Overrode the getFallbackOpenTelemetry method in TestableGapicSpannerRpc to return options.getOpenTelemetry().
    • Overrode the getFallbackOpenTelemetry method in TestableGapicSpannerRpcWithLowerMinFailedCalls to return options.getOpenTelemetry().
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.

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 correctly switches the EEF metrics to use the built-in OpenTelemetry instance, which is appropriate for internal metrics. The changes involve exposing the built-in OpenTelemetry instance through SpannerOptions and utilizing it in GapicSpannerRpc for the fallback channel's telemetry. Additionally, new constants and views for the EEF metrics are introduced. The implementation appears solid. I have one suggestion to enhance code maintainability by refactoring a lengthy conditional statement.

Comment on lines 88 to +91
if (!(metricData.getInstrumentationScopeInfo().getName().equals(GAX_METER_NAME)
|| metricData.getInstrumentationScopeInfo().getName().equals(SPANNER_METER_NAME)
|| metricData.getInstrumentationScopeInfo().getName().equals(GRPC_METER_NAME))) {
|| metricData.getInstrumentationScopeInfo().getName().equals(GRPC_METER_NAME)
|| metricData.getInstrumentationScopeInfo().getName().equals(GRPC_GCP_METER_NAME))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The chain of || conditions is getting long and can be hard to read. To improve readability and maintainability, consider using a Set of allowed meter names for this check.

You could define a public static Set<String> in BuiltInMetricsConstant.java:

// In BuiltInMetricsConstant.java
public static final String SPANNER_METER_NAME = "spanner-java"; // Make public
public static final String GRPC_METER_NAME = "grpc-java"; // Make public

public static final java.util.Set<String> ALLOWED_BUILT_IN_METRICS_METERS =
    com.google.common.collect.ImmutableSet.of(
        GAX_METER_NAME, SPANNER_METER_NAME, GRPC_METER_NAME, GRPC_GCP_METER_NAME);

Then, you can simplify this check to:

if (!BuiltInMetricsConstant.ALLOWED_BUILT_IN_METRICS_METERS.contains(
    metricData.getInstrumentationScopeInfo().getName())) {
  // ...
}

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.

1 participant