Skip to content

feat(gax): implement active scope management and attribute validation for T3 attempt spans - #13977

Draft
jinseopkim0 wants to merge 1 commit into
mainfrom
tracing-t3-spans-gax
Draft

feat(gax): implement active scope management and attribute validation for T3 attempt spans#13977
jinseopkim0 wants to merge 1 commit into
mainfrom
tracing-t3-spans-gax

Conversation

@jinseopkim0

@jinseopkim0 jinseopkim0 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Description

Implements active scope context propagation and attribute validation for individual RPC attempt spans (T3 spans) in OpenTelemetryTracingTracer.

Changes

  • Activated OpenTelemetry context Scope during attemptStarted(...) via otelContext.makeCurrent().
  • Added cleanup for attemptScope in endAttempt().
  • Set StatusCode.ERROR on attemptSpan when an attempt fails in recordErrorAndEndAttempt.
  • Added unit tests in OpenTelemetryTracingTracerTest verifying scope management and error status propagation.

b/541322523

@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 OpenTelemetry context scope management to OpenTelemetryTracingTracer by storing the active scope during an attempt and closing it upon completion, as well as setting the span status to error when an attempt fails. However, the review highlights a critical thread-safety issue: storing the thread-local Scope in an instance variable and closing it asynchronously across different threads (e.g., from the application thread to the executor thread) can lead to context leaks and corruption. Additionally, the new unit tests execute synchronously on a single thread, which masks this multi-threading issue.

@jinseopkim0

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 error status tracking on OpenTelemetry spans during failed attempts and adds a corresponding unit test. However, the newly declared attemptScope field is never initialized or used. Feedback recommends implementing the scope activation, ensuring that attemptScope is closed in an exception-safe manner to prevent context leaks, and adding unit tests to verify proper scope management.

@jinseopkim0

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 updates OpenTelemetryTracingTracer to set the span status to StatusCode.ERROR when an attempt fails, and adds a corresponding unit test. It also introduces an unused attemptScope field. The review feedback highlights that attemptScope is declared but never initialized or closed, which could lead to context leaks. Additionally, a null check is recommended for attemptSpan before calling methods on it in recordErrorAndEndAttempt to prevent potential NullPointerExceptions.

@jinseopkim0
jinseopkim0 force-pushed the tracing-t3-spans-gax branch from aa33fec to 4a8d3f4 Compare August 5, 2026 17:56
@sonarqubecloud

sonarqubecloud Bot commented Aug 5, 2026

Copy link
Copy Markdown

@sonarqubecloud

sonarqubecloud Bot commented Aug 5, 2026

Copy link
Copy Markdown

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