chore: Added trace and span info to context (#32399)
This commit is contained in:
parent
57b62797ff
commit
9571ff0f7b
|
|
@ -2,6 +2,8 @@ package com.appsmith.server.configurations;
|
|||
|
||||
import com.appsmith.server.filters.MDCFilter;
|
||||
import com.appsmith.server.helpers.LogHelper;
|
||||
import io.micrometer.observation.Observation;
|
||||
import io.micrometer.tracing.handler.TracingObservationHandler;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.annotation.PreDestroy;
|
||||
import org.reactivestreams.Subscription;
|
||||
|
|
@ -13,11 +15,15 @@ import reactor.core.publisher.Operators;
|
|||
import reactor.util.context.Context;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@Configuration
|
||||
public class MDCConfig {
|
||||
|
||||
private static final String MDC_CONTEXT_REACTOR_KEY = "MDCConfig";
|
||||
private static final String OBSERVATION = "micrometer.observation";
|
||||
private static final String TRACE_ID = "traceId";
|
||||
private static final String SPAN_ID = "spanId";
|
||||
|
||||
@PostConstruct
|
||||
void contextOperatorHook() {
|
||||
|
|
@ -78,6 +84,15 @@ public class MDCConfig {
|
|||
Map<String, String> map = context.get(LogHelper.CONTEXT_MAP);
|
||||
|
||||
map.put(MDCFilter.THREAD, Thread.currentThread().getName());
|
||||
Optional<Observation> observationOptional = context.getOrEmpty(OBSERVATION);
|
||||
observationOptional.ifPresent(observation -> {
|
||||
TracingObservationHandler.TracingContext tracingContext =
|
||||
observation.getContext().get(TracingObservationHandler.TracingContext.class);
|
||||
if (tracingContext != null && tracingContext.getSpan() != null) {
|
||||
map.put(TRACE_ID, tracingContext.getSpan().context().traceId());
|
||||
map.put(SPAN_ID, tracingContext.getSpan().context().spanId());
|
||||
}
|
||||
});
|
||||
MDC.setContextMap(map);
|
||||
} else {
|
||||
MDC.clear();
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user