Skip to content

feat(gax): Actionable Errors Logging API Tracer#12202

Open
westarle wants to merge 5 commits intogoogleapis:mainfrom
westarle:feat/actionable-errors-api-tracer
Open

feat(gax): Actionable Errors Logging API Tracer#12202
westarle wants to merge 5 commits intogoogleapis:mainfrom
westarle:feat/actionable-errors-api-tracer

Conversation

@westarle
Copy link
Copy Markdown
Contributor

No description provided.

@westarle westarle requested a review from a team as a code owner March 25, 2026 20:06
@gemini-code-assist
Copy link
Copy Markdown
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 GAX tracing mechanism by introducing a dedicated LoggingTracer designed to capture and log actionable errors during RPC failures. It provides a more detailed and structured approach to error reporting, incorporating various contextual attributes and specific error details from ApiException into the logs. This improvement aims to provide clearer insights into why RPC attempts fail, thereby aiding in quicker diagnosis and resolution of issues.

Highlights

  • New LoggingTracer: Introduced a new LoggingTracer class that extends BaseApiTracer to specifically log actionable errors when an RPC attempt fails.
  • Error Context Enrichment: The LoggingTracer enriches error logs with contextual information such as RPC system name, full method name, server port, repository, and detailed ErrorInfo extracted from ApiException.
  • LoggingTracerFactory: Added a LoggingTracerFactory to create instances of LoggingTracer, allowing for flexible integration and context merging.
  • Comprehensive Testing: Included unit tests for both LoggingTracer and LoggingTracerFactory to ensure correct functionality and integration.
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
Copy Markdown
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 new LoggingTracer and LoggingTracerFactory to provide actionable error logging for RPC failures, along with their corresponding unit tests. The LoggingTracer collects various context attributes and error details for logging. Feedback includes suggestions to use constants for log context keys in LoggingTracer for better maintainability, to ensure consistent context merging in one of the newTracer overloads in LoggingTracerFactory, and to improve the LoggingTracerTest to assert actual logged messages.

@westarle westarle force-pushed the feat/actionable-errors-api-tracer branch 5 times, most recently from 2de91cf to d5cc997 Compare March 26, 2026 03:44
@westarle westarle force-pushed the feat/actionable-errors-api-tracer branch from d5cc997 to 60569e8 Compare March 26, 2026 23:17
@westarle westarle force-pushed the feat/actionable-errors-api-tracer branch from 60569e8 to a73c78b Compare March 27, 2026 03:05
@westarle westarle requested a review from blakeli0 March 27, 2026 04:19
*/
@BetaApi
@InternalApi
public class LoggingTracer extends BaseApiTracer {
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.

Can we change the scope of this class and the constructor from public to package private?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done


Map<String, Object> logContext = new HashMap<>(apiTracerContext.getAttemptAttributes());

if (apiTracerContext.serviceName() != null) {
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.

This is probably a miss. I think getAttemptAttributes should include serviceName as well, since it is listed as a common attribute in the requirement.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added to getAttemptAttributes()

}

@Override
public void attemptFailedRetriesExhausted(Throwable error) {
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.

Can we add unit tests for this method attemptFailedRetriesExhausted and method below attemptPermanentFailure?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

}

@Test
void testAttemptFailed_LogsErrorAndAttributes() {
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.

I see that most of the logics are in recordActionableError, we could test it directly by making it package private and @VisibleForTesting.

Then we can have a simple test for each method that calls it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

void testAttemptFailed_LogsErrorAndAttributes() {
ApiTracerContext context =
ApiTracerContext.empty().toBuilder()
.setServiceName("test-service")
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.

Since all these 5 attributes are all from getAttemptAttributes(), maybe we don't have to add all them, using one or two should be good enough? I think it also blurred the focus of the test which is extracting errors info.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

"test.service.v1.Method",
attributesMap.get(ObservabilityAttributes.GRPC_RPC_METHOD_ATTRIBUTE));
assertEquals("grpc", attributesMap.get(ObservabilityAttributes.RPC_SYSTEM_NAME_ATTRIBUTE));
assertEquals(
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.

Can we try to test these attributes in its own test case? This is inline with the best practices. Maybe we can group all the error info ones together, but I feel status should be its own test case.

Same comment for testing the error message as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done


/** Function to extract the ErrorInfo payload from the error, if available */
@Nullable
static ErrorInfo extractErrorInfo(@Nullable Throwable error) {
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.

I'm adding similar logic in #12189.

Let me know if you'd prefer a different surface for my util.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

happy to move to your logic when it's ready.

@westarle westarle requested a review from blakeli0 March 27, 2026 22:12
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.

3 participants