This is an automated email from the ASF dual-hosted git repository.

szetszwo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ratis.git


The following commit(s) were added to refs/heads/master by this push:
     new 47bed2b51 RATIS-2398. Add opentelemetry-javaagent to ratis-examples 
and assembly (#1428)
47bed2b51 is described below

commit 47bed2b5161c38127239c96ae3a6c39551fdfc1b
Author: Tak Lon (Stephen) Wu <[email protected]>
AuthorDate: Mon Jul 20 12:46:44 2026 -0700

    RATIS-2398. Add opentelemetry-javaagent to ratis-examples and assembly 
(#1428)
---
 pom.xml                                            |  1 +
 ratis-assembly/src/main/assembly/bin.xml           |  6 ++
 .../apache/ratis/client/impl/RaftClientImpl.java   |  3 +
 .../org/apache/ratis/trace/NoOpTraceProvider.java  |  6 ++
 .../java/org/apache/ratis/trace/TraceProvider.java |  4 ++
 .../java/org/apache/ratis/trace/TraceUtils.java    |  5 ++
 ratis-examples/README.md                           | 50 ++++++++++++++++
 ratis-examples/pom.xml                             |  5 +-
 ratis-examples/src/main/bin/client.sh              |  5 +-
 ratis-examples/src/main/bin/common.sh              | 40 +++++++++++++
 ratis-examples/src/main/bin/server.sh              |  3 +-
 .../ratis/examples/arithmetic/cli/Client.java      |  2 +-
 .../ratis/examples/arithmetic/cli/Server.java      |  2 +-
 .../ratis/examples/common/ExampleLauncher.java     | 70 ++++++++++++++++++++++
 .../org/apache/ratis/examples/common/Runner.java   |  1 +
 .../ratis/examples/common/SubCommandBase.java      |  5 ++
 .../ratis/examples/filestore/cli/Client.java       |  2 +-
 .../apache/ratis/examples/filestore/cli/Read.java  |  6 +-
 .../ratis/examples/filestore/cli/Server.java       |  2 +-
 ratis-trace-otel/pom.xml                           |  6 +-
 .../apache/ratis/trace/otel/OTelTraceProvider.java |  5 ++
 .../apache/ratis/trace/otel/OTelTraceUtils.java    |  4 ++
 22 files changed, 221 insertions(+), 12 deletions(-)

diff --git a/pom.xml b/pom.xml
index f31df018d..da6816ec6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -185,6 +185,7 @@
 
     <!-- OpenTelemetry versions -->
     <opentelemetry.version>1.63.0</opentelemetry.version>
+    <opentelemetry-javaagent.version>2.28.1</opentelemetry-javaagent.version>
     <!-- Test properties -->
     
<maven.test.redirectTestOutputToFile>true</maven.test.redirectTestOutputToFile>
     <test.exclude.pattern>_</test.exclude.pattern>
diff --git a/ratis-assembly/src/main/assembly/bin.xml 
b/ratis-assembly/src/main/assembly/bin.xml
index 05286e571..4ee0dbb8d 100644
--- a/ratis-assembly/src/main/assembly/bin.xml
+++ b/ratis-assembly/src/main/assembly/bin.xml
@@ -33,6 +33,12 @@
       </includes>
       <outputDirectory>examples/lib</outputDirectory>
     </dependencySet>
+    <dependencySet>
+      <outputDirectory>lib/trace</outputDirectory>
+      <includes>
+        <include>io.opentelemetry.javaagent:*</include>
+      </includes>
+    </dependencySet>
   </dependencySets>
   <moduleSets>
     <moduleSet>
diff --git 
a/ratis-client/src/main/java/org/apache/ratis/client/impl/RaftClientImpl.java 
b/ratis-client/src/main/java/org/apache/ratis/client/impl/RaftClientImpl.java
index f24360f62..1492463fa 100644
--- 
a/ratis-client/src/main/java/org/apache/ratis/client/impl/RaftClientImpl.java
+++ 
b/ratis-client/src/main/java/org/apache/ratis/client/impl/RaftClientImpl.java
@@ -292,6 +292,9 @@ public final class RaftClientImpl implements RaftClient {
       b.setLeaderId(getLeaderId())
        .setRepliedCallIds(repliedCallIds.get(callId));
     }
+    if (TraceUtils.isEnabled()) {
+      b.setSpanContext(TraceUtils.injectContextToProto());
+    }
     return b.setClientId(clientId)
         .setGroupId(groupId)
         .setCallId(callId)
diff --git 
a/ratis-common/src/main/java/org/apache/ratis/trace/NoOpTraceProvider.java 
b/ratis-common/src/main/java/org/apache/ratis/trace/NoOpTraceProvider.java
index 66451d5c0..d7b52e8ff 100644
--- a/ratis-common/src/main/java/org/apache/ratis/trace/NoOpTraceProvider.java
+++ b/ratis-common/src/main/java/org/apache/ratis/trace/NoOpTraceProvider.java
@@ -18,6 +18,7 @@
 package org.apache.ratis.trace;
 
 import org.apache.ratis.proto.RaftProtos.AppendEntriesRequestProto;
+import org.apache.ratis.proto.RaftProtos.SpanContextProto;
 import org.apache.ratis.protocol.RaftClientRequest;
 import org.apache.ratis.protocol.RaftPeerId;
 import org.apache.ratis.util.function.CheckedSupplier;
@@ -28,6 +29,11 @@ import java.util.concurrent.CompletableFuture;
 enum NoOpTraceProvider implements TraceProvider {
   INSTANCE;
 
+  @Override
+  public SpanContextProto injectContextToProto() {
+    return null;
+  }
+
   @Override
   public <T, THROWABLE extends Throwable> CompletableFuture<T> traceClientSend(
       CheckedSupplier<CompletableFuture<T>, THROWABLE> action,
diff --git 
a/ratis-common/src/main/java/org/apache/ratis/trace/TraceProvider.java 
b/ratis-common/src/main/java/org/apache/ratis/trace/TraceProvider.java
index 36b5b11d7..1df01e424 100644
--- a/ratis-common/src/main/java/org/apache/ratis/trace/TraceProvider.java
+++ b/ratis-common/src/main/java/org/apache/ratis/trace/TraceProvider.java
@@ -18,6 +18,7 @@
 package org.apache.ratis.trace;
 
 import org.apache.ratis.proto.RaftProtos.AppendEntriesRequestProto;
+import org.apache.ratis.proto.RaftProtos.SpanContextProto;
 import org.apache.ratis.protocol.RaftClientRequest;
 import org.apache.ratis.protocol.RaftPeerId;
 import org.apache.ratis.util.function.CheckedSupplier;
@@ -26,6 +27,7 @@ import java.io.IOException;
 import java.util.concurrent.CompletableFuture;
 
 public interface TraceProvider {
+
   <T, THROWABLE extends Throwable> CompletableFuture<T> traceClientSend(
       CheckedSupplier<CompletableFuture<T>, THROWABLE> action,
       RaftClientRequest.Type type, RaftPeerId server) throws THROWABLE;
@@ -37,4 +39,6 @@ public interface TraceProvider {
   <T> CompletableFuture<T> traceAppendEntries(
       CheckedSupplier<CompletableFuture<T>, IOException> action,
       AppendEntriesRequestProto request, String memberId) throws IOException;
+
+  SpanContextProto injectContextToProto();
 }
diff --git a/ratis-common/src/main/java/org/apache/ratis/trace/TraceUtils.java 
b/ratis-common/src/main/java/org/apache/ratis/trace/TraceUtils.java
index d91a8edb2..4f15d79b2 100644
--- a/ratis-common/src/main/java/org/apache/ratis/trace/TraceUtils.java
+++ b/ratis-common/src/main/java/org/apache/ratis/trace/TraceUtils.java
@@ -18,6 +18,7 @@
 package org.apache.ratis.trace;
 
 import org.apache.ratis.conf.RaftProperties;
+import org.apache.ratis.proto.RaftProtos.SpanContextProto;
 import org.apache.ratis.util.ServiceUtils;
 
 import java.util.concurrent.atomic.AtomicReference;
@@ -55,6 +56,10 @@ public final class TraceUtils {
     return !(getProvider() instanceof NoOpTraceProvider);
   }
 
+  public static SpanContextProto injectContextToProto() {
+    return getProvider().injectContextToProto();
+  }
+
   static TraceProvider getProvider() {
     return PROVIDER.get();
   }
diff --git a/ratis-examples/README.md b/ratis-examples/README.md
index 1e50058dc..8ae5eeae1 100644
--- a/ratis-examples/README.md
+++ b/ratis-examples/README.md
@@ -146,3 +146,53 @@ by using the `run_all_tests.sh` script found in 
[dev-support/vagrant/](../dev-su
 See the [dev-support/vagrant/README.md](../dev-support/vagrant/README.md) for 
more on dependencies and what is setup.
 This will allow one to try a fully setup three server Ratis cluster on a 
single VM image,
 preventing resource contention with your development host and allowing failure 
injection too.
+
+
+## Enable Tracing when testing examples
+Ratis uses OpenTelemetry to provide distributed tracing of requests across the 
cluster.
+Tracing is configured through `RaftProperties`; Ratis itself does not read JVM 
system
+properties for configuration.
+
+The example shell scripts pass `-Draft.otel.tracing.enabled=true` as a JVM 
option when the
+OpenTelemetry agent is found. `Runner` reads that property through 
`ExampleLauncher` and
+applies it to `RaftProperties` before starting an example (e.g. "filestore" or
+"arithmetic").
+
+For example, to enable tracing for the FileStore server, you can run the 
following command:
+
+```bash
+# build the assembly jar first
+mvn clean package -DskipTests
+
+# extract the assembly jar, mainly we need the dependencies for tracing
+pushd ratis-assembly/target
+file=$(ls -1t ratis-assembly-*.tar.gz | head -n1)
+tar -zxvf "$file"
+popd
+
+# run the server, the tracing will be enabled because it found the 
+# opentelemetry agent jar
+BIN=ratis-examples/src/main/bin
+PEERS=n0:127.0.0.1:6000,n1:127.0.0.1:6001,n2:127.0.0.1:6002
+
+ID=n0; ${BIN}/server.sh filestore server --id ${ID} --storage /tmp/ratis/${ID} 
--peers ${PEERS}
+ID=n1; ${BIN}/server.sh filestore server --id ${ID} --storage /tmp/ratis/${ID} 
--peers ${PEERS}
+ID=n2; ${BIN}/server.sh filestore server --id ${ID} --storage /tmp/ratis/${ID} 
--peers ${PEERS}
+
+# some message should be shown
+[otel.javaagent 2026-04-15 15:55:11:320 -0700] [main] INFO 
io.opentelemetry.javaagent.tooling.VersionLogger - opentelemetry-javaagent - 
version: 2.26.1
+```
+
+If you want to configure the tracing further, you can set the following system 
properties
+
+```bash
+# below is an example to configure the OTLP exporter to send the traces to a 
local collector,
+# you can change the endpoint and protocol as needed. ExampleLauncher reads
+# -Draft.otel.tracing.enabled=true and applies it to RaftProperties.
+export OTEL_EXPORTER_OPTS="-Dotel.traces.exporter=otlp \
+-Dotel.exporter.otlp.protocol=grpc \
+-Dotel.exporter.otlp.endpoint=http://localhost:4317 \
+-Dotel.metrics.exporter=none \
+-Dotel.logs.exporter=none \
+-Draft.otel.tracing.enabled=true"
+```
\ No newline at end of file
diff --git a/ratis-examples/pom.xml b/ratis-examples/pom.xml
index c52019334..8064b1be6 100644
--- a/ratis-examples/pom.xml
+++ b/ratis-examples/pom.xml
@@ -116,7 +116,10 @@
       <artifactId>slf4j-reload4j</artifactId>
       <scope>runtime</scope>
     </dependency>
-
+    <dependency>
+      <groupId>org.apache.ratis</groupId>
+      <artifactId>ratis-trace-otel</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.junit.jupiter</groupId>
       <artifactId>junit-jupiter-engine</artifactId>
diff --git a/ratis-examples/src/main/bin/client.sh 
b/ratis-examples/src/main/bin/client.sh
index e42786fa3..d5e00268e 100755
--- a/ratis-examples/src/main/bin/client.sh
+++ b/ratis-examples/src/main/bin/client.sh
@@ -23,7 +23,8 @@ if [ "$#" -lt 2 ]; then
   exit 1
 fi
 
-source $DIR/common.sh
+OTEL_SERVICE_NAME=ratis.client
+source "${DIR}/common.sh"
 
 # One of the examples, e.g. "filestore" or "arithmetic"
 example="$1"
@@ -32,4 +33,4 @@ shift
 subcommand="$1"
 shift
 
-java ${LOGGER_OPTS} -jar $ARTIFACT "$example" "$subcommand" "$@"
+java ${OTEL_OPTS} ${LOGGER_OPTS} -jar $ARTIFACT "$example" "$subcommand" "$@"
diff --git a/ratis-examples/src/main/bin/common.sh 
b/ratis-examples/src/main/bin/common.sh
index b05bf4dbf..8fa3b3ba7 100755
--- a/ratis-examples/src/main/bin/common.sh
+++ b/ratis-examples/src/main/bin/common.sh
@@ -46,3 +46,43 @@ if [[ -d "${CONF_DIR}" ]]; then
 else
   LOGGER_OPTS="-Dlog4j.configuration=file:${DIR}/../resources/log4j.properties"
 fi
+
+
+# for opentelemetry: release tarball uses lib/trace next to examples/;
+# dev tree uses ratis-assembly/target/apache-ratis-*-bin/lib/trace after 
package.
+if [[ -n "${OTEL_JAR:-}" && -f "${OTEL_JAR}" ]]; then
+  : # use OTEL_JAR from environment
+else
+  otel_jar_candidates=()
+  for _jar in "${SCRIPT_DIR}"/../../lib/trace/opentelemetry-javaagent*.jar; do
+    [[ -f "${_jar}" ]] && otel_jar_candidates+=("${_jar}")
+  done
+  for _otel_trace_dir in 
"${SCRIPT_DIR}"/../../../../ratis-assembly/target/apache-ratis-*-bin/lib/trace; 
do
+    [[ -d "${_otel_trace_dir}" ]] || continue
+    for _jar in "${_otel_trace_dir}"/opentelemetry-javaagent*.jar; do
+      [[ -f "${_jar}" ]] && otel_jar_candidates+=("${_jar}")
+    done
+  done
+  if ((${#otel_jar_candidates[@]} > 0)); then
+    OTEL_JAR="$(printf '%s\n' "${otel_jar_candidates[@]}" | sort -V | tail -n 
1)"
+  else
+    echo "Warning: OpenTelemetry agent jar not found; OTEL disabled"
+    OTEL_JAR=""
+  fi
+fi
+
+OTEL_SERVICE_NAME="${OTEL_SERVICE_NAME:-ratis.server}"
+OTEL_DEFAULT_EXPORTER_OPTS="-Dotel.traces.exporter=logging \
+-Dotel.metrics.exporter=none \
+-Dotel.logs.exporter=logging"
+# Unset or empty → default exporter flags (empty is not a supported override).
+OTEL_EXPORTER_OPTS="${OTEL_EXPORTER_OPTS:-${OTEL_DEFAULT_EXPORTER_OPTS}}"
+
+# Enable javaagent when OTEL_JAR resolves to a file (env or discovery above).
+if [[ -n "${OTEL_JAR}" && -f "${OTEL_JAR}" ]]; then
+  OTEL_OPTS="-javaagent:${OTEL_JAR} 
-Dotel.resource.attributes=service.name=${OTEL_SERVICE_NAME} 
${OTEL_EXPORTER_OPTS} -Draft.otel.tracing.enabled=true"
+else
+  OTEL_OPTS=""
+fi
+
+echo "Using OTEL_OPTS: ${OTEL_OPTS}"
\ No newline at end of file
diff --git a/ratis-examples/src/main/bin/server.sh 
b/ratis-examples/src/main/bin/server.sh
index 3cc069edf..c0468c15b 100755
--- a/ratis-examples/src/main/bin/server.sh
+++ b/ratis-examples/src/main/bin/server.sh
@@ -16,5 +16,4 @@
 
 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" > /dev/null && pwd )"
 source $DIR/common.sh
-
-java ${LOGGER_OPTS} -jar $ARTIFACT "$@"
+java ${OTEL_OPTS} ${LOGGER_OPTS} -jar $ARTIFACT "$@"
diff --git 
a/ratis-examples/src/main/java/org/apache/ratis/examples/arithmetic/cli/Client.java
 
b/ratis-examples/src/main/java/org/apache/ratis/examples/arithmetic/cli/Client.java
index 5c01520ce..bb2ad3188 100644
--- 
a/ratis-examples/src/main/java/org/apache/ratis/examples/arithmetic/cli/Client.java
+++ 
b/ratis-examples/src/main/java/org/apache/ratis/examples/arithmetic/cli/Client.java
@@ -37,7 +37,7 @@ public abstract class Client extends SubCommandBase {
 
   @Override
   public void run() throws Exception {
-    RaftProperties raftProperties = new RaftProperties();
+    RaftProperties raftProperties = newRaftProperties();
 
     final RaftGroup raftGroup = 
RaftGroup.valueOf(RaftGroupId.valueOf(ByteString.copyFromUtf8(getRaftGroupId())),
             getPeers());
diff --git 
a/ratis-examples/src/main/java/org/apache/ratis/examples/arithmetic/cli/Server.java
 
b/ratis-examples/src/main/java/org/apache/ratis/examples/arithmetic/cli/Server.java
index a93997425..a3bbf5a9f 100644
--- 
a/ratis-examples/src/main/java/org/apache/ratis/examples/arithmetic/cli/Server.java
+++ 
b/ratis-examples/src/main/java/org/apache/ratis/examples/arithmetic/cli/Server.java
@@ -56,7 +56,7 @@ public class Server extends SubCommandBase {
   @Override
   public void run() throws Exception {
     RaftPeerId peerId = RaftPeerId.valueOf(id);
-    RaftProperties properties = new RaftProperties();
+    RaftProperties properties = newRaftProperties();
 
     final int port = 
NetUtils.createSocketAddr(getPeer(peerId).getAddress()).getPort();
     GrpcConfigKeys.Server.setPort(properties, port);
diff --git 
a/ratis-examples/src/main/java/org/apache/ratis/examples/common/ExampleLauncher.java
 
b/ratis-examples/src/main/java/org/apache/ratis/examples/common/ExampleLauncher.java
new file mode 100644
index 000000000..373eeb052
--- /dev/null
+++ 
b/ratis-examples/src/main/java/org/apache/ratis/examples/common/ExampleLauncher.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ratis.examples.common;
+
+import org.apache.ratis.conf.RaftProperties;
+import org.apache.ratis.trace.TraceConfigKeys;
+import org.apache.ratis.util.StringUtils;
+
+/**
+ * Applies example-only JVM system properties to {@link RaftProperties}.
+ * {@link Runner} calls {@link #init()} at startup; example subcommands obtain
+ * configured properties via {@link #newRaftProperties()}.
+ */
+public final class ExampleLauncher {
+
+  private static volatile boolean initialized;
+  private static Boolean tracingEnabled;
+
+  private ExampleLauncher() {
+  }
+
+  /** Reads example JVM system properties. Called once from {@link 
Runner#main}. */
+  public static void init() {
+    initFromSystemProperties();
+  }
+
+  /**
+   * Creates {@link RaftProperties} for examples, applying any tracing 
configuration
+   * read from the JVM system property {@value TraceConfigKeys#ENABLED_KEY}.
+   */
+  public static RaftProperties newRaftProperties() {
+    initFromSystemProperties();
+    final RaftProperties properties = new RaftProperties();
+    if (tracingEnabled != null) {
+      TraceConfigKeys.setEnabled(properties, tracingEnabled);
+    }
+    return properties;
+  }
+
+  private static void initFromSystemProperties() {
+    if (initialized) {
+      return;
+    }
+    synchronized (ExampleLauncher.class) {
+      if (initialized) {
+        return;
+      }
+      final String value = System.getProperty(TraceConfigKeys.ENABLED_KEY);
+      if (value != null) {
+        tracingEnabled = StringUtils.string2boolean(value.trim(), 
TraceConfigKeys.ENABLED_DEFAULT);
+      }
+      initialized = true;
+    }
+  }
+}
diff --git 
a/ratis-examples/src/main/java/org/apache/ratis/examples/common/Runner.java 
b/ratis-examples/src/main/java/org/apache/ratis/examples/common/Runner.java
index f8090ff79..5dd4c7a18 100644
--- a/ratis-examples/src/main/java/org/apache/ratis/examples/common/Runner.java
+++ b/ratis-examples/src/main/java/org/apache/ratis/examples/common/Runner.java
@@ -40,6 +40,7 @@ public final class Runner {
       System.err.println("No command type specified: ");
       return;
     }
+    ExampleLauncher.init();
     List<SubCommandBase> commands = initializeCommands(args[0]);
     Runner runner = new Runner();
 
diff --git 
a/ratis-examples/src/main/java/org/apache/ratis/examples/common/SubCommandBase.java
 
b/ratis-examples/src/main/java/org/apache/ratis/examples/common/SubCommandBase.java
index 0755cbd8b..83354a45a 100644
--- 
a/ratis-examples/src/main/java/org/apache/ratis/examples/common/SubCommandBase.java
+++ 
b/ratis-examples/src/main/java/org/apache/ratis/examples/common/SubCommandBase.java
@@ -18,6 +18,7 @@
 package org.apache.ratis.examples.common;
 
 import com.beust.jcommander.Parameter;
+import org.apache.ratis.conf.RaftProperties;
 import org.apache.ratis.protocol.RaftPeer;
 import org.apache.ratis.protocol.RaftPeerId;
 import org.apache.ratis.protocol.RoutingTable;
@@ -114,6 +115,10 @@ public abstract class SubCommandBase {
 
   public abstract void run() throws Exception;
 
+  protected RaftProperties newRaftProperties() {
+    return ExampleLauncher.newRaftProperties();
+  }
+
   public String getRaftGroupId() {
     return raftGroupId;
   }
diff --git 
a/ratis-examples/src/main/java/org/apache/ratis/examples/filestore/cli/Client.java
 
b/ratis-examples/src/main/java/org/apache/ratis/examples/filestore/cli/Client.java
index caf2aa59b..4cdad21fe 100644
--- 
a/ratis-examples/src/main/java/org/apache/ratis/examples/filestore/cli/Client.java
+++ 
b/ratis-examples/src/main/java/org/apache/ratis/examples/filestore/cli/Client.java
@@ -94,7 +94,7 @@ public abstract class Client extends SubCommandBase {
   @Override
   public void run() throws Exception {
     int raftSegmentPreallocatedSize = 1024 * 1024 * 1024;
-    RaftProperties raftProperties = new RaftProperties();
+    RaftProperties raftProperties = newRaftProperties();
     RaftConfigKeys.Rpc.setType(raftProperties, SupportedRpcType.GRPC);
     GrpcConfigKeys.setMessageSizeMax(raftProperties,
         SizeInBytes.valueOf(raftSegmentPreallocatedSize));
diff --git 
a/ratis-examples/src/main/java/org/apache/ratis/examples/filestore/cli/Read.java
 
b/ratis-examples/src/main/java/org/apache/ratis/examples/filestore/cli/Read.java
index 128a9abba..ef317b4f6 100644
--- 
a/ratis-examples/src/main/java/org/apache/ratis/examples/filestore/cli/Read.java
+++ 
b/ratis-examples/src/main/java/org/apache/ratis/examples/filestore/cli/Read.java
@@ -24,6 +24,7 @@ import org.apache.ratis.client.RaftClient;
 import org.apache.ratis.client.RaftClientConfigKeys;
 import org.apache.ratis.conf.RaftProperties;
 import org.apache.ratis.datastream.SupportedDataStreamType;
+import org.apache.ratis.examples.common.ExampleLauncher;
 import org.apache.ratis.examples.common.SubCommandBase;
 import org.apache.ratis.examples.filestore.FileStoreClient;
 import org.apache.ratis.grpc.GrpcConfigKeys;
@@ -124,9 +125,10 @@ public class Read extends SubCommandBase {
     }
   }
 
-  private static RaftProperties newRaftProperties() {
+  @Override
+  protected RaftProperties newRaftProperties() {
     final int raftSegmentPreallocatedSize = 1024 * 1024 * 1024;
-    final RaftProperties raftProperties = new RaftProperties();
+    final RaftProperties raftProperties = ExampleLauncher.newRaftProperties();
     RaftConfigKeys.Rpc.setType(raftProperties, SupportedRpcType.GRPC);
     GrpcConfigKeys.setMessageSizeMax(raftProperties, 
SizeInBytes.valueOf(raftSegmentPreallocatedSize));
     RaftServerConfigKeys.Log.Appender.setBufferByteLimit(raftProperties,
diff --git 
a/ratis-examples/src/main/java/org/apache/ratis/examples/filestore/cli/Server.java
 
b/ratis-examples/src/main/java/org/apache/ratis/examples/filestore/cli/Server.java
index 5204ee21b..071fdd170 100644
--- 
a/ratis-examples/src/main/java/org/apache/ratis/examples/filestore/cli/Server.java
+++ 
b/ratis-examples/src/main/java/org/apache/ratis/examples/filestore/cli/Server.java
@@ -77,7 +77,7 @@ public class Server extends SubCommandBase {
     JvmMetrics.initJvmMetrics(TimeDuration.valueOf(10, TimeUnit.SECONDS));
 
     RaftPeerId peerId = RaftPeerId.valueOf(id);
-    RaftProperties properties = new RaftProperties();
+    RaftProperties properties = newRaftProperties();
 
     // Avoid leader change affect the performance
     RaftServerConfigKeys.Rpc.setTimeoutMin(properties, TimeDuration.valueOf(2, 
TimeUnit.SECONDS));
diff --git a/ratis-trace-otel/pom.xml b/ratis-trace-otel/pom.xml
index 6e04f3286..2399d91b6 100644
--- a/ratis-trace-otel/pom.xml
+++ b/ratis-trace-otel/pom.xml
@@ -51,7 +51,11 @@
       <version>${opentelemetry.version}</version>
       <scope>test</scope>
     </dependency>
-
+    <dependency>
+      <groupId>io.opentelemetry.javaagent</groupId>
+      <artifactId>opentelemetry-javaagent</artifactId>
+      <version>${opentelemetry-javaagent.version}</version>
+    </dependency>
     <dependency>
       <groupId>org.junit.jupiter</groupId>
       <artifactId>junit-jupiter-engine</artifactId>
diff --git 
a/ratis-trace-otel/src/main/java/org/apache/ratis/trace/otel/OTelTraceProvider.java
 
b/ratis-trace-otel/src/main/java/org/apache/ratis/trace/otel/OTelTraceProvider.java
index 94942b4d5..5ba4d2f55 100644
--- 
a/ratis-trace-otel/src/main/java/org/apache/ratis/trace/otel/OTelTraceProvider.java
+++ 
b/ratis-trace-otel/src/main/java/org/apache/ratis/trace/otel/OTelTraceProvider.java
@@ -60,6 +60,11 @@ public final class OTelTraceProvider implements 
TraceProvider {
       GlobalOpenTelemetry.getTracer("org.apache.ratis", 
VersionInfo.getSoftwareInfoVersion()),
       "tracer == null");
 
+  @Override
+  public SpanContextProto injectContextToProto() {
+    return OTelTraceUtils.injectContextToProto();
+  }
+
   @Override
   public <T, THROWABLE extends Throwable> CompletableFuture<T> traceClientSend(
       CheckedSupplier<CompletableFuture<T>, THROWABLE> action,
diff --git 
a/ratis-trace-otel/src/main/java/org/apache/ratis/trace/otel/OTelTraceUtils.java
 
b/ratis-trace-otel/src/main/java/org/apache/ratis/trace/otel/OTelTraceUtils.java
index 662503a8d..fda0ca5c0 100644
--- 
a/ratis-trace-otel/src/main/java/org/apache/ratis/trace/otel/OTelTraceUtils.java
+++ 
b/ratis-trace-otel/src/main/java/org/apache/ratis/trace/otel/OTelTraceUtils.java
@@ -32,6 +32,10 @@ public final class OTelTraceUtils {
   private OTelTraceUtils() {
   }
 
+  public static SpanContextProto injectContextToProto() {
+    return injectContextToProto(Context.current());
+  }
+
   public static SpanContextProto injectContextToProto(Context context) {
     final Map<String, String> carrier = new TreeMap<>();
     getTextMapPropagator().inject(context, carrier, (map, key, value) -> 
map.put(key, value));

Reply via email to