This is an automated email from the ASF dual-hosted git repository.
adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new be545286f93 HDDS-15579. Replace SimpleSpanProcessor with
BatchSpanProcessor (#10569)
be545286f93 is described below
commit be545286f93d96ca93e4ad3798d6c2365443f3fb
Author: sravani <[email protected]>
AuthorDate: Mon Jul 6 16:11:08 2026 +0530
HDDS-15579. Replace SimpleSpanProcessor with BatchSpanProcessor (#10569)
---
.../apache/hadoop/hdds/tracing/TracingUtil.java | 58 +++++++++++++++++++---
.../java/org/apache/hadoop/ozone/shell/Shell.java | 4 +-
.../dist/src/main/compose/ozone/monitoring.conf | 2 +-
.../java/org/apache/hadoop/ozone/freon/Freon.java | 3 +-
.../org/apache/hadoop/fs/ozone/OzoneFsShell.java | 11 ++--
.../org/apache/hadoop/ozone/shell/OzoneRatis.java | 5 +-
6 files changed, 62 insertions(+), 21 deletions(-)
diff --git
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/tracing/TracingUtil.java
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/tracing/TracingUtil.java
index b2263c4f5be..d25817a7a7d 100644
---
a/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/tracing/TracingUtil.java
+++
b/hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/tracing/TracingUtil.java
@@ -31,12 +31,13 @@
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
-import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
+import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
import io.opentelemetry.sdk.trace.samplers.Sampler;
import java.lang.reflect.Proxy;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import org.apache.hadoop.hdds.conf.ConfigurationSource;
import org.apache.ratis.util.function.CheckedRunnable;
@@ -53,7 +54,8 @@ public final class TracingUtil {
private static volatile boolean isInit = false;
private static Tracer tracer = OpenTelemetry.noop().getTracer("noop");
- private static SdkTracerProvider sdkTracerProvider;
+ private static volatile SdkTracerProvider sdkTracerProvider;
+ private static BatchSpanProcessor batchSpanProcessor;
private TracingUtil() {
}
@@ -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) {
- sdkTracerProvider.shutdown();
+ if (sdkTracerProvider == null) {
+ return;
+ }
+ try {
+ sdkTracerProvider.shutdown().join(10L, TimeUnit.SECONDS);
+ } catch (Exception e) {
+ LOG.warn("Tracing shutdown failed", e);
+ } finally {
sdkTracerProvider = null;
+ batchSpanProcessor = null;
+ tracer = OpenTelemetry.noop().getTracer("noop");
+ isInit = false;
}
- tracer = OpenTelemetry.noop().getTracer("noop");
- isInit = false;
}
private static void initialize(String serviceName, TracingConfig
tracingConfig) {
@@ -119,7 +160,7 @@ private static void initialize(String serviceName,
TracingConfig tracingConfig)
.setEndpoint(otelEndPoint)
.build();
- SimpleSpanProcessor spanProcessor =
SimpleSpanProcessor.builder(spanExporter).build();
+ batchSpanProcessor = BatchSpanProcessor.builder(spanExporter).build();
// Choose sampler based on span sampling config. If it is empty use trace
based sampling only.
// else use custom SpanSampler.
@@ -132,7 +173,7 @@ private static void initialize(String serviceName,
TracingConfig tracingConfig)
}
SdkTracerProvider tracerProvider = SdkTracerProvider.builder()
- .addSpanProcessor(spanProcessor)
+ .addSpanProcessor(batchSpanProcessor)
.setResource(resource)
.setSampler(sampler)
.build();
@@ -145,6 +186,7 @@ private static void initialize(String serviceName,
TracingConfig tracingConfig)
sdkTracerProvider = tracerProvider;
} catch (RuntimeException e) {
tracerProvider.shutdown();
+ batchSpanProcessor = null;
throw e;
}
}
diff --git
a/hadoop-ozone/cli-shell/src/main/java/org/apache/hadoop/ozone/shell/Shell.java
b/hadoop-ozone/cli-shell/src/main/java/org/apache/hadoop/ozone/shell/Shell.java
index 5106497a8d1..f3e5efdd98a 100644
---
a/hadoop-ozone/cli-shell/src/main/java/org/apache/hadoop/ozone/shell/Shell.java
+++
b/hadoop-ozone/cli-shell/src/main/java/org/apache/hadoop/ozone/shell/Shell.java
@@ -99,9 +99,9 @@ private int execute(CommandLine.ParseResult parseResult) {
return 0;
}
- TracingUtil.initTracing("shell", getOzoneConf());
String spanName = spec.name() + " " + String.join(" ",
parseResult.originalArgs());
- return TracingUtil.executeInNewSpan(spanName, () -> new
CommandLine.RunLast().execute(parseResult));
+ return TracingUtil.execute("shell", spanName, getOzoneConf(),
+ () -> new CommandLine.RunLast().execute(parseResult));
}
private void installBatchExceptionHandler() {
diff --git a/hadoop-ozone/dist/src/main/compose/ozone/monitoring.conf
b/hadoop-ozone/dist/src/main/compose/ozone/monitoring.conf
index ef490953a1d..6b4262429f4 100644
--- a/hadoop-ozone/dist/src/main/compose/ozone/monitoring.conf
+++ b/hadoop-ozone/dist/src/main/compose/ozone/monitoring.conf
@@ -15,7 +15,7 @@
# limitations under the License.
OZONE-SITE.XML_hdds.prometheus.endpoint.enabled=true
-OZONE-SITE.XML_hdds.tracing.enabled=true
+OZONE-SITE.XML_ozone.tracing.enabled=true
OZONE-SITE.XML_ozone.metastore.rocksdb.statistics=ALL
HDFS-SITE.XML_rpc.metrics.quantile.enable=true
HDFS-SITE.XML_rpc.metrics.percentiles.intervals=60,300
diff --git
a/hadoop-ozone/freon/src/main/java/org/apache/hadoop/ozone/freon/Freon.java
b/hadoop-ozone/freon/src/main/java/org/apache/hadoop/ozone/freon/Freon.java
index c6e21cf7a95..b4a23943400 100644
--- a/hadoop-ozone/freon/src/main/java/org/apache/hadoop/ozone/freon/Freon.java
+++ b/hadoop-ozone/freon/src/main/java/org/apache/hadoop/ozone/freon/Freon.java
@@ -57,9 +57,8 @@ public class Freon extends GenericCli implements
ExtensibleParentCommand {
public int execute(String[] argv) {
conf = getOzoneConf();
HddsServerUtil.initializeMetrics(conf, "ozone-freon");
- TracingUtil.initTracing("freon", conf);
String spanName = "ozone freon " + String.join(" ", argv);
- return TracingUtil.executeInNewSpan(spanName, () -> super.execute(argv));
+ return TracingUtil.execute("freon", spanName, conf, () ->
super.execute(argv));
}
@Override
diff --git
a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/fs/ozone/OzoneFsShell.java
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/fs/ozone/OzoneFsShell.java
index 9eb42d752eb..c7519ea6f97 100644
---
a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/fs/ozone/OzoneFsShell.java
+++
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/fs/ozone/OzoneFsShell.java
@@ -78,12 +78,13 @@ protected String getUsagePrefix() {
public static void main(String[] argv) throws Exception {
OzoneFsShell shell = newShellInstance();
OzoneConfiguration conf = new OzoneConfiguration();
- TracingUtil.initTracing("FsShell", conf);
- conf.setQuietMode(false);
- shell.setConf(conf);
String spanName = "ozone fs " + String.join(" ", argv);
- int res = TracingUtil.executeInNewSpan(spanName,
- () -> shell.execute(argv));
+ int res = TracingUtil.execute("FsShell", spanName, conf, () -> {
+ conf.setQuietMode(false);
+ shell.setConf(conf);
+ return shell.execute(argv);
+ });
+
System.exit(res);
}
diff --git
a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/OzoneRatis.java
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/OzoneRatis.java
index 2a88d9a4b4c..f69fe7c8a7a 100644
---
a/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/OzoneRatis.java
+++
b/hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/shell/OzoneRatis.java
@@ -38,9 +38,8 @@ public static void main(String[] argv) throws Exception {
@Override
public int execute(String[] argv) {
- TracingUtil.initTracing("shell", getOzoneConf());
- String spanName = "ozone ratis" + String.join(" ", argv);
- return TracingUtil.executeInNewSpan(spanName, () -> {
+ String spanName = "ozone ratis " + String.join(" ", argv);
+ return TracingUtil.execute("shell", spanName, getOzoneConf(), () -> {
// TODO: When Ozone has RATIS-2155, update this line to use the
RatisShell.Builder
// in order to setup TLS and other confs.
final RatisShell shell = new RatisShell(System.out);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]