Class ErrorTypeUtil

java.lang.Object
com.google.api.gax.tracing.ErrorTypeUtil

public class ErrorTypeUtil extends Object
  • Constructor Details

    • ErrorTypeUtil

      public ErrorTypeUtil()
  • Method Details

    • extractErrorType

      public static String extractErrorType(@Nonnull Throwable error)
      Extracts a low-cardinality string representing the specific classification of the error to be used in the ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE attribute.

      This value is determined based on the following priority:

      1. google.rpc.ErrorInfo.reason: If the error response from the service includes google.rpc.ErrorInfo details, the reason field (e.g., "RATE_LIMIT_EXCEEDED", "SERVICE_DISABLED") will be used. This offers the most precise error cause.
      2. Specific Server Error Code: If no ErrorInfo.reason is available and it is not a client-side failure, but a server error code was received:
        • For HTTP: The HTTP status code (e.g., "403", "503").
        • For gRPC: The gRPC status code name (e.g., "PERMISSION_DENIED", "UNAVAILABLE").
      3. Client-Side Network/Operational Errors: For errors occurring within the client library or network stack, mapping to specific enum representations from ErrorTypeUtil.ErrorType. This includes checking the exception for diagnostic markers (e.g., ConnectException or SocketTimeoutException).
      4. Language-specific error type: The class or struct name of the exception or error if available. This must be low-cardinality, meaning it returns the short name of the exception class (e.g. "IllegalStateException") rather than its message.
      5. Internal Fallback: If the error doesn't fit any of the above categories, "INTERNAL" will be used, indicating an unexpected issue within the client library's own logic.
      Parameters:
      error - the Throwable from which to extract the error type string.
      Returns:
      a low-cardinality string representing the specific error type