Skip to content

impl(o11y): introduce resend_count logic#4156

Merged
blakeli0 merged 7 commits intomainfrom
observability/tracing-attr/resend_count
Mar 21, 2026
Merged

impl(o11y): introduce resend_count logic#4156
blakeli0 merged 7 commits intomainfrom
observability/tracing-attr/resend_count

Conversation

@diegomarquezp
Copy link
Contributor

@diegomarquezp diegomarquezp commented Mar 18, 2026

Introduces gcp.grpc.resend_count and http.request.resend_count by relying on the parameter passed to ApiTracer.


Reliability of attemptNumber in ApiTracer

The attemptNumber is passed from the retrying logic in gax-java/gax.

For unary calls, here is an example of how the overall attempt count behaves:

How it is updated:
The attempt count is managed by the retry algorithms. For example, ExponentialRetryAlgorithm is thread-safe and creates immutable TimedAttemptSettings. It initializes overallAttemptCount to 0 and increments it for each subsequent attempt.

// gax-java/gax/src/main/java/com/google/api/gax/retrying/ExponentialRetryAlgorithm.java

  @Override
  public TimedAttemptSettings createFirstAttempt() {
    return TimedAttemptSettings.newBuilder()
        // ...
        .setOverallAttemptCount(0)
        // ...
        .build();
  }

  @Override
  public TimedAttemptSettings createNextAttempt(TimedAttemptSettings previousSettings) {
    // ...
    return TimedAttemptSettings.newBuilder()
        // ...
        .setOverallAttemptCount(previousSettings.getOverallAttemptCount() + 1)
        // ...
        .build();
  }

How it is consumed:
AttemptCallable executes unary calls. externalFuture is marked as volatile to handle potential visibility between the thread that schedules the retry and the thread executing call(). Before starting the RPC call, AttemptCallable invokes attemptStarted using the overallAttemptCount from externalFuture.

// gax-java/gax/src/main/java/com/google/api/gax/rpc/AttemptCallable.java

class AttemptCallable<RequestT, ResponseT> implements Callable<ResponseT> {
  // ...
  private volatile RetryingFuture<ResponseT> externalFuture;
  // ...
  @Override
  public ResponseT call() {
    // ...
    callContext
        .getTracer()
        .attemptStarted(request, externalFuture.getAttemptSettings().getOverallAttemptCount());
    // ...
  }
}

Thread Safety:
Attempts for a single RPC are strictly sequential; a new attempt is only constructed and scheduled after the previous attempt fails and the retry delay elapses. ExponentialRetryAlgorithm is thread-safe, TimedAttemptSettings is immutable, and the externalFuture reference inside AttemptCallable is volatile. This combination ensures thread-safe observation of the linearly increasing overallAttemptCount.

Conclusion

Since the retrying infrastructure sequentially updates and consumes getOverallAttemptCount() in a thread-safe manner, we can confidently and safely use attemptNumber in SpanTracer to populate the rpc.grpc.resend_count or rpc.http.resend_count attributes. This approach directly leverages the existing reliable retry logic rather than implementing a redundant internal counter.

@product-auto-label product-auto-label bot added the size: l Pull request size is large. label Mar 18, 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 enhances the observability of client-side operations by introducing a resend_count attribute to tracing spans. This attribute, applied to both gRPC and HTTP requests, provides crucial context for understanding and analyzing retry behavior, which is vital for debugging transient errors and optimizing performance in distributed systems.

Highlights

  • New Observability Attributes: Introduced new constants, "HTTP_RESEND_COUNT_ATTRIBUTE" and "GRPC_RESEND_COUNT_ATTRIBUTE", to ObservabilityAttributes for tracking the number of times a request has been resent due to retries.
  • SpanTracer Enhancement: Modified SpanTracer to track and include a resendCount attribute in attempt spans for retried requests, differentiating between HTTP and gRPC transports.
  • Attribute Type Handling: Updated ObservabilityUtils to correctly handle Long type attributes when converting them to OpenTelemetry attributes.
  • Comprehensive Testing: Added new unit tests in SpanTracerTest and integration tests in ITOtelTracing to validate the correct propagation and value of the resend_count attribute for both gRPC and HTTP retries.
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.

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 introduces logic to add a resend_count attribute to observability spans for retried requests. The implementation in SpanTracer is solid, correctly incrementing the count for each retry and adding the appropriate transport-specific attribute. The unit tests for this logic are also well-written.

However, I've found issues in the new integration tests in ITOtelTracing.java. The verification logic for the resend_count attribute is flawed in both the gRPC and HTTP JSON test cases. I've provided suggestions to correct the test logic to ensure it properly validates the new feature.

@diegomarquezp diegomarquezp marked this pull request as ready for review March 19, 2026 02:15
…-attr/resend_count

# Conflicts:
#	gax-java/gax/src/main/java/com/google/api/gax/tracing/SpanTracer.java
…-attr/resend_count

# Conflicts:
#	gax-java/gax/src/main/java/com/google/api/gax/tracing/SpanTracer.java
…hub.com/googleapis/sdk-platform-java into observability/tracing-attr/resend_count

# Conflicts:
#	gax-java/gax/src/test/java/com/google/api/gax/tracing/SpanTracerTest.java
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed for 'gapic-generator-java-root'

Failed conditions
71.4% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@sonarqubecloud
Copy link

Quality Gate Passed Quality Gate passed for 'java_showcase_integration_tests'

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
82.1% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@blakeli0 blakeli0 merged commit e8b6d50 into main Mar 21, 2026
56 of 57 checks passed
@blakeli0 blakeli0 deleted the observability/tracing-attr/resend_count branch March 21, 2026 03:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: l Pull request size is large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants