io.quarkus.micrometer.runtime.export.exemplars.OpentelemetryExemplarSamplerProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-micrometer Show documentation
Show all versions of quarkus-micrometer Show documentation
Instrument the runtime and your application with dimensional metrics using Micrometer.
package io.quarkus.micrometer.runtime.export.exemplars;
import java.util.Optional;
import java.util.function.Function;
import jakarta.enterprise.inject.Produces;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanContext;
import io.prometheus.client.exemplars.DefaultExemplarSampler;
import io.prometheus.client.exemplars.ExemplarSampler;
import io.prometheus.client.exemplars.tracer.common.SpanContextSupplier;
import io.quarkus.opentelemetry.runtime.QuarkusContextStorage;
public class OpentelemetryExemplarSamplerProvider {
@Produces
public Optional exemplarSampler() {
return Optional.of(new DefaultExemplarSampler(new SpanContextSupplier() {
@Override
public String getTraceId() {
return get(SpanContext::getTraceId);
}
@Override
public String getSpanId() {
return get(SpanContext::getSpanId);
}
@Override
public boolean isSampled() {
return Boolean.TRUE.equals(get(SpanContext::isSampled));
}
private T get(Function valueExtractor) {
return Optional.ofNullable(Span.fromContextOrNull(QuarkusContextStorage.INSTANCE.current()))
.map(Span::getSpanContext)
.map(valueExtractor)
.orElse(null);
}
}));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy