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

network.oxalis.ng.commons.tracing.SpanManagerImpl Maven / Gradle / Ivy

Go to download

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