Skip to content

Commit 31f8c9a

Browse files
committed
feat: Use EXCEPTION_MESSAGE_ATTRIBUTE and clean up LoggingTracer
1 parent 7ef71c2 commit 31f8c9a

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/LoggingTracer.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.google.api.gax.logging.LoggerProvider;
3636
import com.google.api.gax.logging.LoggingUtils;
3737
import com.google.common.annotations.VisibleForTesting;
38+
import com.google.common.base.Strings;
3839
import com.google.rpc.ErrorInfo;
3940
import java.util.HashMap;
4041
import java.util.Map;
@@ -80,13 +81,13 @@ void recordActionableError(Throwable error) {
8081
logContext.putAll(
8182
ObservabilityUtils.getResponseAttributes(error, apiTracerContext.transport()));
8283

83-
if (error != null && error.getMessage() != null) {
84-
logContext.put("exception.message", error.getMessage());
84+
if (!Strings.isNullOrEmpty(error.getMessage())) {
85+
logContext.put(ObservabilityAttributes.EXCEPTION_MESSAGE_ATTRIBUTE, error.getMessage());
8586
}
8687

8788
ErrorInfo errorInfo = ObservabilityUtils.extractErrorInfo(error);
8889
if (errorInfo != null) {
89-
if (errorInfo.getDomain() != null && !errorInfo.getDomain().isEmpty()) {
90+
if (!Strings.isNullOrEmpty(errorInfo.getDomain())) {
9091
logContext.put(ObservabilityAttributes.ERROR_DOMAIN_ATTRIBUTE, errorInfo.getDomain());
9192
}
9293
if (errorInfo.getMetadataMap() != null) {

sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/tracing/ObservabilityAttributes.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ public class ObservabilityAttributes {
8585
/** If the error was caused by an exception, the exception class name. */
8686
public static final String EXCEPTION_TYPE_ATTRIBUTE = "exception.type";
8787

88+
/** If the error was caused by an exception, the exception message. */
89+
public static final String EXCEPTION_MESSAGE_ATTRIBUTE = "exception.message";
90+
8891
/** Size of the response body in bytes. */
8992
public static final String HTTP_RESPONSE_BODY_SIZE = "http.response.body.size";
9093

sdk-platform-java/gax-java/gax/src/test/java/com/google/api/gax/tracing/LoggingTracerTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ void testRecordActionableError_logsExceptionDetails() {
196196
assertEquals(
197197
"java.lang.RuntimeException",
198198
attributesMap.get(ObservabilityAttributes.EXCEPTION_TYPE_ATTRIBUTE));
199-
assertEquals("test error message", attributesMap.get("exception.message"));
199+
assertEquals(
200+
"test error message",
201+
attributesMap.get(ObservabilityAttributes.EXCEPTION_MESSAGE_ATTRIBUTE));
200202
}
201203

202204
@Test

0 commit comments

Comments
 (0)