Skip to content

Commit cb06ccc

Browse files
author
Carter Kozak
authored
QosException reasons are included in SafeLoggable args (#930)
QosException reasons are included in SafeLoggable args for better observability when exceptions are wrapped and logged.
1 parent 9ba9250 commit cb06ccc

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
type: improvement
2+
improvement:
3+
description: QosException reasons are included in SafeLoggable args for better observability
4+
when exceptions are wrapped and logged.
5+
links:
6+
- https://github.com/palantir/conjure-java-runtime-api/pull/930

errors/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ dependencies {
1010
implementation "com.palantir.safe-logging:preconditions"
1111

1212
testImplementation project(":extras:jackson-support")
13+
testImplementation "com.palantir.safe-logging:preconditions-assertj"
1314
testImplementation "org.assertj:assertj-core"
1415
testImplementation "org.apache.commons:commons-lang3"
1516
testImplementation 'org.junit.jupiter:junit-jupiter'

errors/src/main/java/com/palantir/conjure/java/api/errors/QosException.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public String getLogMessage() {
222222

223223
@Override
224224
public List<Arg<?>> getArgs() {
225-
return Collections.singletonList(SafeArg.of("retryAfter", retryAfter.orElse(null)));
225+
return List.of(SafeArg.of("retryAfter", retryAfter.orElse(null)), SafeArg.of("reason", getReason()));
226226
}
227227
}
228228

@@ -269,7 +269,7 @@ public String getLogMessage() {
269269

270270
@Override
271271
public List<Arg<?>> getArgs() {
272-
return Collections.singletonList(UnsafeArg.of("redirectTo", redirectTo));
272+
return List.of(UnsafeArg.of("redirectTo", redirectTo), SafeArg.of("reason", getReason()));
273273
}
274274
}
275275

@@ -307,7 +307,7 @@ public String getLogMessage() {
307307

308308
@Override
309309
public List<Arg<?>> getArgs() {
310-
return Collections.emptyList();
310+
return Collections.singletonList(SafeArg.of("reason", getReason()));
311311
}
312312
}
313313
}

errors/src/test/java/com/palantir/conjure/java/api/errors/QosExceptionTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@
1616

1717
package com.palantir.conjure.java.api.errors;
1818

19+
import static com.palantir.logsafe.testing.Assertions.assertThatLoggableExceptionThrownBy;
1920
import static org.assertj.core.api.Assertions.assertThat;
2021
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2122

23+
import com.palantir.logsafe.SafeArg;
2224
import com.palantir.logsafe.exceptions.SafeIllegalArgumentException;
2325
import java.net.MalformedURLException;
2426
import java.net.URL;
@@ -53,8 +55,12 @@ public Class visit(QosException.Unavailable exception) {
5355

5456
@Test
5557
public void testReason() {
56-
QosReason reason = QosReason.of("reason");
58+
QosReason reason = QosReason.of("custom-reason");
5759
assertThat(QosException.throttle(reason).getReason()).isEqualTo(reason);
60+
assertThatLoggableExceptionThrownBy(() -> {
61+
throw QosException.throttle(reason);
62+
})
63+
.containsArgs(SafeArg.of("reason", reason));
5864
}
5965

6066
@Test

0 commit comments

Comments
 (0)