network.oxalis.ng.commons.tracing.SpanManagerImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of oxalis-ng-commons Show documentation
Show all versions of oxalis-ng-commons Show documentation
Holds the stuff which is common for both inbound and outbound messages and should be shared between them.
The newest version!
package network.oxalis.ng.commons.tracing;
import com.google.inject.Inject;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
import network.oxalis.ng.commons.util.ClosableSpan;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
public class SpanManagerImpl implements SpanManager {
@Inject
private Tracer tracer;
public T runWithinSpan(String spanName, Function function) {
if (spanName == null) {
throw new IllegalStateException("spanName needs to be set");
}
Span span = tracer.spanBuilder(spanName).startSpan();
try {
return function.apply(span);
} finally {
span.end();
}
}
public ClosableSpan startClosableSpan(String spanName) {
return tracer.spanBuilder(spanName).startSpan()::end;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy