Skip to content

Commit

Permalink
fix: bug of ex-client-trace-id not cleared in the end
Browse files Browse the repository at this point in the history
Signed-off-by: Zvi Grinberg <[email protected]>
  • Loading branch information
zvigrinberg committed Aug 13, 2024
1 parent 0987947 commit 17389aa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
Empty file added sbom.json
Empty file.
3 changes: 2 additions & 1 deletion src/main/java/com/redhat/exhort/impl/ExhortApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,10 @@ static HttpClient.Version getHttpVersion() {

private String commonHookBeginning(boolean startOfApi) {
if (startOfApi) {
generateClientRequestId();
// generateClientRequestId();
if (debugLoggingIsNeeded()) {
LOG.info("Start of exhort-java-api client");
LOG.info(String.format("Starting time of API: %s", LocalDateTime.now()));
}
} else {
if (Objects.isNull(getClientRequestId())) {
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/com/redhat/exhort/impl/RequestManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

public class RequestManager {

Expand All @@ -40,7 +41,18 @@ public synchronized void addClientTraceIdToRequest(String requestId) {
}

public synchronized void removeClientTraceIdFromRequest() {
requests.remove(concatenatedThreadId());
String removedClientTraceId = requests.remove(concatenatedThreadId());
// remove the traceId If it was propagated from parent Thread.
if (removedClientTraceId != null) {
Optional<String> keyOfParent =
requests.entrySet().stream()
.filter(pair -> pair.getValue().equals(removedClientTraceId))
.map(pair -> pair.getKey())
.findFirst();
if (keyOfParent.isPresent()) {
requests.remove(keyOfParent.get());
}
}
}

public String getTraceIdOfRequest() {
Expand Down

0 comments on commit 17389aa

Please sign in to comment.