jojochuang commented on code in PR #10569:
URL: https://github.com/apache/ozone/pull/10569#discussion_r3482998375


##########
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/tracing/TracingUtil.java:
##########
@@ -95,13 +97,52 @@ public static synchronized void reconfigureTracing(
     initTracing(serviceName, tracingConfig);
   }
 
+  /**
+   * Drain the BatchSpanProcessor queue without shutting down.
+   * Call from short-lived CLIs before the JVM exits.
+   */
+  public static synchronized void flushTracing() {
+    if (batchSpanProcessor == null) {
+      return;
+    }
+    try {
+      // Best-effort: wait up to 10s for span export; remaining spans may be 
dropped on exit.
+      batchSpanProcessor.forceFlush().join(10, TimeUnit.SECONDS);
+    } catch (Exception e) {
+      LOG.warn("Tracing flush: forceFlush failed", e);
+    }
+  }
+
+  /**
+   * This function initializes tracing, runs the command in a span, and 
exports spans before returning for CLI spans.
+   */
+  public static <R, E extends Exception> R execute(
+      String serviceName,
+      String spanName,
+      ConfigurationSource conf,
+      CheckedSupplier<R, E> supplier) throws E {
+    initTracing(serviceName, conf);
+    try {
+      return executeInNewSpan(spanName, supplier);
+    } finally {
+      flushTracing();
+    }
+  }
+
   private static void shutdownTracing() {
-    if (sdkTracerProvider != null) {
+    if (sdkTracerProvider == null) {

Review Comment:
   sdkTracerProvider should be made a volatile.



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