adutra commented on code in PR #2720:
URL: https://github.com/apache/polaris/pull/2720#discussion_r2398053623


##########
runtime/service/src/main/java/org/apache/polaris/service/tracing/RequestIdFilter.java:
##########
@@ -18,33 +18,62 @@
  */
 package org.apache.polaris.service.tracing;
 
-import jakarta.annotation.Priority;
-import jakarta.enterprise.context.ApplicationScoped;
+import io.smallrye.common.vertx.ContextLocals;
+import io.smallrye.mutiny.Uni;
 import jakarta.inject.Inject;
 import jakarta.ws.rs.container.ContainerRequestContext;
-import jakarta.ws.rs.container.ContainerRequestFilter;
-import jakarta.ws.rs.container.PreMatching;
-import jakarta.ws.rs.ext.Provider;
+import jakarta.ws.rs.container.ContainerResponseContext;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
+import org.apache.iceberg.rest.responses.ErrorResponse;
 import org.apache.polaris.service.config.FilterPriorities;
 import org.apache.polaris.service.logging.LoggingConfiguration;
+import org.jboss.resteasy.reactive.server.ServerRequestFilter;
+import org.jboss.resteasy.reactive.server.ServerResponseFilter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-@PreMatching
-@ApplicationScoped
-@Priority(FilterPriorities.REQUEST_ID_FILTER)
-@Provider
-public class RequestIdFilter implements ContainerRequestFilter {
+public class RequestIdFilter {
 
   public static final String REQUEST_ID_KEY = "requestId";
 
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(RequestIdFilter.class);
+
   @Inject LoggingConfiguration loggingConfiguration;
   @Inject RequestIdGenerator requestIdGenerator;
 
-  @Override
-  public void filter(ContainerRequestContext rc) {
+  @ServerRequestFilter(preMatching = true, priority = 
FilterPriorities.REQUEST_ID_FILTER)
+  public Uni<Response> assignRequestId(ContainerRequestContext rc) {
     var requestId = 
rc.getHeaderString(loggingConfiguration.requestIdHeaderName());
-    if (requestId == null) {
-      requestId = requestIdGenerator.generateRequestId();
+    return (requestId != null
+            ? Uni.createFrom().item(requestId)
+            : requestIdGenerator.generateRequestId(rc))
+        .onItem()
+        .invoke(id -> rc.setProperty(REQUEST_ID_KEY, id))
+        .invoke(id -> ContextLocals.put(REQUEST_ID_KEY, id))

Review Comment:
   > How would you compare both approaches?
   
   Indeed, a request-scoped bean is undoubtedly better.
   
   > So while I see that we are putting the information in RealmContextFilter, 
what is our (proposed?) use of this?
   
   This was done a while ago, as I thought at that time that we would be 
leveraging context propagation to "transfer" some information from the initial 
request scope to, say, the async tasks framework.
   
   It seems though that, since that time, we've been taking the opposite 
direction: that of _avoiding_ context propagation (due to some issues with bean 
proxies, etc.)
   
   The situation today is that those calls to `ContextLocals` are probably not 
necessary anymore. They can be removed.
   
   Are we OK if I remove the call to `ContextLocals` in `RequestIdFilter` in 
this PR, then remove the other call in `RealmContextFilter` in a different PR?



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

Reply via email to