feat(gax): actionable errors logging in ApiTracer framework by westarle · Pull Request #4153 · googleapis/sdk-platform-java · GitHub
Skip to content
This repository was archived by the owner on May 14, 2026. It is now read-only.

feat(gax): actionable errors logging in ApiTracer framework#4153

Closed
westarle wants to merge 7 commits into
googleapis:mainfrom
westarle:feat/actionable-errors-api-tracer
Closed

feat(gax): actionable errors logging in ApiTracer framework#4153
westarle wants to merge 7 commits into
googleapis:mainfrom
westarle:feat/actionable-errors-api-tracer

Conversation

@westarle

@westarle westarle commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

This PR introduces SLF4J logging for "Actionable Errors" occurring at the RPC Attempt level.

@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
Copy Markdown
Contributor

@westarle westarle force-pushed the feat/actionable-errors-api-tracer branch from ba3c2cd to 865c099 Compare March 18, 2026 04:52

@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 logging for actionable errors within the ApiTracer framework, which is a great step towards better observability. The implementation uses a decorator pattern with LoggingTracer and LoggingTracerFactory to intercept failed RPC attempts and log relevant context, gated by an environment variable. The changes are well-structured. I have a couple of suggestions to improve maintainability and test robustness.

I am having trouble creating individual review comments. Click here to see my feedback.

gax-java/gax/src/main/java/com/google/api/gax/tracing/LoggingTracer.java (186-190)

medium

The string literals for logging context keys like "error.type" are hardcoded. To improve maintainability and prevent potential typos, it's a good practice to define them as private static final constants at the top of the class and use them here.

For example, you could add:

private static final String ERROR_TYPE_ATTRIBUTE = "error.type";
private static final String GCP_ERRORS_DOMAIN_ATTRIBUTE = "gcp.errors.domain";
private static final String GCP_ERRORS_METADATA_PREFIX = "gcp.errors.metadata.";

And then use these constants in this block.

gax-java/gax/src/test/java/com/google/api/gax/logging/LoggingUtilsTest.java (120-137)

medium

The testLogActionableError_success test is a bit weak as it only verifies that getLogger() and isInfoEnabled() are called. It doesn't confirm that the logging context and message are correctly passed to the underlying logging framework. To make the test more robust, you should also verify that addKeyValue is called with the expected key-value pairs from the context and that log is called with the correct message on the LoggingEventBuilder.

  @Test
  void testLogActionableError_success() {
    LoggingUtils.setLoggingEnabled(true);
    LoggerProvider loggerProvider = mock(LoggerProvider.class);
    Logger logger = mock(Logger.class);
    when(loggerProvider.getLogger()).thenReturn(logger);
    when(logger.isInfoEnabled()).thenReturn(true);

    org.slf4j.spi.LoggingEventBuilder eventBuilder = mock(org.slf4j.spi.LoggingEventBuilder.class);
    when(logger.atInfo()).thenReturn(eventBuilder);
    when(eventBuilder.addKeyValue(anyString(), any())).thenReturn(eventBuilder);

    Map<String, Object> context = Collections.singletonMap("key", "value");
    LoggingUtils.logActionableError(context, loggerProvider, "message");

    verify(loggerProvider).getLogger();
    verify(logger).isInfoEnabled();
    verify(eventBuilder).addKeyValue("key", "value");
    verify(eventBuilder).log("message");
  }

Comment thread gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java Outdated
Comment thread gax-java/gax/src/main/java/com/google/api/gax/tracing/LoggingTracer.java Outdated
@westarle westarle force-pushed the feat/actionable-errors-api-tracer branch 2 times, most recently from af203ff to ade532f Compare March 18, 2026 22:05
@westarle westarle force-pushed the feat/actionable-errors-api-tracer branch from ade532f to a3ed812 Compare March 22, 2026 16:03
@westarle westarle force-pushed the feat/actionable-errors-api-tracer branch from a3ed812 to 1548dce Compare March 22, 2026 16:42
@westarle westarle force-pushed the feat/actionable-errors-api-tracer branch from 1548dce to 983d57d Compare March 22, 2026 17:27
@westarle westarle force-pushed the feat/actionable-errors-api-tracer branch from 983d57d to b87215a Compare March 22, 2026 17:35
@westarle westarle force-pushed the feat/actionable-errors-api-tracer branch 11 times, most recently from 76d0900 to 042c642 Compare March 23, 2026 20:23
@product-auto-label product-auto-label Bot added size: m Pull request size is medium. and removed size: l Pull request size is large. labels Mar 23, 2026
@westarle westarle force-pushed the feat/actionable-errors-api-tracer branch from 31ce3f0 to 269c749 Compare March 24, 2026 02:42
@product-auto-label product-auto-label Bot added size: l Pull request size is large. and removed size: m Pull request size is medium. labels Mar 24, 2026
@westarle westarle force-pushed the feat/actionable-errors-api-tracer branch from eb6ef7c to 5d46299 Compare March 24, 2026 15:46
@westarle

Copy link
Copy Markdown
Contributor Author

@westarle westarle closed this Mar 30, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

size: l Pull request size is large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants