From 86b9e946dbaffea624a2ce1480056e5e07ab5445 Mon Sep 17 00:00:00 2001 From: blakeli Date: Fri, 3 Apr 2026 17:55:37 -0400 Subject: [PATCH 1/6] fix: update observability attributes and tests --- .../api/gax/tracing/ApiTracerContext.java | 16 +- .../tracing/GoldenSignalsMetricsTracer.java | 10 +- .../api/gax/tracing/ObservabilityUtils.java | 14 +- .../google/api/gax/tracing/SpanTracer.java | 23 +-- .../api/gax/tracing/ApiTracerContextTest.java | 22 --- .../GoldenSignalsMetricsTracerTest.java | 20 +- .../gax/tracing/ObservabilityUtilsTest.java | 42 ++--- .../api/gax/tracing/SpanTracerTest.java | 177 +++++++++++------- .../showcase/v1beta1/it/ITOtelTracing.java | 2 - 9 files changed, 171 insertions(+), 155 deletions(-) diff --git a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracerContext.java b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracerContext.java index ab2c92e60547..068af971233e 100644 --- a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracerContext.java +++ b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/ApiTracerContext.java @@ -220,17 +220,8 @@ public Map getAttemptAttributes() { if (rpcSystemName() != null) { attributes.put(ObservabilityAttributes.RPC_SYSTEM_NAME_ATTRIBUTE, rpcSystemName()); } - if (!libraryMetadata().isEmpty()) { - if (!Strings.isNullOrEmpty(libraryMetadata().repository())) { - attributes.put(ObservabilityAttributes.REPO_ATTRIBUTE, libraryMetadata().repository()); - } - if (!Strings.isNullOrEmpty(libraryMetadata().artifactName())) { - attributes.put( - ObservabilityAttributes.ARTIFACT_ATTRIBUTE, libraryMetadata().artifactName()); - } - if (!Strings.isNullOrEmpty(libraryMetadata().version())) { - attributes.put(ObservabilityAttributes.VERSION_ATTRIBUTE, libraryMetadata().version()); - } + if (!libraryMetadata().isEmpty() && !Strings.isNullOrEmpty(libraryMetadata().repository())) { + attributes.put(ObservabilityAttributes.REPO_ATTRIBUTE, libraryMetadata().repository()); } if (transport() == Transport.GRPC && !Strings.isNullOrEmpty(fullMethodName())) { attributes.put(ObservabilityAttributes.GRPC_RPC_METHOD_ATTRIBUTE, fullMethodName()); @@ -264,6 +255,9 @@ Map getMetricsAttributes() { if (serverPort() != null) { attributes.put(ObservabilityAttributes.SERVER_PORT_ATTRIBUTE, serverPort()); } + if (!libraryMetadata().isEmpty() && !Strings.isNullOrEmpty(libraryMetadata().repository())) { + attributes.put(ObservabilityAttributes.REPO_ATTRIBUTE, libraryMetadata().repository()); + } if (!Strings.isNullOrEmpty(serviceName())) { attributes.put(ObservabilityAttributes.GCP_CLIENT_SERVICE_ATTRIBUTE, serviceName()); } diff --git a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/GoldenSignalsMetricsTracer.java b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/GoldenSignalsMetricsTracer.java index f24bed478ee7..a59c49126a37 100644 --- a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/GoldenSignalsMetricsTracer.java +++ b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/GoldenSignalsMetricsTracer.java @@ -75,9 +75,7 @@ class GoldenSignalsMetricsTracer implements ApiTracer { */ @Override public void operationSucceeded() { - ObservabilityUtils.populateStatusAttributes(attributes, null, transport); - metricsRecorder.recordOperationLatency( - clientRequestTimer.elapsed(TimeUnit.NANOSECONDS) / 1_000_000_000.0, attributes); + recordError(null); } @Override @@ -91,9 +89,9 @@ public void operationFailed(Throwable error) { } private void recordError(Throwable error) { - ObservabilityUtils.populateStatusAttributes(attributes, error, transport); - attributes.put( - ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE, ObservabilityUtils.extractErrorType(error)); + Map errorAttributes = + ObservabilityUtils.populateErrorAttributes(error, transport); + attributes.putAll(errorAttributes); metricsRecorder.recordOperationLatency( clientRequestTimer.elapsed(TimeUnit.NANOSECONDS) / 1_000_000_000.0, attributes); } diff --git a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/ObservabilityUtils.java b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/ObservabilityUtils.java index f538d0807e78..3a5384740531 100644 --- a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/ObservabilityUtils.java +++ b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/ObservabilityUtils.java @@ -37,6 +37,7 @@ import com.google.rpc.ErrorInfo; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.AttributesBuilder; +import java.util.HashMap; import java.util.Map; import java.util.concurrent.CancellationException; import javax.annotation.Nullable; @@ -170,16 +171,21 @@ private static String redactSensitiveQueryValues(final String rawQuery) { return Joiner.on('&').join(redactedParams); } - static void populateStatusAttributes( - Map attributes, - @Nullable Throwable error, - ApiTracerContext.Transport transport) { + static Map populateErrorAttributes( + @Nullable Throwable error, ApiTracerContext.Transport transport) { + Map attributes = new HashMap<>(); StatusCode.Code code = extractStatus(error); attributes.put(ObservabilityAttributes.RPC_RESPONSE_STATUS_ATTRIBUTE, code.toString()); if (transport == ApiTracerContext.Transport.HTTP) { attributes.put( ObservabilityAttributes.HTTP_RESPONSE_STATUS_ATTRIBUTE, (long) code.getHttpStatusCode()); } + if (error != null) { + attributes.put( + ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE, ObservabilityUtils.extractErrorType(error)); + attributes.put(ObservabilityAttributes.EXCEPTION_TYPE_ATTRIBUTE, error.getClass().getName()); + } + return attributes; } /** Function to extract the ErrorInfo payload from the error, if available */ diff --git a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/SpanTracer.java b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/SpanTracer.java index 01fc07531442..4fb0a43b463b 100644 --- a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/SpanTracer.java +++ b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/SpanTracer.java @@ -217,26 +217,13 @@ private void recordErrorAndEndAttempt(Throwable error) { if (attemptSpan == null) { return; } - - Map statusAttributes = new HashMap<>(); - ObservabilityUtils.populateStatusAttributes( - statusAttributes, error, this.apiTracerContext.transport()); - if (!statusAttributes.isEmpty()) { - attemptSpan.setAllAttributes(ObservabilityUtils.toOtelAttributes(statusAttributes)); - } - - if (error == null) { - endAttempt(); - return; + Map errorAttributes = + ObservabilityUtils.populateErrorAttributes(error, this.apiTracerContext.transport()); + if (!errorAttributes.isEmpty()) { + attemptSpan.setAllAttributes(ObservabilityUtils.toOtelAttributes(errorAttributes)); } - attemptSpan.setAttribute( - ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE, ObservabilityUtils.extractErrorType(error)); - - attemptSpan.setAttribute( - ObservabilityAttributes.EXCEPTION_TYPE_ATTRIBUTE, error.getClass().getName()); - - if (!Strings.isNullOrEmpty(error.getMessage())) { + if (error != null && !Strings.isNullOrEmpty(error.getMessage())) { attemptSpan.setAttribute( ObservabilityAttributes.STATUS_MESSAGE_ATTRIBUTE, error.getMessage()); } diff --git a/sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/ApiTracerContextTest.java b/sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/ApiTracerContextTest.java index 6b1109ae8f42..9c0c01e54408 100644 --- a/sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/ApiTracerContextTest.java +++ b/sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/ApiTracerContextTest.java @@ -62,28 +62,6 @@ void testGetAttemptAttributes_repo() { assertThat(attributes).containsEntry(ObservabilityAttributes.REPO_ATTRIBUTE, "test-repo"); } - @Test - void testGetAttemptAttributes_artifact() { - LibraryMetadata libraryMetadata = - LibraryMetadata.newBuilder().setArtifactName("test-artifact").build(); - ApiTracerContext context = - ApiTracerContext.newBuilder().setLibraryMetadata(libraryMetadata).build(); - Map attributes = context.getAttemptAttributes(); - - assertThat(attributes) - .containsEntry(ObservabilityAttributes.ARTIFACT_ATTRIBUTE, "test-artifact"); - } - - @Test - void testGetAttemptAttributes_version() { - LibraryMetadata libraryMetadata = LibraryMetadata.newBuilder().setVersion("1.2.3").build(); - ApiTracerContext context = - ApiTracerContext.newBuilder().setLibraryMetadata(libraryMetadata).build(); - Map attributes = context.getAttemptAttributes(); - - assertThat(attributes).containsEntry(ObservabilityAttributes.VERSION_ATTRIBUTE, "1.2.3"); - } - @Test void testGetAttemptAttributes_httpMethod() { ApiTracerContext context = diff --git a/sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/GoldenSignalsMetricsTracerTest.java b/sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/GoldenSignalsMetricsTracerTest.java index 5a4377300765..8f6a6d7eef1d 100644 --- a/sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/GoldenSignalsMetricsTracerTest.java +++ b/sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/GoldenSignalsMetricsTracerTest.java @@ -138,7 +138,9 @@ void operationCancelled_shouldRecordsOKStatus() { AttributeKey.stringKey(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE), "CancellationException", AttributeKey.stringKey(RPC_RESPONSE_STATUS_ATTRIBUTE), - StatusCode.Code.CANCELLED.toString())); + StatusCode.Code.CANCELLED.toString(), + AttributeKey.stringKey(ObservabilityAttributes.EXCEPTION_TYPE_ATTRIBUTE), + java.util.concurrent.CancellationException.class.getName())); } @Test @@ -174,7 +176,9 @@ void operationFailed_shouldRecordsOKStatus() { AttributeKey.stringKey(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE), "INTERNAL", AttributeKey.stringKey(RPC_RESPONSE_STATUS_ATTRIBUTE), - StatusCode.Code.INTERNAL.toString())); + StatusCode.Code.INTERNAL.toString(), + AttributeKey.stringKey(ObservabilityAttributes.EXCEPTION_TYPE_ATTRIBUTE), + com.google.api.gax.rpc.ApiException.class.getName())); } @Test @@ -194,7 +198,9 @@ void operationFailed_shouldRecordCancellationException() { AttributeKey.stringKey(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE), "CancellationException", AttributeKey.stringKey(RPC_RESPONSE_STATUS_ATTRIBUTE), - StatusCode.Code.CANCELLED.toString())); + StatusCode.Code.CANCELLED.toString(), + AttributeKey.stringKey(ObservabilityAttributes.EXCEPTION_TYPE_ATTRIBUTE), + java.util.concurrent.CancellationException.class.getName())); } @Test @@ -213,7 +219,9 @@ void operationFailed_shouldRecordClientTimeout() { AttributeKey.stringKey(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE), "CLIENT_TIMEOUT", AttributeKey.stringKey(RPC_RESPONSE_STATUS_ATTRIBUTE), - StatusCode.Code.UNKNOWN.toString())); + StatusCode.Code.UNKNOWN.toString(), + AttributeKey.stringKey(ObservabilityAttributes.EXCEPTION_TYPE_ATTRIBUTE), + java.net.SocketTimeoutException.class.getName())); } @Test @@ -232,6 +240,8 @@ void operationFailed_shouldRecordClientRequestError() { AttributeKey.stringKey(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE), "CLIENT_REQUEST_ERROR", AttributeKey.stringKey(RPC_RESPONSE_STATUS_ATTRIBUTE), - StatusCode.Code.UNKNOWN.toString())); + StatusCode.Code.UNKNOWN.toString(), + AttributeKey.stringKey(ObservabilityAttributes.EXCEPTION_TYPE_ATTRIBUTE), + java.lang.IllegalArgumentException.class.getName())); } } diff --git a/sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/ObservabilityUtilsTest.java b/sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/ObservabilityUtilsTest.java index bebbc89dd16c..644798f44a83 100644 --- a/sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/ObservabilityUtilsTest.java +++ b/sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/ObservabilityUtilsTest.java @@ -115,36 +115,36 @@ void testToOtelAttributes_shouldMapIntAttributes() { } @Test - void testPopulateStatusAttributes_grpc_success() { - Map attributes = new java.util.HashMap<>(); - ObservabilityUtils.populateStatusAttributes(attributes, null, ApiTracerContext.Transport.GRPC); + void testPopulateErrorAttributes_grpc_success() { + Map attributes = + ObservabilityUtils.populateErrorAttributes(null, ApiTracerContext.Transport.GRPC); assertThat(attributes) .containsEntry(ObservabilityAttributes.RPC_RESPONSE_STATUS_ATTRIBUTE, "OK"); } @Test - void testPopulateStatusAttributes_grpc_apiException() { - Map attributes = new java.util.HashMap<>(); + void testPopulateErrorAttributes_grpc_apiException() { ApiException error = new ApiException("fake_error", null, new FakeStatusCode(StatusCode.Code.NOT_FOUND), false); - ObservabilityUtils.populateStatusAttributes(attributes, error, ApiTracerContext.Transport.GRPC); + Map attributes = + ObservabilityUtils.populateErrorAttributes(error, ApiTracerContext.Transport.GRPC); assertThat(attributes) .containsEntry(ObservabilityAttributes.RPC_RESPONSE_STATUS_ATTRIBUTE, "NOT_FOUND"); } @Test - void testPopulateStatusAttributes_grpc_cancellationException() { - Map attributes = new java.util.HashMap<>(); + void testPopulateErrorAttributes_grpc_cancellationException() { Throwable error = new java.util.concurrent.CancellationException(); - ObservabilityUtils.populateStatusAttributes(attributes, error, ApiTracerContext.Transport.GRPC); + Map attributes = + ObservabilityUtils.populateErrorAttributes(error, ApiTracerContext.Transport.GRPC); assertThat(attributes) .containsEntry(ObservabilityAttributes.RPC_RESPONSE_STATUS_ATTRIBUTE, "CANCELLED"); } @Test - void testPopulateStatusAttributes_http_success() { - Map attributes = new java.util.HashMap<>(); - ObservabilityUtils.populateStatusAttributes(attributes, null, ApiTracerContext.Transport.HTTP); + void testPopulateErrorAttributes_http_success() { + Map attributes = + ObservabilityUtils.populateErrorAttributes(null, ApiTracerContext.Transport.HTTP); assertThat(attributes) .containsEntry( ObservabilityAttributes.HTTP_RESPONSE_STATUS_ATTRIBUTE, @@ -152,8 +152,7 @@ void testPopulateStatusAttributes_http_success() { } @Test - void testPopulateStatusAttributes_http_apiExceptionWithIntegerTransportCode() { - Map attributes = new java.util.HashMap<>(); + void testPopulateErrorAttributes_http_apiExceptionWithIntegerTransportCode() { ApiException error = new ApiException( "fake_error", @@ -170,7 +169,8 @@ public Object getTransportCode() { } }, false); - ObservabilityUtils.populateStatusAttributes(attributes, error, ApiTracerContext.Transport.HTTP); + Map attributes = + ObservabilityUtils.populateErrorAttributes(error, ApiTracerContext.Transport.HTTP); assertThat(attributes) .containsEntry( ObservabilityAttributes.HTTP_RESPONSE_STATUS_ATTRIBUTE, @@ -178,8 +178,7 @@ public Object getTransportCode() { } @Test - void testPopulateStatusAttributes_http_apiExceptionWithNonIntegerTransportCode() { - Map attributes = new java.util.HashMap<>(); + void testPopulateErrorAttributes_http_apiExceptionWithNonIntegerTransportCode() { ApiException error = new ApiException( "fake_error", @@ -196,7 +195,8 @@ public Object getTransportCode() { } }, false); - ObservabilityUtils.populateStatusAttributes(attributes, error, ApiTracerContext.Transport.HTTP); + Map attributes = + ObservabilityUtils.populateErrorAttributes(error, ApiTracerContext.Transport.HTTP); assertThat(attributes) .containsEntry( ObservabilityAttributes.HTTP_RESPONSE_STATUS_ATTRIBUTE, @@ -204,10 +204,10 @@ public Object getTransportCode() { } @Test - void testPopulateStatusAttributes_http_cancellationException() { - Map attributes = new java.util.HashMap<>(); + void testPopulateErrorAttributes_http_cancellationException() { Throwable error = new java.util.concurrent.CancellationException(); - ObservabilityUtils.populateStatusAttributes(attributes, error, ApiTracerContext.Transport.HTTP); + Map attributes = + ObservabilityUtils.populateErrorAttributes(error, ApiTracerContext.Transport.HTTP); assertThat(attributes) .containsEntry( ObservabilityAttributes.HTTP_RESPONSE_STATUS_ATTRIBUTE, diff --git a/sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/SpanTracerTest.java b/sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/SpanTracerTest.java index a14d6a6777e0..580974243b6b 100644 --- a/sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/SpanTracerTest.java +++ b/sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/SpanTracerTest.java @@ -43,6 +43,7 @@ import com.google.common.collect.ImmutableList; import com.google.protobuf.Any; import com.google.rpc.ErrorInfo; +import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.SpanBuilder; @@ -50,6 +51,7 @@ import io.opentelemetry.api.trace.Tracer; import java.net.ConnectException; import java.net.SocketTimeoutException; +import java.util.Map; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -102,9 +104,7 @@ void testAttemptSucceeded_grpc() { assertThat(attrsCaptor.getValue().asMap()) .containsEntry( - io.opentelemetry.api.common.AttributeKey.stringKey( - ObservabilityAttributes.RPC_RESPONSE_STATUS_ATTRIBUTE), - "OK"); + AttributeKey.stringKey(ObservabilityAttributes.RPC_RESPONSE_STATUS_ATTRIBUTE), "OK"); } @Test @@ -125,16 +125,14 @@ void testAttemptSucceeded_http() { assertThat(attrsCaptor.getValue().asMap()) .containsEntry( - io.opentelemetry.api.common.AttributeKey.longKey( - ObservabilityAttributes.HTTP_RESPONSE_STATUS_ATTRIBUTE), - 200L); + AttributeKey.longKey(ObservabilityAttributes.HTTP_RESPONSE_STATUS_ATTRIBUTE), 200L); } @Test void testResponseHeadersReceived_setsContentLengthAttribute() { spanTracer.attemptStarted(new Object(), 1); - java.util.Map headers = new java.util.HashMap<>(); + Map headers = new java.util.HashMap<>(); headers.put("Content-Length", 12345L); spanTracer.responseHeadersReceived(headers); @@ -145,7 +143,7 @@ void testResponseHeadersReceived_setsContentLengthAttribute() { void testResponseHeadersReceived_variousContentLengthStringFormats() { spanTracer.attemptStarted(new Object(), 1); - java.util.Map headers = new java.util.HashMap<>(); + Map headers = new java.util.HashMap<>(); headers.put("content-length", "6789"); spanTracer.responseHeadersReceived(headers); @@ -156,7 +154,7 @@ void testResponseHeadersReceived_variousContentLengthStringFormats() { void testResponseHeadersReceived_missingContentLength() { spanTracer.attemptStarted(new Object(), 1); - java.util.Map headers = new java.util.HashMap<>(); + Map headers = new java.util.HashMap<>(); headers.put("Other-Header", "123"); spanTracer.responseHeadersReceived(headers); @@ -170,7 +168,7 @@ void testResponseHeadersReceived_missingContentLength() { void testResponseHeadersReceived_badFormat() { spanTracer.attemptStarted(new Object(), 1); - java.util.Map headers = new java.util.HashMap<>(); + Map headers = new java.util.HashMap<>(); headers.put("Content-Length", "12X3"); spanTracer.responseHeadersReceived(headers); @@ -184,7 +182,7 @@ void testResponseHeadersReceived_badFormat() { void testResponseHeadersReceived_listContentLength() { spanTracer.attemptStarted(new Object(), 1); - java.util.Map headers = new java.util.HashMap<>(); + Map headers = new java.util.HashMap<>(); headers.put("Content-Length", java.util.Arrays.asList(98765L)); spanTracer.responseHeadersReceived(headers); @@ -205,12 +203,10 @@ void testAttemptStarted_noRetryAttributes_grpc() { verify(spanBuilder).setAllAttributes(attributesCaptor.capture()); assertThat(attributesCaptor.getValue().asMap()) .doesNotContainKey( - io.opentelemetry.api.common.AttributeKey.longKey( - ObservabilityAttributes.GRPC_RESEND_COUNT_ATTRIBUTE)); + AttributeKey.longKey(ObservabilityAttributes.GRPC_RESEND_COUNT_ATTRIBUTE)); assertThat(attributesCaptor.getValue().asMap()) .doesNotContainKey( - io.opentelemetry.api.common.AttributeKey.longKey( - ObservabilityAttributes.HTTP_RESEND_COUNT_ATTRIBUTE)); + AttributeKey.longKey(ObservabilityAttributes.HTTP_RESEND_COUNT_ATTRIBUTE)); } @Test @@ -248,8 +244,7 @@ public Object getTransportCode() { assertThat(attrsCaptor.getValue().asMap()) .containsEntry( - io.opentelemetry.api.common.AttributeKey.stringKey( - ObservabilityAttributes.RPC_RESPONSE_STATUS_ATTRIBUTE), + AttributeKey.stringKey(ObservabilityAttributes.RPC_RESPONSE_STATUS_ATTRIBUTE), "NOT_FOUND"); } @@ -266,17 +261,13 @@ void testAttemptStarted_retryAttributes_grpc() { grpcTracer.attemptStarted(new Object(), 5); ArgumentCaptor attributesCaptor = ArgumentCaptor.forClass(Attributes.class); verify(spanBuilder).setAllAttributes(attributesCaptor.capture()); - java.util.Map, Object> capturedAttributes = - attributesCaptor.getValue().asMap(); + Map, Object> capturedAttributes = attributesCaptor.getValue().asMap(); assertThat(capturedAttributes) .containsEntry( - io.opentelemetry.api.common.AttributeKey.longKey( - ObservabilityAttributes.GRPC_RESEND_COUNT_ATTRIBUTE), - 5L); + AttributeKey.longKey(ObservabilityAttributes.GRPC_RESEND_COUNT_ATTRIBUTE), 5L); assertThat(capturedAttributes) .doesNotContainKey( - io.opentelemetry.api.common.AttributeKey.longKey( - ObservabilityAttributes.HTTP_RESEND_COUNT_ATTRIBUTE)); + AttributeKey.longKey(ObservabilityAttributes.HTTP_RESEND_COUNT_ATTRIBUTE)); } @Test @@ -314,9 +305,7 @@ public Object getTransportCode() { assertThat(attrsCaptor.getValue().asMap()) .containsEntry( - io.opentelemetry.api.common.AttributeKey.longKey( - ObservabilityAttributes.HTTP_RESPONSE_STATUS_ATTRIBUTE), - 404L); + AttributeKey.longKey(ObservabilityAttributes.HTTP_RESPONSE_STATUS_ATTRIBUTE), 404L); } @Test @@ -332,16 +321,13 @@ void testAttemptStarted_noRetryAttributes_http() { httpTracer.attemptStarted(new Object(), 0); ArgumentCaptor attributesCaptor = ArgumentCaptor.forClass(Attributes.class); verify(spanBuilder).setAllAttributes(attributesCaptor.capture()); - java.util.Map, Object> capturedAttributes = - attributesCaptor.getValue().asMap(); + Map, Object> capturedAttributes = attributesCaptor.getValue().asMap(); assertThat(capturedAttributes) .doesNotContainKey( - io.opentelemetry.api.common.AttributeKey.longKey( - ObservabilityAttributes.GRPC_RESEND_COUNT_ATTRIBUTE)); + AttributeKey.longKey(ObservabilityAttributes.GRPC_RESEND_COUNT_ATTRIBUTE)); assertThat(capturedAttributes) .doesNotContainKey( - io.opentelemetry.api.common.AttributeKey.longKey( - ObservabilityAttributes.HTTP_RESEND_COUNT_ATTRIBUTE)); + AttributeKey.longKey(ObservabilityAttributes.HTTP_RESEND_COUNT_ATTRIBUTE)); } @Test @@ -357,17 +343,13 @@ void testAttemptStarted_retryAttributes_http() { httpTracer.attemptStarted(new Object(), 5); ArgumentCaptor attributesCaptor = ArgumentCaptor.forClass(Attributes.class); verify(spanBuilder).setAllAttributes(attributesCaptor.capture()); - java.util.Map, Object> capturedAttributes = - attributesCaptor.getValue().asMap(); + Map, Object> capturedAttributes = attributesCaptor.getValue().asMap(); assertThat(capturedAttributes) .doesNotContainKey( - io.opentelemetry.api.common.AttributeKey.longKey( - ObservabilityAttributes.GRPC_RESEND_COUNT_ATTRIBUTE)); + AttributeKey.longKey(ObservabilityAttributes.GRPC_RESEND_COUNT_ATTRIBUTE)); assertThat(capturedAttributes) .containsEntry( - io.opentelemetry.api.common.AttributeKey.longKey( - ObservabilityAttributes.HTTP_RESEND_COUNT_ATTRIBUTE), - 5L); + AttributeKey.longKey(ObservabilityAttributes.HTTP_RESEND_COUNT_ATTRIBUTE), 5L); } @Test @@ -398,7 +380,14 @@ public Object getTransportCode() { spanTracer.attemptFailedRetriesExhausted(apiException); - verify(span).setAttribute(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE, "RATE_LIMIT_EXCEEDED"); + ArgumentCaptor attrsCaptor = ArgumentCaptor.forClass(Attributes.class); + verify(span).setAllAttributes(attrsCaptor.capture()); + Map, Object> capturedAttributes = attrsCaptor.getValue().asMap(); + assertThat(capturedAttributes) + .containsEntry( + AttributeKey.stringKey(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE), + "RATE_LIMIT_EXCEEDED"); + verify(span).end(); } @@ -425,12 +414,26 @@ public Object getTransportCode() { spanTracer.attemptFailedRetriesExhausted(apiException); - verify(span).setAttribute(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE, "PERMISSION_DENIED"); + ArgumentCaptor attrsCaptor = ArgumentCaptor.forClass(Attributes.class); + verify(span).setAllAttributes(attrsCaptor.capture()); + Map, Object> capturedAttributes = attrsCaptor.getValue().asMap(); + assertThat(capturedAttributes) + .containsEntry( + AttributeKey.stringKey(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE), + "PERMISSION_DENIED"); + verify(span).end(); } @Test void testAttemptFailed_specificServerErrorCodeHttp() { + ApiTracerContext context = + ApiTracerContext.newBuilder() + .setLibraryMetadata(com.google.api.gax.rpc.LibraryMetadata.empty()) + .setTransport(ApiTracerContext.Transport.HTTP) + .build(); + spanTracer = new SpanTracer(tracer, context, ATTEMPT_SPAN_NAME); + spanTracer.attemptStarted(new Object(), 1); ApiException apiException = @@ -452,7 +455,12 @@ public Object getTransportCode() { spanTracer.attemptFailedRetriesExhausted(apiException); - verify(span).setAttribute(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE, "403"); + ArgumentCaptor attrsCaptor = ArgumentCaptor.forClass(Attributes.class); + verify(span).setAllAttributes(attrsCaptor.capture()); + Map, Object> capturedAttributes = attrsCaptor.getValue().asMap(); + assertThat(capturedAttributes) + .containsEntry(AttributeKey.stringKey(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE), "403"); + verify(span).end(); } @@ -462,10 +470,14 @@ void testAttemptFailed_clientTimeout() { spanTracer.attemptFailedRetriesExhausted(new SocketTimeoutException()); - verify(span) - .setAttribute( - ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE, + ArgumentCaptor attrsCaptor = ArgumentCaptor.forClass(Attributes.class); + verify(span).setAllAttributes(attrsCaptor.capture()); + Map, Object> capturedAttributes = attrsCaptor.getValue().asMap(); + assertThat(capturedAttributes) + .containsEntry( + AttributeKey.stringKey(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE), ErrorTypeUtil.ErrorType.CLIENT_TIMEOUT.toString()); + verify(span).end(); } @@ -475,10 +487,14 @@ void testAttemptFailed_clientConnectionError() { spanTracer.attemptFailedRetriesExhausted(new ConnectException("connection failed")); - verify(span) - .setAttribute( - ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE, + ArgumentCaptor attrsCaptor = ArgumentCaptor.forClass(Attributes.class); + verify(span).setAllAttributes(attrsCaptor.capture()); + Map, Object> capturedAttributes = attrsCaptor.getValue().asMap(); + assertThat(capturedAttributes) + .containsEntry( + AttributeKey.stringKey(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE), ErrorTypeUtil.ErrorType.CLIENT_CONNECTION_ERROR.toString()); + verify(span).end(); } @@ -488,7 +504,13 @@ void testAttemptFailed_clientRedirectError() { spanTracer.attemptFailedRetriesExhausted(new RedirectException("redirect failed")); - verify(span).setAttribute(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE, "RedirectException"); + ArgumentCaptor attrsCaptor = ArgumentCaptor.forClass(Attributes.class); + verify(span).setAllAttributes(attrsCaptor.capture()); + Map, Object> capturedAttributes = attrsCaptor.getValue().asMap(); + assertThat(capturedAttributes) + .containsEntry( + AttributeKey.stringKey(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE), + "RedirectException"); verify(span).end(); } @@ -498,9 +520,12 @@ void testAttemptFailed_clientRequestError() { spanTracer.attemptFailedRetriesExhausted(new IllegalArgumentException()); - verify(span) - .setAttribute( - ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE, + ArgumentCaptor attrsCaptor = ArgumentCaptor.forClass(Attributes.class); + verify(span).setAllAttributes(attrsCaptor.capture()); + Map, Object> capturedAttributes = attrsCaptor.getValue().asMap(); + assertThat(capturedAttributes) + .containsEntry( + AttributeKey.stringKey(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE), ErrorTypeUtil.ErrorType.CLIENT_REQUEST_ERROR.toString()); verify(span).end(); } @@ -511,8 +536,13 @@ void testAttemptFailed_clientUnknownError() { spanTracer.attemptFailedRetriesExhausted(new UnknownClientException()); - verify(span) - .setAttribute(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE, "UnknownClientException"); + ArgumentCaptor attrsCaptor = ArgumentCaptor.forClass(Attributes.class); + verify(span).setAllAttributes(attrsCaptor.capture()); + Map, Object> capturedAttributes = attrsCaptor.getValue().asMap(); + assertThat(capturedAttributes) + .containsEntry( + AttributeKey.stringKey(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE), + "UnknownClientException"); verify(span).end(); } @@ -522,8 +552,13 @@ void testAttemptFailed_languageSpecificFallback() { spanTracer.attemptFailedRetriesExhausted(new IllegalStateException("illegal state")); - verify(span) - .setAttribute(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE, "IllegalStateException"); + ArgumentCaptor attrsCaptor = ArgumentCaptor.forClass(Attributes.class); + verify(span).setAllAttributes(attrsCaptor.capture()); + Map, Object> capturedAttributes = attrsCaptor.getValue().asMap(); + assertThat(capturedAttributes) + .containsEntry( + AttributeKey.stringKey(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE), + "IllegalStateException"); verify(span).end(); } @@ -536,9 +571,12 @@ void testAttemptFailed_internalFallback() { // For an anonymous inner class Throwable, getSimpleName() is empty string, // which triggers the // fallback - verify(span) - .setAttribute( - ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE, + ArgumentCaptor attrsCaptor = ArgumentCaptor.forClass(Attributes.class); + verify(span).setAllAttributes(attrsCaptor.capture()); + Map, Object> capturedAttributes = attrsCaptor.getValue().asMap(); + assertThat(capturedAttributes) + .containsEntry( + AttributeKey.stringKey(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE), ErrorTypeUtil.ErrorType.INTERNAL.toString()); verify(span).end(); } @@ -552,8 +590,11 @@ void testAttemptFailed_internalFallback_nullError() { // For an anonymous inner class Throwable, getSimpleName() is empty string, // which triggers the // fallback - verify(span, never()) - .setAttribute(eq(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE), anyString()); + ArgumentCaptor attrsCaptor = ArgumentCaptor.forClass(Attributes.class); + verify(span).setAllAttributes(attrsCaptor.capture()); + Map, Object> capturedAttributes = attrsCaptor.getValue().asMap(); + assertThat(capturedAttributes) + .doesNotContainKey(AttributeKey.stringKey(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE)); verify(span).end(); } @@ -563,9 +604,13 @@ void testAttemptFailed_populatesExceptionTypeAndMessage() { spanTracer.attemptFailedRetriesExhausted(new IllegalStateException("custom error message")); - verify(span) - .setAttribute( - ObservabilityAttributes.EXCEPTION_TYPE_ATTRIBUTE, "java.lang.IllegalStateException"); + ArgumentCaptor attrsCaptor = ArgumentCaptor.forClass(Attributes.class); + verify(span).setAllAttributes(attrsCaptor.capture()); + Map, Object> capturedAttributes = attrsCaptor.getValue().asMap(); + assertThat(capturedAttributes) + .containsEntry( + AttributeKey.stringKey(ObservabilityAttributes.EXCEPTION_TYPE_ATTRIBUTE), + "java.lang.IllegalStateException"); verify(span) .setAttribute(ObservabilityAttributes.STATUS_MESSAGE_ATTRIBUTE, "custom error message"); verify(span).end(); @@ -618,7 +663,7 @@ void testInjectTraceContext_addsHeaders() { spanTracer = new SpanTracer(tracer, ApiTracerContext.empty(), ATTEMPT_SPAN_NAME); spanTracer.attemptStarted(new Object(), 1); - java.util.Map carrier = new java.util.HashMap<>(); + Map carrier = new java.util.HashMap<>(); spanTracer.injectTraceContext(carrier); assertThat(carrier).containsKey("traceparent"); diff --git a/sdk-platform-java/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITOtelTracing.java b/sdk-platform-java/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITOtelTracing.java index d5af2b99b7d9..fdce9cc7c452 100644 --- a/sdk-platform-java/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITOtelTracing.java +++ b/sdk-platform-java/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITOtelTracing.java @@ -184,7 +184,6 @@ void testTracing_successfulEcho_grpc() throws Exception { assertThat(attemptSpan.getAttributes().get(RPC_SYSTEM_KEY)).isEqualTo(VALUE_GRPC); assertThat(attemptSpan.getAttributes().get(RPC_RESPONSE_STATUS_KEY)).isEqualTo(VALUE_OK); assertThat(attemptSpan.getAttributes().get(REPO_KEY)).isEqualTo(SHOWCASE_REPO); - assertThat(attemptSpan.getAttributes().get(ARTIFACT_KEY)).isEqualTo(SHOWCASE_ARTIFACT); assertThat( attemptSpan @@ -255,7 +254,6 @@ void testTracing_successfulEcho_httpjson() throws Exception { assertThat(attemptSpan.getAttributes().get(RPC_SYSTEM_KEY)).isEqualTo(VALUE_HTTP); assertThat(attemptSpan.getAttributes().get(HTTP_RESPONSE_STATUS_KEY)).isEqualTo(200L); assertThat(attemptSpan.getAttributes().get(REPO_KEY)).isEqualTo(SHOWCASE_REPO); - assertThat(attemptSpan.getAttributes().get(ARTIFACT_KEY)).isEqualTo(SHOWCASE_ARTIFACT); assertThat( attemptSpan .getAttributes() From 04bcc1f241e83ec4b7c41f3e2a10480b669ead08 Mon Sep 17 00:00:00 2001 From: blakeli Date: Fri, 3 Apr 2026 18:00:33 -0400 Subject: [PATCH 2/6] fix: format --- .../tracing/GoldenSignalsMetricsTracer.java | 2 +- .../api/gax/tracing/ObservabilityUtils.java | 2 +- .../google/api/gax/tracing/SpanTracer.java | 2 +- .../gax/tracing/ObservabilityUtilsTest.java | 28 +++++++++---------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/GoldenSignalsMetricsTracer.java b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/GoldenSignalsMetricsTracer.java index a59c49126a37..2226007d5817 100644 --- a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/GoldenSignalsMetricsTracer.java +++ b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/GoldenSignalsMetricsTracer.java @@ -90,7 +90,7 @@ public void operationFailed(Throwable error) { private void recordError(Throwable error) { Map errorAttributes = - ObservabilityUtils.populateErrorAttributes(error, transport); + ObservabilityUtils.gettErrorAttributes(error, transport); attributes.putAll(errorAttributes); metricsRecorder.recordOperationLatency( clientRequestTimer.elapsed(TimeUnit.NANOSECONDS) / 1_000_000_000.0, attributes); diff --git a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/ObservabilityUtils.java b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/ObservabilityUtils.java index 3a5384740531..0806f1910b9d 100644 --- a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/ObservabilityUtils.java +++ b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/ObservabilityUtils.java @@ -171,7 +171,7 @@ private static String redactSensitiveQueryValues(final String rawQuery) { return Joiner.on('&').join(redactedParams); } - static Map populateErrorAttributes( + static Map gettErrorAttributes( @Nullable Throwable error, ApiTracerContext.Transport transport) { Map attributes = new HashMap<>(); StatusCode.Code code = extractStatus(error); diff --git a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/SpanTracer.java b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/SpanTracer.java index 4fb0a43b463b..75f4cc5ac841 100644 --- a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/SpanTracer.java +++ b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/SpanTracer.java @@ -218,7 +218,7 @@ private void recordErrorAndEndAttempt(Throwable error) { return; } Map errorAttributes = - ObservabilityUtils.populateErrorAttributes(error, this.apiTracerContext.transport()); + ObservabilityUtils.gettErrorAttributes(error, this.apiTracerContext.transport()); if (!errorAttributes.isEmpty()) { attemptSpan.setAllAttributes(ObservabilityUtils.toOtelAttributes(errorAttributes)); } diff --git a/sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/ObservabilityUtilsTest.java b/sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/ObservabilityUtilsTest.java index 644798f44a83..a649e04103a1 100644 --- a/sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/ObservabilityUtilsTest.java +++ b/sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/ObservabilityUtilsTest.java @@ -115,36 +115,36 @@ void testToOtelAttributes_shouldMapIntAttributes() { } @Test - void testPopulateErrorAttributes_grpc_success() { + void testGettErrorAttributes_grpc_success() { Map attributes = - ObservabilityUtils.populateErrorAttributes(null, ApiTracerContext.Transport.GRPC); + ObservabilityUtils.gettErrorAttributes(null, ApiTracerContext.Transport.GRPC); assertThat(attributes) .containsEntry(ObservabilityAttributes.RPC_RESPONSE_STATUS_ATTRIBUTE, "OK"); } @Test - void testPopulateErrorAttributes_grpc_apiException() { + void testGettErrorAttributes_grpc_apiException() { ApiException error = new ApiException("fake_error", null, new FakeStatusCode(StatusCode.Code.NOT_FOUND), false); Map attributes = - ObservabilityUtils.populateErrorAttributes(error, ApiTracerContext.Transport.GRPC); + ObservabilityUtils.gettErrorAttributes(error, ApiTracerContext.Transport.GRPC); assertThat(attributes) .containsEntry(ObservabilityAttributes.RPC_RESPONSE_STATUS_ATTRIBUTE, "NOT_FOUND"); } @Test - void testPopulateErrorAttributes_grpc_cancellationException() { + void testGettErrorAttributes_grpc_cancellationException() { Throwable error = new java.util.concurrent.CancellationException(); Map attributes = - ObservabilityUtils.populateErrorAttributes(error, ApiTracerContext.Transport.GRPC); + ObservabilityUtils.gettErrorAttributes(error, ApiTracerContext.Transport.GRPC); assertThat(attributes) .containsEntry(ObservabilityAttributes.RPC_RESPONSE_STATUS_ATTRIBUTE, "CANCELLED"); } @Test - void testPopulateErrorAttributes_http_success() { + void testGettErrorAttributes_http_success() { Map attributes = - ObservabilityUtils.populateErrorAttributes(null, ApiTracerContext.Transport.HTTP); + ObservabilityUtils.gettErrorAttributes(null, ApiTracerContext.Transport.HTTP); assertThat(attributes) .containsEntry( ObservabilityAttributes.HTTP_RESPONSE_STATUS_ATTRIBUTE, @@ -152,7 +152,7 @@ void testPopulateErrorAttributes_http_success() { } @Test - void testPopulateErrorAttributes_http_apiExceptionWithIntegerTransportCode() { + void testGettErrorAttributes_http_apiExceptionWithIntegerTransportCode() { ApiException error = new ApiException( "fake_error", @@ -170,7 +170,7 @@ public Object getTransportCode() { }, false); Map attributes = - ObservabilityUtils.populateErrorAttributes(error, ApiTracerContext.Transport.HTTP); + ObservabilityUtils.gettErrorAttributes(error, ApiTracerContext.Transport.HTTP); assertThat(attributes) .containsEntry( ObservabilityAttributes.HTTP_RESPONSE_STATUS_ATTRIBUTE, @@ -178,7 +178,7 @@ public Object getTransportCode() { } @Test - void testPopulateErrorAttributes_http_apiExceptionWithNonIntegerTransportCode() { + void testGettErrorAttributes_http_apiExceptionWithNonIntegerTransportCode() { ApiException error = new ApiException( "fake_error", @@ -196,7 +196,7 @@ public Object getTransportCode() { }, false); Map attributes = - ObservabilityUtils.populateErrorAttributes(error, ApiTracerContext.Transport.HTTP); + ObservabilityUtils.gettErrorAttributes(error, ApiTracerContext.Transport.HTTP); assertThat(attributes) .containsEntry( ObservabilityAttributes.HTTP_RESPONSE_STATUS_ATTRIBUTE, @@ -204,10 +204,10 @@ public Object getTransportCode() { } @Test - void testPopulateErrorAttributes_http_cancellationException() { + void testGettErrorAttributes_http_cancellationException() { Throwable error = new java.util.concurrent.CancellationException(); Map attributes = - ObservabilityUtils.populateErrorAttributes(error, ApiTracerContext.Transport.HTTP); + ObservabilityUtils.gettErrorAttributes(error, ApiTracerContext.Transport.HTTP); assertThat(attributes) .containsEntry( ObservabilityAttributes.HTTP_RESPONSE_STATUS_ATTRIBUTE, From a06287126ae63cf65d4d167596f133890bcb273f Mon Sep 17 00:00:00 2001 From: blakeli Date: Fri, 3 Apr 2026 18:03:53 -0400 Subject: [PATCH 3/6] fix: format --- .../com/google/api/gax/tracing/ObservabilityAttributes.java | 6 ------ .../java/com/google/showcase/v1beta1/it/ITOtelTracing.java | 2 -- 2 files changed, 8 deletions(-) diff --git a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/ObservabilityAttributes.java b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/ObservabilityAttributes.java index a6fcf4438955..dd963ad96640 100644 --- a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/ObservabilityAttributes.java +++ b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/ObservabilityAttributes.java @@ -50,12 +50,6 @@ public class ObservabilityAttributes { /** The repository of the client library (e.g., "googleapis/google-cloud-java"). */ public static final String REPO_ATTRIBUTE = "gcp.client.repo"; - /** The artifact name of the client library (e.g., "google-cloud-vision"). */ - public static final String ARTIFACT_ATTRIBUTE = "gcp.client.artifact"; - - /** The version of the client library (e.g., "1.2.3"). */ - public static final String VERSION_ATTRIBUTE = "gcp.client.version"; - /** The full RPC method name, including package, service, and method. */ public static final String GRPC_RPC_METHOD_ATTRIBUTE = "rpc.method"; diff --git a/sdk-platform-java/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITOtelTracing.java b/sdk-platform-java/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITOtelTracing.java index fdce9cc7c452..6242d21880d7 100644 --- a/sdk-platform-java/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITOtelTracing.java +++ b/sdk-platform-java/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITOtelTracing.java @@ -103,8 +103,6 @@ class ITOtelTracing { AttributeKey.longKey(ObservabilityAttributes.HTTP_RESPONSE_STATUS_ATTRIBUTE); private static final AttributeKey REPO_KEY = AttributeKey.stringKey(ObservabilityAttributes.REPO_ATTRIBUTE); - private static final AttributeKey ARTIFACT_KEY = - AttributeKey.stringKey(ObservabilityAttributes.ARTIFACT_ATTRIBUTE); private static final AttributeKey ERROR_TYPE_KEY = AttributeKey.stringKey(ObservabilityAttributes.ERROR_TYPE_ATTRIBUTE); private static final AttributeKey EXCEPTION_TYPE_KEY = From 944d05c0e447309eaa1d9433e5922eb6ca7ebd91 Mon Sep 17 00:00:00 2001 From: blakeli Date: Fri, 3 Apr 2026 18:18:55 -0400 Subject: [PATCH 4/6] fix: fix typo --- .../tracing/GoldenSignalsMetricsTracer.java | 2 +- .../api/gax/tracing/ObservabilityUtils.java | 2 +- .../google/api/gax/tracing/SpanTracer.java | 2 +- .../gax/tracing/ObservabilityUtilsTest.java | 28 +++++++++---------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/GoldenSignalsMetricsTracer.java b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/GoldenSignalsMetricsTracer.java index 2226007d5817..826ff04bef98 100644 --- a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/GoldenSignalsMetricsTracer.java +++ b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/GoldenSignalsMetricsTracer.java @@ -90,7 +90,7 @@ public void operationFailed(Throwable error) { private void recordError(Throwable error) { Map errorAttributes = - ObservabilityUtils.gettErrorAttributes(error, transport); + ObservabilityUtils.getErrorAttributes(error, transport); attributes.putAll(errorAttributes); metricsRecorder.recordOperationLatency( clientRequestTimer.elapsed(TimeUnit.NANOSECONDS) / 1_000_000_000.0, attributes); diff --git a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/ObservabilityUtils.java b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/ObservabilityUtils.java index 0806f1910b9d..8edbd7ce6899 100644 --- a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/ObservabilityUtils.java +++ b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/ObservabilityUtils.java @@ -171,7 +171,7 @@ private static String redactSensitiveQueryValues(final String rawQuery) { return Joiner.on('&').join(redactedParams); } - static Map gettErrorAttributes( + static Map getErrorAttributes( @Nullable Throwable error, ApiTracerContext.Transport transport) { Map attributes = new HashMap<>(); StatusCode.Code code = extractStatus(error); diff --git a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/SpanTracer.java b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/SpanTracer.java index 75f4cc5ac841..a0359492d5ef 100644 --- a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/SpanTracer.java +++ b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/SpanTracer.java @@ -218,7 +218,7 @@ private void recordErrorAndEndAttempt(Throwable error) { return; } Map errorAttributes = - ObservabilityUtils.gettErrorAttributes(error, this.apiTracerContext.transport()); + ObservabilityUtils.getErrorAttributes(error, this.apiTracerContext.transport()); if (!errorAttributes.isEmpty()) { attemptSpan.setAllAttributes(ObservabilityUtils.toOtelAttributes(errorAttributes)); } diff --git a/sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/ObservabilityUtilsTest.java b/sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/ObservabilityUtilsTest.java index a649e04103a1..f422b8520000 100644 --- a/sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/ObservabilityUtilsTest.java +++ b/sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/ObservabilityUtilsTest.java @@ -115,36 +115,36 @@ void testToOtelAttributes_shouldMapIntAttributes() { } @Test - void testGettErrorAttributes_grpc_success() { + void testGetErrorAttributes_grpc_success() { Map attributes = - ObservabilityUtils.gettErrorAttributes(null, ApiTracerContext.Transport.GRPC); + ObservabilityUtils.getErrorAttributes(null, ApiTracerContext.Transport.GRPC); assertThat(attributes) .containsEntry(ObservabilityAttributes.RPC_RESPONSE_STATUS_ATTRIBUTE, "OK"); } @Test - void testGettErrorAttributes_grpc_apiException() { + void testGetErrorAttributes_grpc_apiException() { ApiException error = new ApiException("fake_error", null, new FakeStatusCode(StatusCode.Code.NOT_FOUND), false); Map attributes = - ObservabilityUtils.gettErrorAttributes(error, ApiTracerContext.Transport.GRPC); + ObservabilityUtils.getErrorAttributes(error, ApiTracerContext.Transport.GRPC); assertThat(attributes) .containsEntry(ObservabilityAttributes.RPC_RESPONSE_STATUS_ATTRIBUTE, "NOT_FOUND"); } @Test - void testGettErrorAttributes_grpc_cancellationException() { + void testGetErrorAttributes_grpc_cancellationException() { Throwable error = new java.util.concurrent.CancellationException(); Map attributes = - ObservabilityUtils.gettErrorAttributes(error, ApiTracerContext.Transport.GRPC); + ObservabilityUtils.getErrorAttributes(error, ApiTracerContext.Transport.GRPC); assertThat(attributes) .containsEntry(ObservabilityAttributes.RPC_RESPONSE_STATUS_ATTRIBUTE, "CANCELLED"); } @Test - void testGettErrorAttributes_http_success() { + void testGetErrorAttributes_http_success() { Map attributes = - ObservabilityUtils.gettErrorAttributes(null, ApiTracerContext.Transport.HTTP); + ObservabilityUtils.getErrorAttributes(null, ApiTracerContext.Transport.HTTP); assertThat(attributes) .containsEntry( ObservabilityAttributes.HTTP_RESPONSE_STATUS_ATTRIBUTE, @@ -152,7 +152,7 @@ void testGettErrorAttributes_http_success() { } @Test - void testGettErrorAttributes_http_apiExceptionWithIntegerTransportCode() { + void testGetErrorAttributes_http_apiExceptionWithIntegerTransportCode() { ApiException error = new ApiException( "fake_error", @@ -170,7 +170,7 @@ public Object getTransportCode() { }, false); Map attributes = - ObservabilityUtils.gettErrorAttributes(error, ApiTracerContext.Transport.HTTP); + ObservabilityUtils.getErrorAttributes(error, ApiTracerContext.Transport.HTTP); assertThat(attributes) .containsEntry( ObservabilityAttributes.HTTP_RESPONSE_STATUS_ATTRIBUTE, @@ -178,7 +178,7 @@ public Object getTransportCode() { } @Test - void testGettErrorAttributes_http_apiExceptionWithNonIntegerTransportCode() { + void testGetErrorAttributes_http_apiExceptionWithNonIntegerTransportCode() { ApiException error = new ApiException( "fake_error", @@ -196,7 +196,7 @@ public Object getTransportCode() { }, false); Map attributes = - ObservabilityUtils.gettErrorAttributes(error, ApiTracerContext.Transport.HTTP); + ObservabilityUtils.getErrorAttributes(error, ApiTracerContext.Transport.HTTP); assertThat(attributes) .containsEntry( ObservabilityAttributes.HTTP_RESPONSE_STATUS_ATTRIBUTE, @@ -204,10 +204,10 @@ public Object getTransportCode() { } @Test - void testGettErrorAttributes_http_cancellationException() { + void testGetErrorAttributes_http_cancellationException() { Throwable error = new java.util.concurrent.CancellationException(); Map attributes = - ObservabilityUtils.gettErrorAttributes(error, ApiTracerContext.Transport.HTTP); + ObservabilityUtils.getErrorAttributes(error, ApiTracerContext.Transport.HTTP); assertThat(attributes) .containsEntry( ObservabilityAttributes.HTTP_RESPONSE_STATUS_ATTRIBUTE, From f33bbdd7a32bca28995db172b741fe159627d203 Mon Sep 17 00:00:00 2001 From: blakeli Date: Sat, 4 Apr 2026 00:03:02 -0400 Subject: [PATCH 5/6] fix: rename --- .../tracing/GoldenSignalsMetricsTracer.java | 10 +++---- .../api/gax/tracing/ObservabilityUtils.java | 2 +- .../google/api/gax/tracing/SpanTracer.java | 2 +- .../gax/tracing/ObservabilityUtilsTest.java | 28 +++++++++---------- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/GoldenSignalsMetricsTracer.java b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/GoldenSignalsMetricsTracer.java index 826ff04bef98..4d174c44f1b0 100644 --- a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/GoldenSignalsMetricsTracer.java +++ b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/GoldenSignalsMetricsTracer.java @@ -75,22 +75,22 @@ class GoldenSignalsMetricsTracer implements ApiTracer { */ @Override public void operationSucceeded() { - recordError(null); + recordMetric(null); } @Override public void operationCancelled() { - recordError(new CancellationException()); + recordMetric(new CancellationException()); } @Override public void operationFailed(Throwable error) { - recordError(error); + recordMetric(error); } - private void recordError(Throwable error) { + private void recordMetric(Throwable error) { Map errorAttributes = - ObservabilityUtils.getErrorAttributes(error, transport); + ObservabilityUtils.getResponseAttributes(error, transport); attributes.putAll(errorAttributes); metricsRecorder.recordOperationLatency( clientRequestTimer.elapsed(TimeUnit.NANOSECONDS) / 1_000_000_000.0, attributes); diff --git a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/ObservabilityUtils.java b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/ObservabilityUtils.java index 8edbd7ce6899..bd44e1f0a362 100644 --- a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/ObservabilityUtils.java +++ b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/ObservabilityUtils.java @@ -171,7 +171,7 @@ private static String redactSensitiveQueryValues(final String rawQuery) { return Joiner.on('&').join(redactedParams); } - static Map getErrorAttributes( + static Map getResponseAttributes( @Nullable Throwable error, ApiTracerContext.Transport transport) { Map attributes = new HashMap<>(); StatusCode.Code code = extractStatus(error); diff --git a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/SpanTracer.java b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/SpanTracer.java index a0359492d5ef..078a703a7681 100644 --- a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/SpanTracer.java +++ b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/SpanTracer.java @@ -218,7 +218,7 @@ private void recordErrorAndEndAttempt(Throwable error) { return; } Map errorAttributes = - ObservabilityUtils.getErrorAttributes(error, this.apiTracerContext.transport()); + ObservabilityUtils.getResponseAttributes(error, this.apiTracerContext.transport()); if (!errorAttributes.isEmpty()) { attemptSpan.setAllAttributes(ObservabilityUtils.toOtelAttributes(errorAttributes)); } diff --git a/sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/ObservabilityUtilsTest.java b/sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/ObservabilityUtilsTest.java index f422b8520000..d0da067067d6 100644 --- a/sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/ObservabilityUtilsTest.java +++ b/sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/ObservabilityUtilsTest.java @@ -115,36 +115,36 @@ void testToOtelAttributes_shouldMapIntAttributes() { } @Test - void testGetErrorAttributes_grpc_success() { + void testGetResponseAttributes_grpc_success() { Map attributes = - ObservabilityUtils.getErrorAttributes(null, ApiTracerContext.Transport.GRPC); + ObservabilityUtils.getResponseAttributes(null, ApiTracerContext.Transport.GRPC); assertThat(attributes) .containsEntry(ObservabilityAttributes.RPC_RESPONSE_STATUS_ATTRIBUTE, "OK"); } @Test - void testGetErrorAttributes_grpc_apiException() { + void testGetResponseAttributes_grpc_apiException() { ApiException error = new ApiException("fake_error", null, new FakeStatusCode(StatusCode.Code.NOT_FOUND), false); Map attributes = - ObservabilityUtils.getErrorAttributes(error, ApiTracerContext.Transport.GRPC); + ObservabilityUtils.getResponseAttributes(error, ApiTracerContext.Transport.GRPC); assertThat(attributes) .containsEntry(ObservabilityAttributes.RPC_RESPONSE_STATUS_ATTRIBUTE, "NOT_FOUND"); } @Test - void testGetErrorAttributes_grpc_cancellationException() { + void testGetResponseAttributes_grpc_cancellationException() { Throwable error = new java.util.concurrent.CancellationException(); Map attributes = - ObservabilityUtils.getErrorAttributes(error, ApiTracerContext.Transport.GRPC); + ObservabilityUtils.getResponseAttributes(error, ApiTracerContext.Transport.GRPC); assertThat(attributes) .containsEntry(ObservabilityAttributes.RPC_RESPONSE_STATUS_ATTRIBUTE, "CANCELLED"); } @Test - void testGetErrorAttributes_http_success() { + void testGetResponseAttributes_http_success() { Map attributes = - ObservabilityUtils.getErrorAttributes(null, ApiTracerContext.Transport.HTTP); + ObservabilityUtils.getResponseAttributes(null, ApiTracerContext.Transport.HTTP); assertThat(attributes) .containsEntry( ObservabilityAttributes.HTTP_RESPONSE_STATUS_ATTRIBUTE, @@ -152,7 +152,7 @@ void testGetErrorAttributes_http_success() { } @Test - void testGetErrorAttributes_http_apiExceptionWithIntegerTransportCode() { + void testGetResponseAttributes_http_apiExceptionWithIntegerTransportCode() { ApiException error = new ApiException( "fake_error", @@ -170,7 +170,7 @@ public Object getTransportCode() { }, false); Map attributes = - ObservabilityUtils.getErrorAttributes(error, ApiTracerContext.Transport.HTTP); + ObservabilityUtils.getResponseAttributes(error, ApiTracerContext.Transport.HTTP); assertThat(attributes) .containsEntry( ObservabilityAttributes.HTTP_RESPONSE_STATUS_ATTRIBUTE, @@ -178,7 +178,7 @@ public Object getTransportCode() { } @Test - void testGetErrorAttributes_http_apiExceptionWithNonIntegerTransportCode() { + void testGetResponseAttributes_http_apiExceptionWithNonIntegerTransportCode() { ApiException error = new ApiException( "fake_error", @@ -196,7 +196,7 @@ public Object getTransportCode() { }, false); Map attributes = - ObservabilityUtils.getErrorAttributes(error, ApiTracerContext.Transport.HTTP); + ObservabilityUtils.getResponseAttributes(error, ApiTracerContext.Transport.HTTP); assertThat(attributes) .containsEntry( ObservabilityAttributes.HTTP_RESPONSE_STATUS_ATTRIBUTE, @@ -204,10 +204,10 @@ public Object getTransportCode() { } @Test - void testGetErrorAttributes_http_cancellationException() { + void testGetResponseAttributes_http_cancellationException() { Throwable error = new java.util.concurrent.CancellationException(); Map attributes = - ObservabilityUtils.getErrorAttributes(error, ApiTracerContext.Transport.HTTP); + ObservabilityUtils.getResponseAttributes(error, ApiTracerContext.Transport.HTTP); assertThat(attributes) .containsEntry( ObservabilityAttributes.HTTP_RESPONSE_STATUS_ATTRIBUTE, From 7d35ea99149865928d758ad35d8b657fcd76053a Mon Sep 17 00:00:00 2001 From: blakeli Date: Sat, 4 Apr 2026 00:04:10 -0400 Subject: [PATCH 6/6] fix: rename --- .../google/api/gax/tracing/GoldenSignalsMetricsTracer.java | 4 ++-- .../main/java/com/google/api/gax/tracing/SpanTracer.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/GoldenSignalsMetricsTracer.java b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/GoldenSignalsMetricsTracer.java index 4d174c44f1b0..a4376e8c6c26 100644 --- a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/GoldenSignalsMetricsTracer.java +++ b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/GoldenSignalsMetricsTracer.java @@ -89,9 +89,9 @@ public void operationFailed(Throwable error) { } private void recordMetric(Throwable error) { - Map errorAttributes = + Map responseAttributes = ObservabilityUtils.getResponseAttributes(error, transport); - attributes.putAll(errorAttributes); + attributes.putAll(responseAttributes); metricsRecorder.recordOperationLatency( clientRequestTimer.elapsed(TimeUnit.NANOSECONDS) / 1_000_000_000.0, attributes); } diff --git a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/SpanTracer.java b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/SpanTracer.java index 078a703a7681..81d2d1c9a033 100644 --- a/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/SpanTracer.java +++ b/sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/SpanTracer.java @@ -217,10 +217,10 @@ private void recordErrorAndEndAttempt(Throwable error) { if (attemptSpan == null) { return; } - Map errorAttributes = + Map responseAttributes = ObservabilityUtils.getResponseAttributes(error, this.apiTracerContext.transport()); - if (!errorAttributes.isEmpty()) { - attemptSpan.setAllAttributes(ObservabilityUtils.toOtelAttributes(errorAttributes)); + if (!responseAttributes.isEmpty()) { + attemptSpan.setAllAttributes(ObservabilityUtils.toOtelAttributes(responseAttributes)); } if (error != null && !Strings.isNullOrEmpty(error.getMessage())) {