GeezerVison is showing github.com — feat(storage): add StorageErrorTypeMapper for standard metrics by nidhiii-27 · Pull Request #14694 · googleapis/google-cloud-java
Conversation
nidhiii-27
commented
Oct 20, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Adds mapping logic to classify exceptions, gRPC status codes, and HTTP response codes into standard OpenTelemetry error types.
- Adds StorageErrorTypeMapper for error.type classification across gRPC, GAX, HTTP, auth, checksum, and client network/timeout exceptions.
- Adds comprehensive unit tests in StorageErrorTypeMapperTest.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
gemini-code-assist[bot] reacted with eyes emoji
There was a problem hiding this 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 comprehensive support for OpenTelemetry client metrics and debug metrics in Google Cloud Storage, including configuration options in StorageOptions, GrpcStorageOptions, and HttpStorageOptions. It adds utility classes such as StorageClientMetrics for instrument registration, StorageErrorTypeMapper for mapping exceptions to canonical error strings, StorageMetricsConfig for environment-based configuration, and StorageMetricsContext for tracking metric state across boundaries, along with corresponding unit tests. Feedback on the changes suggests simplifying a redundant null check on a transient field in StorageOptions, defensively preventing infinite loops from self-causation in StorageErrorTypeMapper's exception unwrapping, and robustly checking for authentication exceptions by using full class names instead of simple names to correctly handle anonymous classes.
I am having trouble creating individual review comments. Click here to see my feedback.
java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageOptions.java (262)

Since meterProvider is marked as transient, it will not be serialized and will always be null after deserialization. Therefore, the check this.meterProvider != null in readObject is redundant and will always evaluate to false. We can simplify this to only check this.customMeterProviderConfigured.
if (this.customMeterProviderConfigured) {
java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageErrorTypeMapper.java (159-162)

To prevent potential infinite loops in case of custom exceptions with self-causation (where t.getCause() == t), we should defensively add a check for t.getCause() != t in the while loop condition, similar to how it is handled at the end of the mapThrowable method.
while ((t instanceof ExecutionException || t instanceof CompletionException)
&& t.getCause() != null
&& t.getCause() != t) {
t = t.getCause();
}
java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageErrorTypeMapper.java (258)

Using t.getClass().getSimpleName() can return an empty string "" for anonymous classes, which would bypass the contains("Auth") check even if the base class name contains "Auth". Using the full class name className.contains("Auth") is more robust and avoids extra string parsing overhead.
if (className.contains("Auth")) {
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
nidhiii-27
added a commit
that referenced
this pull request
Oct 20, 2026
- Map HTTP 401 to UNAUTHENTICATED and HTTP 502 to UNAVAILABLE.
- Guard against self-causation cycles in ExecutionException/CompletionException loops.
- Check hasSpecificClientCause on StatusRuntimeException, StatusException, and ApiException before status code mapping.
- Support cause unwrapping for gRPC exceptions on StorageException.
- Add unit tests for gRPC network causes and self-referencing exceptions.
[Generated-by: AI]
…nfiguration
- Add configuration options to StorageOptions, GrpcStorageOptions, and HttpStorageOptions (enableOtelMetrics, enableOtelDebugMetrics, meterProvider, metricInterval).
- Add development gate checking system properties and environment variables in StorageMetricsConfig.
- Implement package-private instrument registry in StorageClientMetrics.
- Update OpenTelemetryBootstrappingUtils to register client views with custom histogram boundaries and create client meter provider.
- Add comprehensive unit tests in StorageOptionsTest, StorageClientMetricsTest, and OpenTelemetryBootstrappingUtilsTest.
Apply spotify fmt-maven-plugin formatting to StorageMetricsConfig, StorageClientMetrics, StorageOptionsTest, and StorageClientMetricsTest.
[Generated-by: AI]
Use simple class name Duration instead of fully qualified java.time.Duration in GrpcStorageOptions and OpenTelemetryBootstrappingUtils.
[Generated-by: AI]
…trappingUtils
Apply spotify fmt-maven-plugin formatting to OpenTelemetryBootstrappingUtils.
[Generated-by: AI]
…nd views [Generated-by: AI]
… metrics
Refactor addClientHistogramView in OpenTelemetryBootstrappingUtils to remove unit selector and custom view description, preserving instrument default descriptions.
Remove deferred Phase 2 connection metrics (dnsLookupDuration, tcpConnectDuration, tlsHandshakeDuration) from StorageClientMetrics, CLIENT_LATENCY_HISTOGRAMS, and StorageClientMetricsTest.
Ensure clean Duration imports.
[Generated-by: AI]
…rProvider
Default api parameter to "grpc" instead of "storage" in createClientMeterProvider, allow specifying "json" / "http" transport protocols for Cloud Monitoring monitored resource storage.googleapis.com/Client, and add unit test coverage in OpenTelemetryBootstrappingUtilsTest.
[Generated-by: AI]
Update createClientMeterProvider to use prefix custom.googleapis.com with default monitored resource mapping.
Add KEY_URL_TEMPLATE attribute key constant in StorageClientMetrics.
[Generated-by: AI]
…for default monitored resource
…geClientMetricsTest [Generated-by: AI]
…eErrorTypeMapper [Generated-by: AI]
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
… tests
- Walk the class hierarchy in isAuthException to support anonymous and custom subclasses, and remove redundant simpleName check.
- Extract mapSpecificClientCause and mapKnownCause helpers and check specific client causes on HttpResponseException.
- Guard against null StatusCode on ApiException.
- Restrict single-use HTTP mapping status constants to private visibility, use Ascii.toLowerCase, add boolean parameter comments, and move private constructor to bottom of class.
- Split multi-behavior tests in StorageErrorTypeMapperTest, deduplicate test exception classes and CRC32C fixtures, and import SigningException.
[Generated-by: AI]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few changes needed to align error.type values with the Go SDK and metric schema:
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Consolidate CONNECTION_REFUSED, CONNECTION_RESET, and CONNECTIVITY into CONNECTION_ERROR.
- Keep DEADLINE_EXCEEDED for server/RPC status codes and HTTP 408/504, reserving TIMEOUT for client timeouts.
- Map HTTP 409 to ABORTED.
- Include IOException in hasSpecificClientCause so wrapped IOExceptions map to CONNECTION_ERROR.
- Match server-side CRC32C and MD5 checksum mismatch messages in isChecksumMismatch.
[Generated-by: AI]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall! Approving to unblock, with a couple of small comments to address before merging.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Check status.getCause() and server checksum mismatch descriptions on INVALID_ARGUMENT and DATA_LOSS in mapGrpcStatus
- Simplify StorageException cause handling in mapThrowable by calling mapKnownCause directly
- Restrict (crc32c || md5) && match server checksum error pattern to HTTP 400 and gRPC INVALID_ARGUMENT / DATA_LOSS
- Add unit tests for mapGrpcStatus causes/descriptions and negative 404/412 checksum message cases
[Generated-by: AI]
…ic-libraries-bom
[Generated-by: AI]
… entry points
[Generated-by: AI]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly looks good, left one minor nit inline.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
nidhiii-27
added a commit
that referenced
this pull request
Nov 7, 2026
…Interceptor
- Merge updated base branch feat/storage-rpc-call-duration (including #14694)
- Update HttpIOExceptionHandler error type to StorageErrorTypeMapper.STATUS_CONNECTION_ERROR
- Return "/storage/v1/b" in extractV1UrlTemplate when rest is "b" (CreateBucket / ListBuckets)
[Generated-by: AI]
nidhiii-27
added a commit
that referenced
this pull request
Nov 7, 2026
… mapping
After merging StorageErrorTypeMapper updates from #14694, Status.DEADLINE_EXCEEDED
maps to DEADLINE_EXCEEDED while SocketTimeoutException maps to TIMEOUT. Update
recordAttemptError_specificExceptions_mappedToCanonicalTypes to assert 1 count
each for DEADLINE_EXCEEDED, TIMEOUT, and DNS_FAILURE.
[Generated-by: AI]
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…n StorageErrorTypeMapper
- Reword class Javadoc to remove HLD acronym.
- Delegate StatusRuntimeException and StatusException directly to mapGrpcStatus.
- Cap cause-chain traversal depth (MAX_CAUSE_DEPTH = 20) across mapGrpcStatus and mapThrowable to guard against multi-node cause cycles (A -> B -> A).
[Generated-by: AI]
Uh oh!
There was an error while loading. Please reload this page.
nidhiii-27
added a commit
that referenced
this pull request
Nov 11, 2026
…14728)
Introduces `StorageMetricsContext` for tracking per-operation and
per-attempt OpenTelemetry metrics state.
- Adds `StorageMetricsContext` to manage operation attributes, attempt
counters, and durations.
- Adds `StorageMetricsContextTest` unit tests.
Stacked on #14694.
Reviewers
Dhriti07
Dhriti07 approved these changes
+1 more reviewer
Reviewers whose approvals may not affect merge requirements
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|