Skip to content

Commit

Permalink
Update TracerProviderUtil.java
Browse files Browse the repository at this point in the history
fr > en
  • Loading branch information
skerdudou committed Jun 6, 2024
1 parent 6436784 commit 304a53f
Showing 1 changed file with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,29 @@
import io.vertigo.core.analytics.trace.Tracer;
import io.vertigo.core.lang.Assertion;

/**
* Utility class for providing Tracer instances.
*/
public final class TracerProviderUtil {

private TracerProviderUtil() {
//private
}

/**
* Processus binde sur le thread courant. Le processus , recoit les notifications des sondes placees dans le code de
* l'application pendant le traitement d'une requete (thread).
* Process bound to the current thread. The process receives notifications from probes placed in the application code
* during the processing of a request (thread).
*/
private static final ThreadLocal<Stack<TracerImpl>> THREAD_LOCAL_PROCESS = new ThreadLocal<>();

/**
* Traces the execution of a block of code.
*
* @param category the category of the trace
* @param name the name of the trace
* @param consumer the block of code to trace
* @param onCloseConsumer the action to perform when the trace is closed
*/
public static void trace(final String category, final String name, final Consumer<Tracer> consumer, final Consumer<TraceSpan> onCloseConsumer) {
try (TracerImpl tracer = createTracer(category, name, onCloseConsumer)) {
try {
Expand All @@ -50,6 +61,15 @@ public static void trace(final String category, final String name, final Consume
}
}

/**
* Traces the execution of a block of code and returns a result.
*
* @param category the category of the trace
* @param name the name of the trace
* @param function the block of code to trace
* @param onCloseConsumer the action to perform when the trace is closed
* @return the result of the function
*/
public static <O> O traceWithReturn(final String category, final String name, final Function<Tracer, O> function, final Consumer<TraceSpan> onCloseConsumer) {
try (final TracerImpl tracer = createTracer(category, name, onCloseConsumer)) {
try {
Expand All @@ -63,6 +83,11 @@ public static <O> O traceWithReturn(final String category, final String name, fi
}
}

/**
* Returns the current Tracer instance, if one exists.
*
* @return an Optional containing the current Tracer, or an empty Optional if none exists
*/
public static Optional<Tracer> getCurrentTracer() {
// When collect feature is enabled
return doGetCurrentTracer().map(Function.identity()); // convert impl to api
Expand Down

0 comments on commit 304a53f

Please sign in to comment.