dimas-b commented on code in PR #2914:
URL: https://github.com/apache/polaris/pull/2914#discussion_r2467344847


##########
runtime/service/src/main/java/org/apache/polaris/service/tracing/RequestIdFilter.java:
##########
@@ -18,60 +18,38 @@
  */
 package org.apache.polaris.service.tracing;
 
-import io.smallrye.mutiny.Uni;
 import jakarta.inject.Inject;
 import jakarta.ws.rs.container.ContainerRequestContext;
 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;
 
+/**
+ * Filter that handles request IDs for tracing.
+ *
+ * <p>See <a
+ * 
href="https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/observability/tracing";>Envoy
+ * Tracing</a>
+ */
 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;
+  @Inject TracingConfiguration tracingConfiguration;
 
   @ServerRequestFilter(preMatching = true, priority = 
FilterPriorities.REQUEST_ID_FILTER)
-  public Uni<Response> assignRequestId(ContainerRequestContext rc) {
-    var requestId = 
rc.getHeaderString(loggingConfiguration.requestIdHeaderName());
-    return (requestId != null
-            ? Uni.createFrom().item(requestId)
-            : requestIdGenerator.generateRequestId(rc))
-        .onItem()
-        .invoke(id -> rc.setProperty(REQUEST_ID_KEY, id))
-        .onItemOrFailure()
-        .transform((id, error) -> error == null ? null : errorResponse(error));
+  public void extractRequestId(ContainerRequestContext rc) {
+    var requestId = 
rc.getHeaderString(tracingConfiguration.requestId().headerName());
+    rc.setProperty(REQUEST_ID_KEY, requestId);
   }
 
   @ServerResponseFilter
   public void addResponseHeader(
       ContainerRequestContext request, ContainerResponseContext response) {
     String requestId = (String) request.getProperty(REQUEST_ID_KEY);
-    if (requestId != null) { // can be null if request ID generation fails
-      response.getHeaders().add(loggingConfiguration.requestIdHeaderName(), 
requestId);
+    if (requestId != null) {
+      response.getHeaders().add(tracingConfiguration.requestId().headerName(), 
requestId);

Review Comment:
   Do we have any specific use cases / requests for response headers? My 
impression from the `dev` ML discussion was that this feature was not in demand 
🤔 



##########
runtime/service/src/main/java/org/apache/polaris/service/events/listeners/inmemory/InMemoryBufferEventListener.java:
##########
@@ -97,6 +98,23 @@ protected String getRequestId() {
     return (String) requestContext.getProperty(REQUEST_ID_KEY);
   }
 
+  @Nullable
+  @Override
+  protected String getOpenTelemetryContext() {
+    Span span = Span.current();
+    if (span.getSpanContext().isValid()) {
+      // construct a string from the span context according to W3C Trace 
Context proposal
+      // https://www.w3.org/TR/trace-context/
+      return "00-"
+          + span.getSpanContext().getTraceId()
+          + "-"
+          + span.getSpanContext().getSpanId()
+          + "-"
+          + span.getSpanContext().getTraceFlags().asHex();

Review Comment:
   Shall we embed some spec ID into this string? E.g. 
`traceparent:00-0af7651916cd43dd8448eb211c80319c-b9c7c989f97918e1-01`



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