All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aliyun.openservices.shade.io.prometheus.client.exemplars.Tracer Maven / Gradle / Ivy

There is a newer version: 1.9.4.Final
Show newest version
package com.aliyun.openservices.shade.io.prometheus.client.exemplars;

import com.aliyun.openservices.shade.io.prometheus.client.exemplars.tracer.common.SpanContextSupplier;
import com.aliyun.openservices.shade.io.prometheus.client.exemplars.tracer.otel.OpenTelemetrySpanContextSupplier;
import com.aliyun.openservices.shade.io.prometheus.client.exemplars.tracer.otel_agent.OpenTelemetryAgentSpanContextSupplier;

class Tracer {

  ExemplarSampler initExemplarSampler() {
    try {
      Object spanContextSupplier = findSpanContextSupplier();
      if (spanContextSupplier != null) {
        return new DefaultExemplarSampler((SpanContextSupplier) spanContextSupplier);
      }
    } catch (NoClassDefFoundError ignored) {
      // simpleclient_tracer_common dependency not found
    }
    return null;
  }

  // Avoid SpanContextSupplier in the method signature so that we can handle the NoClassDefFoundError
  // even if the user excluded simpleclient_tracer_common from the classpath.
  private Object findSpanContextSupplier() {
    try {
      if (OpenTelemetrySpanContextSupplier.isAvailable()) {
        return new OpenTelemetrySpanContextSupplier();
      }
    } catch (NoClassDefFoundError ignored) {
      // tracer_otel dependency not found
    } catch (UnsupportedClassVersionError ignored) {
      // OpenTelemetry requires Java 8, but client_java might run on Java 6.
    }
    try {
      if (OpenTelemetryAgentSpanContextSupplier.isAvailable()) {
        return new OpenTelemetryAgentSpanContextSupplier();
      }
    } catch (NoClassDefFoundError ignored) {
      // tracer_otel_agent dependency not found
    } catch (UnsupportedClassVersionError ignored) {
      // OpenTelemetry requires Java 8, but client_java might run on Java 6.
    }
    return null;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy