Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bug of ex-client-trace-id not cleared in the end #109

Merged
merged 1 commit into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading