Skip to content

Commit 1610b38

Browse files
committed
fix: remove recursive error logic in SpanTracer
1 parent d7a8fef commit 1610b38

2 files changed

Lines changed: 4 additions & 24 deletions

File tree

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
package com.google.api.gax.tracing;
3232

33+
import com.google.api.client.util.Strings;
3334
import com.google.api.core.BetaApi;
3435
import com.google.api.core.InternalApi;
3536
import io.opentelemetry.api.trace.Span;
@@ -218,14 +219,10 @@ private void recordErrorAndEndAttempt(Throwable error) {
218219
}
219220

220221
private String extractErrorMessage(Throwable error) {
221-
Throwable cause = error;
222-
while (cause != null) {
223-
if (cause.getMessage() != null && !cause.getMessage().isEmpty()) {
224-
return cause.getMessage();
225-
}
226-
cause = cause.getCause();
222+
if (Strings.isNullOrEmpty(error.getMessage())) {
223+
return null;
227224
}
228-
return null;
225+
return error.getMessage();
229226
}
230227

231228
private void endAttempt() {

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -456,23 +456,6 @@ void testAttemptFailed_populatesExceptionTypeAndMessage() {
456456
verify(span).end();
457457
}
458458

459-
@Test
460-
void testAttemptFailed_recursiveMessageSearch() {
461-
spanTracer.attemptStarted(new Object(), 1);
462-
463-
Throwable cause = new IllegalArgumentException("root cause message");
464-
Throwable wrapper = new IllegalStateException("", cause);
465-
466-
spanTracer.attemptFailedRetriesExhausted(wrapper);
467-
468-
verify(span)
469-
.setAttribute(
470-
ObservabilityAttributes.EXCEPTION_TYPE_ATTRIBUTE, "java.lang.IllegalStateException");
471-
verify(span)
472-
.setAttribute(ObservabilityAttributes.STATUS_MESSAGE_ATTRIBUTE, "root cause message");
473-
verify(span).end();
474-
}
475-
476459
private static class RedirectException extends RuntimeException {
477460
public RedirectException(String message) {
478461
super(message);

0 commit comments

Comments
 (0)