feat(gax): Add error attributes to golden signal metrics.#12564
Merged
feat(gax): Add error attributes to golden signal metrics.#12564
Conversation
This commit ensures that all required metrics attributes for Golden Signals are fully implemented in sdk-platform-java. Specifically: - Always populate `rpc.response.status_code` for both gRPC and HTTP transports. - Conditionally populate `http.response.status_code` only for HTTP transport. - Add `error.type` attribute to metrics exclusively on operation failures. - Ensured all other attributes (`gcp.client.service`, `rpc.system.name`, `rpc.method`, `url.domain`, `url.template`, `server.address`, `server.port`) are consistently populated from `ApiTracerContext.getMetricsAttributes()`.
Added additional test cases to GoldenSignalsMetricsTracerTest to ensure that ObservabilityUtils.extractErrorType is correctly translating various exceptions (like CancellationException, SocketTimeoutException, and IllegalArgumentException) into the appropriate error.type attributes during failure reporting.
Updated GoldenSignalsMetricsRecorder to automatically apply the library version retrieved from LibraryMetadata as the instrumentation version on the built OpenTelemetry Meter.
…Recorder Instead of manually extracting properties and passing separate tracking arguments to GoldenSignalsMetricsRecorder, this passes the entire LibraryMetadata model and builds the telemetry setup dynamically.
Removed repetitive check for LibraryMetadata and artifactName from GoldenSignalsMetricsTracerFactory#withContext. Instead, GoldenSignalsMetricsRecorder gracefully handles missing metadata by acting as a no-op instead of creating an underlying OpenTelemetry instrument.
Extracted the metadata validation into a static `create` method inside `GoldenSignalsMetricsRecorder`. This allows the recorder to own the validation logic while allowing `GoldenSignalsMetricsTracerFactory` to cleanly bail out and return a `BaseApiTracerFactory` if telemetry cannot be correctly constructed, maximizing performance by avoiding any tracer overhead without duplicating checks.
Added unit tests to `GoldenSignalsMetricsRecorderTest` to explicitly verify that `GoldenSignalsMetricsRecorder.create()` correctly intercepts invalid `LibraryMetadata` states (null values, missing artifact name, empty artifact name) and returns `null` as expected.
Cleaned up instances of fully qualified class references (LibraryMetadata, Strings, Nullable) by introducing proper Java import statements across GoldenSignalsMetricsRecorder and its associated tests.
Added `ITOtelGoldenMetrics` alongside `ITOtelTracing` to ensure that Golden Signals are correctly collected with accurate dimensional attributes (e.g., service name, status code, error type, port, addressing) across both the gRPC and HTTP/JSON runtime transports.
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors GoldenSignalsMetricsRecorder to use LibraryMetadata for instrumentation versioning and standardizes status attribute population in GoldenSignalsMetricsTracer and ObservabilityUtils. It also adds integration tests for OpenTelemetry metrics. Reviewers suggested simplifying metadata validation and ensuring the error.type attribute is consistently applied to cancelled operations.
...java/gax-java/gax/src/main/java/com/google/api/gax/tracing/GoldenSignalsMetricsRecorder.java
Show resolved
Hide resolved
...m-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/GoldenSignalsMetricsTracer.java
Outdated
Show resolved
Hide resolved
dee16a4 to
18c0a49
Compare
…te expectations and resolve test flakiness in ITOtelGoldenMetricsTest
...a/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/MyQuickTest.java
Outdated
Show resolved
Hide resolved
bac9623 to
232aeb8
Compare
diegomarquezp
approved these changes
Apr 2, 2026
This was referenced Apr 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR