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/ratis.git
The following commit(s) were added to refs/heads/master by this push:
new 400d9cf64 RATIS-2562. Use OTel prefix for OpenTelemetry code (#1482)
400d9cf64 is described below
commit 400d9cf643b3fae0c4070bca8d2d8a2f02f4cb0a
Author: Tsz-Wo Nicholas Sze <[email protected]>
AuthorDate: Tue Jun 16 13:20:16 2026 -0700
RATIS-2562. Use OTel prefix for OpenTelemetry code (#1482)
---
.../java/org/apache/ratis/trace/TraceUtils.java | 11 +++----
.../OTelRatisAttributes.java} | 11 +++----
.../OTelTraceProvider.java} | 37 +++++++++++++---------
.../OTelTraceUtils.java} | 6 ++--
.../server/impl/RaftServerImplTracingTests.java | 14 ++++----
5 files changed, 41 insertions(+), 38 deletions(-)
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 a164184ea..780a4e650 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,7 +18,7 @@
package org.apache.ratis.trace;
import org.apache.ratis.conf.RaftProperties;
-import org.apache.ratis.trace.opentelemetry.OpenTelemetryTraceProvider;
+import org.apache.ratis.trace.otel.OTelTraceProvider;
import java.util.concurrent.atomic.AtomicReference;
@@ -33,9 +33,7 @@ public final class TraceUtils {
/**
* Initializes tracing from configuration when tracing is enabled, or clears
it when disabled.
- * Call from {@link org.apache.ratis.server.RaftServer} and
- * {@link org.apache.ratis.client.RaftClient} construction so tracing follows
- * {@link TraceConfigKeys}.
+ * Call from RaftServer and RaftClient construction so tracing follows
{@link TraceConfigKeys}.
*
* @param properties raft configuration; tracing is on when {@link
TraceConfigKeys#enabled} is true
*/
@@ -63,10 +61,9 @@ public final class TraceUtils {
private static TraceProvider newOpenTelemetryTraceProvider() {
try {
- return new OpenTelemetryTraceProvider();
+ return new OTelTraceProvider();
} catch (Throwable e) {
- throw new IllegalStateException(
- "OpenTelemetry tracing is enabled but OpenTelemetry is not
available; tracing is disabled", e);
+ throw new IllegalStateException("Failed to create OTelTraceProvider.",
e);
}
}
}
diff --git
a/ratis-common/src/main/java/org/apache/ratis/trace/RatisAttributes.java
b/ratis-common/src/main/java/org/apache/ratis/trace/otel/OTelRatisAttributes.java
similarity index 88%
rename from
ratis-common/src/main/java/org/apache/ratis/trace/RatisAttributes.java
rename to
ratis-common/src/main/java/org/apache/ratis/trace/otel/OTelRatisAttributes.java
index ea0c3a342..ac7872a97 100644
--- a/ratis-common/src/main/java/org/apache/ratis/trace/RatisAttributes.java
+++
b/ratis-common/src/main/java/org/apache/ratis/trace/otel/OTelRatisAttributes.java
@@ -15,16 +15,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.ratis.trace;
+package org.apache.ratis.trace.otel;
import io.opentelemetry.api.common.AttributeKey;
/**
- * The constants in this class correspond with the guidance outlined by the
OpenTelemetry <a href=
- * "https://github.com/open-telemetry/semantic-conventions">Semantic
- * Conventions</a>.
+ * The constants in this class correspond with the guidance outlined by the
OpenTelemetry
+ * <a href="https://github.com/open-telemetry/semantic-conventions">Semantic
Conventions</a>.
*/
-public final class RatisAttributes {
+public final class OTelRatisAttributes {
public static final AttributeKey<String> CLIENT_ID =
AttributeKey.stringKey("raft.client.id");
public static final AttributeKey<String> MEMBER_ID =
AttributeKey.stringKey("raft.member.id");
public static final AttributeKey<String> CALL_ID =
AttributeKey.stringKey("raft.call.id");
@@ -36,6 +35,6 @@ public final class RatisAttributes {
/** Number of log entries in a single {@code AppendEntries} RPC (0 for
heartbeat). */
public static final AttributeKey<Long> APPEND_ENTRIES_COUNT =
AttributeKey.longKey("raft.append.entries.count");
- private RatisAttributes() {
+ private OTelRatisAttributes() {
}
}
diff --git
a/ratis-common/src/main/java/org/apache/ratis/trace/opentelemetry/OpenTelemetryTraceProvider.java
b/ratis-common/src/main/java/org/apache/ratis/trace/otel/OTelTraceProvider.java
similarity index 82%
rename from
ratis-common/src/main/java/org/apache/ratis/trace/opentelemetry/OpenTelemetryTraceProvider.java
rename to
ratis-common/src/main/java/org/apache/ratis/trace/otel/OTelTraceProvider.java
index a1059d9bf..94942b4d5 100644
---
a/ratis-common/src/main/java/org/apache/ratis/trace/opentelemetry/OpenTelemetryTraceProvider.java
+++
b/ratis-common/src/main/java/org/apache/ratis/trace/otel/OTelTraceProvider.java
@@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.ratis.trace.opentelemetry;
+package org.apache.ratis.trace.otel;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.trace.Span;
@@ -29,7 +29,6 @@ import org.apache.ratis.proto.RaftProtos.RaftRpcRequestProto;
import org.apache.ratis.proto.RaftProtos.SpanContextProto;
import org.apache.ratis.protocol.RaftClientRequest;
import org.apache.ratis.protocol.RaftPeerId;
-import org.apache.ratis.trace.RatisAttributes;
import org.apache.ratis.trace.SpanNames;
import org.apache.ratis.trace.TraceProvider;
import org.apache.ratis.util.JavaUtils;
@@ -45,8 +44,16 @@ import java.util.concurrent.CompletableFuture;
import java.util.function.BiConsumer;
import java.util.function.Supplier;
-public final class OpenTelemetryTraceProvider implements TraceProvider {
- private static final Logger LOG =
LoggerFactory.getLogger(OpenTelemetryTraceProvider.class);
+import static
org.apache.ratis.trace.otel.OTelRatisAttributes.APPEND_ENTRIES_COUNT;
+import static org.apache.ratis.trace.otel.OTelRatisAttributes.CALL_ID;
+import static org.apache.ratis.trace.otel.OTelRatisAttributes.CLIENT_ID;
+import static org.apache.ratis.trace.otel.OTelRatisAttributes.MEMBER_ID;
+import static org.apache.ratis.trace.otel.OTelRatisAttributes.OPERATION_NAME;
+import static org.apache.ratis.trace.otel.OTelRatisAttributes.OPERATION_TYPE;
+import static org.apache.ratis.trace.otel.OTelRatisAttributes.PEER_ID;
+
+public final class OTelTraceProvider implements TraceProvider {
+ private static final Logger LOG =
LoggerFactory.getLogger(OTelTraceProvider.class);
private static final String LEADER = "LEADER";
private final Tracer tracer = Objects.requireNonNull(
@@ -75,15 +82,15 @@ public final class OpenTelemetryTraceProvider implements
TraceProvider {
final SpanContextProto spanContext = rpc.getSpanContext();
final Context remoteContext = (spanContext == null ||
spanContext.getContextMap().isEmpty())
? Context.root()
- : OpenTelemetryTraceUtils.extractContextFromProto(spanContext);
+ : OTelTraceUtils.extractContextFromProto(spanContext);
return traceAsyncMethod(action, () -> {
final Span span = tracer.spanBuilder(SpanNames.APPEND_ENTRIES_ASYNC)
.setParent(remoteContext)
.setSpanKind(SpanKind.INTERNAL)
.startSpan();
- span.setAttribute(RatisAttributes.MEMBER_ID, memberId);
- span.setAttribute(RatisAttributes.PEER_ID,
String.valueOf(RaftPeerId.valueOf(rpc.getRequestorId())));
- span.setAttribute(RatisAttributes.APPEND_ENTRIES_COUNT, (long)
request.getEntriesCount());
+ span.setAttribute(MEMBER_ID, memberId);
+ span.setAttribute(PEER_ID,
String.valueOf(RaftPeerId.valueOf(rpc.getRequestorId())));
+ span.setAttribute(APPEND_ENTRIES_COUNT, request.getEntriesCount());
return span;
});
}
@@ -95,21 +102,21 @@ public final class OpenTelemetryTraceProvider implements
TraceProvider {
final Span span = tracer.spanBuilder(spanName)
.setSpanKind(SpanKind.CLIENT)
.startSpan();
- span.setAttribute(RatisAttributes.PEER_ID, peerId);
- span.setAttribute(RatisAttributes.OPERATION_NAME, spanName);
- span.setAttribute(RatisAttributes.OPERATION_TYPE, String.valueOf(type));
+ span.setAttribute(PEER_ID, peerId);
+ span.setAttribute(OPERATION_NAME, spanName);
+ span.setAttribute(OPERATION_TYPE, String.valueOf(type));
return span;
}
private Span createServerSpanFromClientRequest(RaftClientRequest request,
String memberId, String spanName) {
- final Context remoteContext =
OpenTelemetryTraceUtils.extractContextFromProto(request.getSpanContext());
+ final Context remoteContext =
OTelTraceUtils.extractContextFromProto(request.getSpanContext());
final Span span = tracer.spanBuilder(spanName)
.setParent(remoteContext)
.setSpanKind(SpanKind.SERVER)
.startSpan();
- span.setAttribute(RatisAttributes.CLIENT_ID,
String.valueOf(request.getClientId()));
- span.setAttribute(RatisAttributes.CALL_ID,
String.valueOf(request.getCallId()));
- span.setAttribute(RatisAttributes.MEMBER_ID, memberId);
+ span.setAttribute(CLIENT_ID, String.valueOf(request.getClientId()));
+ span.setAttribute(CALL_ID, String.valueOf(request.getCallId()));
+ span.setAttribute(MEMBER_ID, memberId);
return span;
}
diff --git
a/ratis-common/src/main/java/org/apache/ratis/trace/opentelemetry/OpenTelemetryTraceUtils.java
b/ratis-common/src/main/java/org/apache/ratis/trace/otel/OTelTraceUtils.java
similarity index 95%
rename from
ratis-common/src/main/java/org/apache/ratis/trace/opentelemetry/OpenTelemetryTraceUtils.java
rename to
ratis-common/src/main/java/org/apache/ratis/trace/otel/OTelTraceUtils.java
index b5f0c8c24..662503a8d 100644
---
a/ratis-common/src/main/java/org/apache/ratis/trace/opentelemetry/OpenTelemetryTraceUtils.java
+++ b/ratis-common/src/main/java/org/apache/ratis/trace/otel/OTelTraceUtils.java
@@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.ratis.trace.opentelemetry;
+package org.apache.ratis.trace.otel;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.context.Context;
@@ -28,8 +28,8 @@ import java.util.Optional;
import java.util.TreeMap;
/** OpenTelemetry-specific helpers. Callers using this class must provide
OpenTelemetry jars. */
-public final class OpenTelemetryTraceUtils {
- private OpenTelemetryTraceUtils() {
+public final class OTelTraceUtils {
+ private OTelTraceUtils() {
}
public static SpanContextProto injectContextToProto(Context context) {
diff --git
a/ratis-server/src/test/java/org/apache/ratis/server/impl/RaftServerImplTracingTests.java
b/ratis-server/src/test/java/org/apache/ratis/server/impl/RaftServerImplTracingTests.java
index db0c466b7..a82d92b11 100644
---
a/ratis-server/src/test/java/org/apache/ratis/server/impl/RaftServerImplTracingTests.java
+++
b/ratis-server/src/test/java/org/apache/ratis/server/impl/RaftServerImplTracingTests.java
@@ -38,12 +38,12 @@ import
org.apache.ratis.protocol.exceptions.ServerNotReadyException;
import org.apache.ratis.server.storage.RaftStorage;
import org.apache.ratis.statemachine.StateMachine;
import org.apache.ratis.statemachine.impl.SimpleStateMachine4Testing;
-import org.apache.ratis.trace.RatisAttributes;
+import org.apache.ratis.trace.otel.OTelRatisAttributes;
import org.apache.ratis.trace.SpanNames;
import org.apache.ratis.trace.TraceConfigKeys;
import org.apache.ratis.trace.TraceServer;
import org.apache.ratis.trace.TraceUtils;
-import org.apache.ratis.trace.opentelemetry.OpenTelemetryTraceUtils;
+import org.apache.ratis.trace.otel.OTelTraceUtils;
import org.apache.ratis.util.JavaUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -109,9 +109,9 @@ public class RaftServerImplTracingTests {
.filter(s -> s.getKind() == SpanKind.INTERNAL &&
s.getName().equals(SpanNames.APPEND_ENTRIES_ASYNC))
.findFirst()
.orElseThrow(() -> new IllegalStateException("Expected INTERNAL span "
+ SpanNames.APPEND_ENTRIES_ASYNC));
- assertEquals("n1",
appendSpan.getAttributes().get(RatisAttributes.MEMBER_ID));
- assertEquals("leader1",
appendSpan.getAttributes().get(RatisAttributes.PEER_ID));
- assertEquals(entriesCount,
appendSpan.getAttributes().get(RatisAttributes.APPEND_ENTRIES_COUNT));
+ assertEquals("n1",
appendSpan.getAttributes().get(OTelRatisAttributes.MEMBER_ID));
+ assertEquals("leader1",
appendSpan.getAttributes().get(OTelRatisAttributes.PEER_ID));
+ assertEquals(entriesCount,
appendSpan.getAttributes().get(OTelRatisAttributes.APPEND_ENTRIES_COUNT));
}
@Test
@@ -183,7 +183,7 @@ public class RaftServerImplTracingTests {
.setSpanKind(SpanKind.CLIENT)
.startSpan();
try {
- return
OpenTelemetryTraceUtils.injectContextToProto(Context.current().with(remoteParent));
+ return
OTelTraceUtils.injectContextToProto(Context.current().with(remoteParent));
} finally {
remoteParent.end();
}
@@ -254,7 +254,7 @@ public class RaftServerImplTracingTests {
.setGroupId(RaftGroupId.randomId())
.setCallId(1L)
.setType(type)
-
.setSpanContext(OpenTelemetryTraceUtils.injectContextToProto(clientContext))
+ .setSpanContext(OTelTraceUtils.injectContextToProto(clientContext))
.build();
} finally {
clientSpan.end();