gabriel-farache commented on code in PR #4094:
URL:
https://github.com/apache/incubator-kie-kogito-runtimes/pull/4094#discussion_r2585914966
##########
quarkus/addons/token-exchange/runtime/src/main/java/org/kie/kogito/addons/quarkus/token/exchange/cache/TokenEvictionHandler.java:
##########
@@ -54,29 +56,47 @@ public TokenEvictionHandler(TokenCRUD tokenCRUD) {
/**
* Creates a removal listener that can be used with Caffeine cache.
- *
+ * This listener sets the proper process instance context from the cache
key before logging.
+ *
* @return A removal listener that handles token eviction events
*/
public RemovalListener<String, CachedTokens> createRemovalListener() {
return (key, value, cause) -> {
if (value == null)
return;
- LOGGER.info("Token cache eviction for cache key '{}' - Cause: {}",
key, cause);
- onTokenExpired(key, value, cause);
+ // Extract process instance ID from cache key and set context for
logging
+ String processInstanceId =
CacheUtils.extractProcessInstanceIdFromCacheKey(key);
+ if (processInstanceId != null && !processInstanceId.isEmpty()) {
+ ProcessInstanceContext.setProcessInstanceId(processInstanceId);
+ }
+
+ try {
+ LOGGER.info("Token cache eviction for cache key '{}' - Cause:
{}", key, cause);
+ onTokenExpired(key, value, cause);
+ } finally {
+ // Reset to general context after logging
+ ProcessInstanceContext.clear();
Review Comment:
You are right, the check here is not strictly needed as the
`setProcessInstanceId` method check for it as well and act upon it. I will
remove the condition.
But the `clear` call is needed because the TokenEvictionHandler is run in
the background so it needs to clear the processInstanceID when exiting to avoid
having the wrong ID in the next logs
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]