Class TraceKit
java.lang.Object
com.iohao.net.common.kit.trace.TraceKit
Distributed tracing utilities using SLF4J MDC for trace ID propagation.
- Author:
- 渔民小镇
- date:
- 2023-12-20
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic RunnableDecorate aRunnableso that the given trace ID is set in MDC during its execution.static <T> Consumer<T> Decorate aConsumerso that the given trace ID is set in MDC during its execution.static StringGet the current trace ID from the SLF4J MDC context.static StringGenerate a new trace ID using the configuredTraceIdSupplier.static org.slf4j.MDC.MDCCloseableputCloseable(String traceId) Put the given trace ID into the MDC context, returning a closeable handle that removes it when closed.static voidsetTraceIdSupplier(TraceIdSupplier traceIdSupplier)
-
Field Details
-
traceName
-
-
Method Details
-
newTraceId
Generate a new trace ID using the configuredTraceIdSupplier.- Returns:
- a new trace ID string
-
getTraceId
Get the current trace ID from the SLF4J MDC context.- Returns:
- the current trace ID, or
nullif none is set
-
putCloseable
Put the given trace ID into the MDC context, returning a closeable handle that removes it when closed.- Parameters:
traceId- the trace ID to set- Returns:
- a closeable that removes the trace ID from MDC on close
-
decorator
Decorate aRunnableso that the given trace ID is set in MDC during its execution.- Parameters:
traceId- the trace ID to propagatecommand- the runnable to decorate- Returns:
- a new runnable that sets and clears the trace ID around execution
-
decorator
Decorate aConsumerso that the given trace ID is set in MDC during its execution.- Type Parameters:
T- the type of the consumer input- Parameters:
traceId- the trace ID to propagateaction- the consumer to decorate- Returns:
- a new consumer that sets and clears the trace ID around execution
-
setTraceIdSupplier
-