Skip to content

RATIS-2553. Isolate OpenTelemetry tracing dependencies#1478

Merged
szetszwo merged 1 commit into
apache:masterfrom
HTHou:RATIS-2553
Jun 12, 2026
Merged

RATIS-2553. Isolate OpenTelemetry tracing dependencies#1478
szetszwo merged 1 commit into
apache:masterfrom
HTHou:RATIS-2553

Conversation

@HTHou

@HTHou HTHou commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This patch isolates OpenTelemetry-specific tracing code behind a TraceProvider facade. The default tracing path uses a no-op provider, so downstream projects can exclude OpenTelemetry jars without loading OTel classes from the default Ratis tracing path.

OpenTelemetry tracing behavior is preserved when tracing is enabled and the OpenTelemetry jars are available. The patch also removes OpenTelemetry SDK and semantic convention dependencies from the main dependency path and keeps SDK testing dependencies in test scope.

What is the link to the Apache JIRA

https://issues.apache.org/jira/browse/RATIS-2553

How was this patch tested?

  • ./mvnw -pl ratis-common,ratis-server,ratis-test -am test-compile -DskipTests
  • ./mvnw -pl ratis-server -am -Dtest=RaftServerImplTracingTests -DfailIfNoTests=false test
  • ./mvnw -pl ratis-server -am dependency:tree -Dscope=compile -Dincludes=io.opentelemetry,io.opentelemetry.semconv -DskipTests
  • Manually verified with a classpath excluding OpenTelemetry jars that TraceUtils.setTracerWhenEnabled(true) falls back to no-op tracing instead of failing with linkage errors.

@HTHou HTHou marked this pull request as ready for review June 11, 2026 09:23
@szetszwo

szetszwo commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

@HTHou , We do plan to make tracing configurable; see #1341 (comment)

Thanks a lot for starting the work! Will review this soon.

Cc @taklwu

@szetszwo szetszwo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HTHou , thanks for working on this! Please see the comments inlined.

Comment on lines +66 to +70
private static TraceProvider tryNewOpenTelemetryTraceProvider() {
try {
return new OpenTelemetryTraceProvider();
} catch (LinkageError e) {
LOG.warn("OpenTelemetry tracing is enabled but OpenTelemetry is not available; tracing is disabled", e);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's throw an exception instead of fallback:

  private static TraceProvider newOpenTelemetryTraceProvider() {
    try {
      return new OpenTelemetryTraceProvider();
    } catch (Throwable e) {
      throw new IllegalStateException("OpenTelemetry tracing is enabled but OpenTelemetry is not available; tracing is disabled", e);
    }
  }

Comment on lines +37 to +39
public static Tracer getGlobalTracer() {
return GlobalOpenTelemetry.getTracer("org.apache.ratis", VersionInfo.getSoftwareInfoVersion());
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove it since it is only used once.

Comment on lines 58 to 60
public static boolean isEnabled() {
return TRACER.get() != null;
return getProvider().isEnabled();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's check the provider class:

  public static boolean isEnabled() {
    return !(getProvider() instanceof NoOpTraceProvider);
  }

private static final Logger LOG = LoggerFactory.getLogger(OpenTelemetryTraceProvider.class);
private static final String LEADER = "LEADER";

private final Tracer tracer = OpenTelemetryTraceUtils.getGlobalTracer();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check null for tracer:

  private final Tracer tracer = Objects.requireNonNull(
      GlobalOpenTelemetry.getTracer("org.apache.ratis", VersionInfo.getSoftwareInfoVersion()),
      "tracer == null");

import java.util.concurrent.CompletableFuture;

interface TraceProvider {
boolean isEnabled();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove isEnabled().

Comment on lines +165 to +166
@SuppressWarnings("FutureReturnValueIgnored")
private static <T> void addListener(CompletableFuture<T> future,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep the javadoc:

  /**
   * This is method is used when you just want to add a listener to the given future. We will call
   * {@link CompletableFuture#whenComplete(BiConsumer)} to register the {@code action} to the
   * {@code future}. Ignoring the return value of a Future is considered as a bad practice as it may
   * suppress exceptions thrown from the code that completes the future, and this method will catch
   * all the exception thrown from the {@code action} to catch possible code bugs.
   * <p/>
   * And the error phone check will always report FutureReturnValueIgnored because every method in
   * the {@link CompletableFuture} class will return a new {@link CompletableFuture}, so you always
   * have one future that has not been checked. So we introduce this method and add a suppression
   * warnings annotation here.
   */
  @SuppressWarnings("FutureReturnValueIgnored")
  private static <T> void addListener(CompletableFuture<T> future,

* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ratis.trace;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move it to a new package:

package org.apache.ratis.trace.opentelemetry;

* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ratis.trace;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move it to a new package:

package org.apache.ratis.trace.opentelemetry;

Comment on lines -164 to -165
private static final TextMapPropagator PROPAGATOR =
GlobalOpenTelemetry.getPropagators().getTextMapPropagator();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add it back to OpenTelemetryTraceUtils and use it.

@HTHou

HTHou commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

Updated the PR to address the inline review comments:

  • Moved the OpenTelemetry-specific tracing classes under org.apache.ratis.trace.opentelemetry.
  • Removed TraceProvider.isEnabled() and switched TraceUtils.isEnabled() to check the provider type.
  • Changed OpenTelemetry provider initialization to throw IllegalStateException when tracing is enabled but OpenTelemetry is unavailable.
  • Added Objects.requireNonNull(...) for the global tracer, removed the one-use helper, and restored the addListener javadoc.

Also rebased on the latest master and force-pushed the updated single-commit branch.

Verified with:

  • ./mvnw -pl ratis-server -am -Dtest=RaftServerImplTracingTests -DfailIfNoTests=false test

@szetszwo szetszwo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 the change looks good.

@szetszwo szetszwo merged commit 1b7a8ff into apache:master Jun 12, 2026
18 checks passed
@HTHou HTHou deleted the RATIS-2553 branch June 12, 2026 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants