Skip to content

impl(o11y): [wip] introduce error.type'#4148

Draft
diegomarquezp wants to merge 2 commits intomainfrom
observability/tracing-attr/error.type
Draft

impl(o11y): [wip] introduce error.type'#4148
diegomarquezp wants to merge 2 commits intomainfrom
observability/tracing-attr/error.type

Conversation

@diegomarquezp
Copy link
Contributor

  • impl(o11y): introduce error.type
  • docs: add javadoc for error type logic

@product-auto-label product-auto-label bot added the size: l Pull request size is large. label Mar 16, 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 significantly enhances the observability capabilities by introducing a new error.type attribute for tracing spans. This attribute provides a standardized, low-cardinality classification of errors, enabling more effective analysis and aggregation of error data. The changes include a robust error type extraction logic that prioritizes specific error reasons and codes, ensuring consistent and meaningful error reporting across different failure modes.

Highlights

  • New error.type Attribute: Introduced a new error.type attribute to provide standardized, low-cardinality error classification in observability traces.
  • Error Type Extraction Logic: Implemented a utility function ObservabilityUtils.extractErrorType to determine the appropriate error type based on a priority system (ErrorInfo.reason, server error codes, client-side errors, language-specific exceptions, or internal fallback).
  • Span Attribute Support: Extended the TraceManager.Span interface and its OpenTelemetry implementation to support adding custom attributes to spans.
  • Automated Error Type Recording: Modified SpanTracer to automatically record the error.type attribute on failed operation attempts.
  • Comprehensive Testing: Added comprehensive unit tests for SpanTracer and integration tests in ITOtelTracing to validate the correct extraction and recording of error.type for various error scenarios.
Changelog
  • gax-java/gax/src/main/java/com/google/api/gax/tracing/ObservabilityAttributes.java
    • Added ERROR_TYPE_ATTRIBUTE constant to define the new error type attribute key.
  • gax-java/gax/src/main/java/com/google/api/gax/tracing/ObservabilityUtils.java
    • Added ErrorType enum for classifying client-side network and operational errors.
    • Implemented extractErrorType static method to determine a low-cardinality error type string from a Throwable based on a defined priority order.
  • gax-java/gax/src/main/java/com/google/api/gax/tracing/OpenTelemetryTraceManager.java
    • Implemented the addAttribute method in the OtelSpan inner class to allow setting custom attributes on the underlying OpenTelemetry span.
  • gax-java/gax/src/main/java/com/google/api/gax/tracing/SpanTracer.java
    • Overrode attemptCancelled, attemptFailedDuration, attemptFailedRetriesExhausted, and attemptPermanentFailure methods to ensure error handling.
    • Introduced a private recordErrorAndEndAttempt method to add the error.type attribute to the span using ObservabilityUtils.extractErrorType before ending the attempt.
  • gax-java/gax/src/main/java/com/google/api/gax/tracing/TraceManager.java
    • Added addAttribute(String key, String value) method to the Span interface, allowing custom attributes to be attached to spans.
  • gax-java/gax/src/test/java/com/google/api/gax/tracing/SpanTracerTest.java
    • Added necessary imports for ApiException, ErrorDetails, StatusCode, ImmutableList, Any, ErrorInfo, ConnectException, and TimeoutException for testing.
    • Added numerous new test methods to verify the error.type extraction and recording logic for various error scenarios, including ErrorInfo.reason, gRPC and HTTP server error codes, and different client-side exceptions.
    • Defined several private static exception classes (CredentialsException, DecodeException, RedirectException, RequestBodyException, RequestException, UnknownClientException) to facilitate testing of client-side error types.
  • java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITOtelTracing.java
    • Added imports for assertThrows, StatusCode.Code, UnavailableException, and Status for integration testing.
    • Added testTracing_failedEcho_grpc_recordsErrorType to verify that the error.type attribute is correctly recorded for gRPC failures.
    • Added testTracing_failedEcho_httpjson_recordsErrorType to verify that the error.type attribute is correctly recorded for HTTP/JSON failures.
Activity
  • Pull request created by diegomarquezp.
  • Initial implementation of error.type attribute for observability.
  • Added Javadoc for the new error type logic.
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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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 new observability attribute error.type to provide a more specific, low-cardinality classification of errors. The core logic is implemented in ObservabilityUtils.extractErrorType, which determines the error type based on a clear priority: ErrorInfo.reason, server error codes, specific client-side exceptions, and then fallbacks. The changes are well-supported by comprehensive unit tests in SpanTracerTest and integration tests in ITOtelTracing for both gRPC and HTTP/JSON transports, which is great to see.

My review includes one suggestion for a minor code simplification. Overall, this is a solid implementation.

Comment on lines +174 to +176
if (exceptionName != null && !exceptionName.isEmpty()) {
return exceptionName;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The check exceptionName != null is redundant. Class.getSimpleName() never returns null; it returns an empty string for anonymous classes, which is already handled by !exceptionName.isEmpty(). You can simplify this condition.

Suggested change
if (exceptionName != null && !exceptionName.isEmpty()) {
return exceptionName;
}
if (!exceptionName.isEmpty()) {
return exceptionName;
}
References
  1. This comment aligns with the principle of avoiding redundant null checks, similar to how validation within ApiTracerContext should be relied upon to prevent unnecessary checks.

@sonarqubecloud
Copy link

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed for 'java_showcase_integration_tests'

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

See analysis details on SonarQube Cloud

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.

1 participant