File tree Expand file tree Collapse file tree 3 files changed +10
-4
lines changed
sdk-platform-java/gax-java/gax/src
main/java/com/google/api/gax/tracing
test/java/com/google/api/gax/tracing Expand file tree Collapse file tree 3 files changed +10
-4
lines changed Original file line number Diff line number Diff line change 3535import com .google .api .gax .logging .LoggerProvider ;
3636import com .google .api .gax .logging .LoggingUtils ;
3737import com .google .common .annotations .VisibleForTesting ;
38+ import com .google .common .base .Strings ;
3839import com .google .rpc .ErrorInfo ;
3940import java .util .HashMap ;
4041import 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 ) {
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments