sreejasahithi commented on code in PR #10020:
URL: https://github.com/apache/ozone/pull/10020#discussion_r3049005342


##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/tracing/TracingUtil.java:
##########


Review Comment:
   Here we are calling System.getenv(OTEL_TRACES_SAMPLER_ARG) again can we not 
directly use sampleStrRatio?



##########
hadoop-ozone/s3gateway/src/main/java/org/apache/hadoop/ozone/s3/TracingFilter.java:
##########
@@ -46,34 +46,57 @@ public class TracingFilter implements 
ContainerRequestFilter,
   public void filter(ContainerRequestContext requestContext) {
     finishAndCloseActiveSpan();
 
-    TracingUtil.TraceCloseable activatedSpan =
-        
TracingUtil.createActivatedSpan(resourceInfo.getResourceClass().getSimpleName() 
+ "." +
-            resourceInfo.getResourceMethod().getName());
-    requestContext.setProperty(TRACING_SPAN_CLOSABLE, activatedSpan);
+    String traceparent = requestContext.getHeaderString("traceparent");
+    String tracestate  = requestContext.getHeaderString("tracestate");
+    String encodedParent = TracingUtil.buildTraceContextCarrier(traceparent, 
tracestate);
+
+    String spanName = resourceInfo.getResourceClass().getSimpleName() + "." +
+        resourceInfo.getResourceMethod().getName();
+
+    TracingUtil.TraceCloseable traceCloseable =
+        TracingUtil.createActivatedSpanWithParent(spanName, encodedParent);
+
+    requestContext.setProperty(TRACING_SPAN_CLOSABLE, traceCloseable);
   }
 
   @Override
   public void filter(ContainerRequestContext requestContext,
       ContainerResponseContext responseContext) {
     final TracingUtil.TraceCloseable spanClosable
         = (TracingUtil.TraceCloseable) 
requestContext.getProperty(TRACING_SPAN_CLOSABLE);
+    if (spanClosable == null) {
+      return;
+    }
     // HDDS-7064: Operation performed while writing StreamingOutput response
     // should only be closed once the StreamingOutput callback has completely
     // written the data to the destination
-    OutputStream out = responseContext.getEntityStream();
-    if (out != null) {
-      responseContext.setEntityStream(new WrappedOutputStream(out) {
-        @Override
-        public void close() throws IOException {
-          super.close();
-          finishAndClose(spanClosable);
-        }
-      });
+    if (isStreamingGetObject(requestContext)) {
+      OutputStream out = responseContext.getEntityStream();
+      if (out != null) {
+        responseContext.setEntityStream(new WrappedOutputStream(out) {
+          @Override
+          public void close() throws IOException {
+            super.close();
+            finishAndClose(spanClosable);
+          }
+        });
+      } else {
+        finishAndClose(spanClosable);
+      }
     } else {
       finishAndClose(spanClosable);
     }
   }
 
+  private boolean isStreamingGetObject(ContainerRequestContext req) {
+    if (!"GET".equalsIgnoreCase(req.getMethod())) {
+      return false;
+    }
+    String cls = resourceInfo.getResourceClass().getSimpleName();
+    String method = resourceInfo.getResourceMethod().getName();
+    return "ObjectEndpoint".equals(cls) && "get".equals(method);
+  }

Review Comment:
   Instead of mentioning "GET" and "ObjectEndpoint" here directly you can 
extract them as constants.



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