Skip to content

Commit

Permalink
QosException reasons are included in SafeLoggable args (#930)
Browse files Browse the repository at this point in the history
QosException reasons are included in SafeLoggable args for better observability when exceptions are wrapped and logged.
  • Loading branch information
carterkozak committed Dec 14, 2022
1 parent 9ba9250 commit cb06ccc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions changelog/@unreleased/pr-930.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: improvement
improvement:
description: QosException reasons are included in SafeLoggable args for better observability
when exceptions are wrapped and logged.
links:
- https://github.com/palantir/conjure-java-runtime-api/pull/930
1 change: 1 addition & 0 deletions errors/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies {
implementation "com.palantir.safe-logging:preconditions"

testImplementation project(":extras:jackson-support")
testImplementation "com.palantir.safe-logging:preconditions-assertj"
testImplementation "org.assertj:assertj-core"
testImplementation "org.apache.commons:commons-lang3"
testImplementation 'org.junit.jupiter:junit-jupiter'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public String getLogMessage() {

@Override
public List<Arg<?>> getArgs() {
return Collections.singletonList(SafeArg.of("retryAfter", retryAfter.orElse(null)));
return List.of(SafeArg.of("retryAfter", retryAfter.orElse(null)), SafeArg.of("reason", getReason()));
}
}

Expand Down Expand Up @@ -269,7 +269,7 @@ public String getLogMessage() {

@Override
public List<Arg<?>> getArgs() {
return Collections.singletonList(UnsafeArg.of("redirectTo", redirectTo));
return List.of(UnsafeArg.of("redirectTo", redirectTo), SafeArg.of("reason", getReason()));
}
}

Expand Down Expand Up @@ -307,7 +307,7 @@ public String getLogMessage() {

@Override
public List<Arg<?>> getArgs() {
return Collections.emptyList();
return Collections.singletonList(SafeArg.of("reason", getReason()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

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

import static com.palantir.logsafe.testing.Assertions.assertThatLoggableExceptionThrownBy;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.palantir.logsafe.SafeArg;
import com.palantir.logsafe.exceptions.SafeIllegalArgumentException;
import java.net.MalformedURLException;
import java.net.URL;
Expand Down Expand Up @@ -53,8 +55,12 @@ public Class visit(QosException.Unavailable exception) {

@Test
public void testReason() {
QosReason reason = QosReason.of("reason");
QosReason reason = QosReason.of("custom-reason");
assertThat(QosException.throttle(reason).getReason()).isEqualTo(reason);
assertThatLoggableExceptionThrownBy(() -> {
throw QosException.throttle(reason);
})
.containsArgs(SafeArg.of("reason", reason));
}

@Test
Expand Down

0 comments on commit cb06ccc

Please sign in to comment.