Skip to content

feat: add resend attribute to span tracing#12191

Open
ldetmer wants to merge 5 commits intomainfrom
rety
Open

feat: add resend attribute to span tracing#12191
ldetmer wants to merge 5 commits intomainfrom
rety

Conversation

@ldetmer
Copy link
Contributor

@ldetmer ldetmer commented Mar 24, 2026

This adds attribute for HTTP_REQUEST_RESEND_COUNT to span tracing. This only gets populated in case of a retry on the client side.

no resend attribute on first attempt
example retry 1
example retry 4

@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 BigQuery client's OpenTelemetry tracing capabilities by introducing a new HTTP_REQUEST_RESEND_COUNT attribute. This attribute will be populated on HTTP request spans only when a client-side retry occurs, providing valuable insight into the retry behavior of requests. The change involves tracking retry attempts using a ThreadLocal variable and integrating this information into the tracing initializer.

Highlights

  • Retry Attempt Tracking: Introduced a ThreadLocal mechanism within BigQueryRetryAlgorithm to accurately track the current retry attempt count for client-side operations.
  • OpenTelemetry Span Attribute: Added a new HTTP_REQUEST_RESEND_COUNT attribute to OpenTelemetry spans, which is populated with the retry attempt count when an HTTP request is retried.
  • Attribute Reset Logic: Implemented logic to reset the ThreadLocal retry attempt count after each request to prevent state leakage across different requests on the same thread.
  • Comprehensive Testing: Included new unit tests across multiple files to validate that the HTTP_REQUEST_RESEND_COUNT attribute is correctly set during retries and appropriately absent when tracing is disabled or no retry occurs.
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 a mechanism to track and report HTTP request resend counts in OpenTelemetry traces for BigQuery operations, utilizing a ThreadLocal variable to store the current retry attempt. The primary feedback highlights a potential ThreadLocal state leakage in BigQueryRetryAlgorithm if a retry sequence fails completely, which could lead to incorrect tracing data for subsequent requests on the same thread. Additionally, the newly added tests that manually set the ThreadLocal state lack try-finally blocks for cleanup, making them fragile and prone to leaking state between tests.

@ldetmer ldetmer marked this pull request as ready for review March 24, 2026 21:04
@ldetmer ldetmer requested review from a team as code owners March 24, 2026 21:04
@ldetmer ldetmer requested review from jinseopkim0 and lqiu96 March 24, 2026 21:07
@ldetmer ldetmer added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 25, 2026
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Mar 25, 2026
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.

2 participants