gabriel-farache commented on code in PR #4094:
URL: 
https://github.com/apache/incubator-kie-kogito-runtimes/pull/4094#discussion_r2585943656


##########
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();
+            }
         };
     }
 
     /**
      * Callback method called when tokens are evicted from the cache.
-     * 
+     * Context is already set by the removal listener, so no need to set it 
here.
+     *
      * @param cacheKey The cache key of the evicted tokens
      * @param tokens The evicted token data
      * @param cause The reason for eviction (Caffeine's RemovalCause)
      */
     private void onTokenExpired(String cacheKey, CachedTokens tokens, 
RemovalCause cause) {
         LOGGER.warn("OAuth2 tokens for cache key '{}' have expired/been 
evicted: {}", cacheKey, cause);
 
+        String processInstanceId = 
CacheUtils.extractProcessInstanceIdFromCacheKey(cacheKey);

Review Comment:
   You are right, this is likely a leftover when refactoring :)



-- 
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]

Reply via email to