io.prometheus.metrics.tracer.initializer.SpanContextSupplier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jmx_prometheus_httpserver Show documentation
Show all versions of jmx_prometheus_httpserver Show documentation
See https://github.com/prometheus/jmx_exporter/blob/master/README.md
package io.prometheus.metrics.tracer.initializer;
import io.prometheus.metrics.tracer.common.SpanContext;
import io.prometheus.metrics.tracer.otel.OpenTelemetrySpanContext;
import io.prometheus.metrics.tracer.otel_agent.OpenTelemetryAgentSpanContext;
import java.util.concurrent.atomic.AtomicReference;
public class SpanContextSupplier {
private static final AtomicReference spanContextRef = new AtomicReference();
public static void setSpanContext(SpanContext spanContext) {
spanContextRef.set(spanContext);
}
public static boolean hasSpanContext() {
return getSpanContext() != null;
}
public static SpanContext getSpanContext() {
return spanContextRef.get();
}
static {
try {
if (OpenTelemetrySpanContext.isAvailable()) {
spanContextRef.set(new OpenTelemetrySpanContext());
}
} 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 (OpenTelemetryAgentSpanContext.isAvailable()) {
spanContextRef.set(new OpenTelemetryAgentSpanContext());
}
} catch (NoClassDefFoundError ignored) {
// tracer_otel_agent dependency not found
} catch (UnsupportedClassVersionError ignored) {
// OpenTelemetry requires Java 8, but client_java might run on Java 6.
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy