public class ErrorTypeUtilStatic Methods
extractErrorType(Throwable error)
public static String extractErrorType(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:
google.rpc.ErrorInfo.reason: If the error response from the service includesgoogle.rpc.ErrorInfodetails, the reason field (e.g., "RATE_LIMIT_EXCEEDED", "SERVICE_DISABLED") will be used. This offers the most precise error cause.- Specific Server Error Code: If no
ErrorInfo.reasonis 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").
- Client-Side Network/Operational Errors: For errors occurring within the client
library or network stack, mapping to specific enum representations from ErrorType. This includes checking the exception for diagnostic markers (e.g.,
ConnectExceptionorSocketTimeoutException). - 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. - 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.
| Parameter | |
|---|---|
| Name | Description |
error |
Throwablethe Throwable from which to extract the error type string. |
| Returns | |
|---|---|
| Type | Description |
String |
a low-cardinality string representing the specific error type |
Constructors
ErrorTypeUtil()
public ErrorTypeUtil()