Remove MdcContextLifterConfig.java if you have one.

1. Add dependency in pom.xml

<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>spring-cloud-gcp-starter-trace</artifactId>
</dependency>

or

<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
</dependencies>

2. Add following properties in application.yaml

sleuth:
reactor:
instrumentation-type: DECORATE_QUEUES
enabled: true

below is zipkin relate (optional)

sampler:
probability: 1.0
propagation-keys: x-request-id,x-ot-span-context
propagation:
type: W3C

3. Add following in logbock.yaml

<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>
%d{HH:mm:ss.SSS} [%thread] [%X{traceId:-}] [%X{spanId:-}] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>


<appender name="logstash" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="net.logstash.logback.encoder.LogstashEncoder">
<mdcKeyFieldName>traceId=trace_id</mdcKeyFieldName>
<mdcKeyFieldName>spanId=span_id</mdcKeyFieldName>
</encoder>
</appender>

Example for extract traceId to send in outbox

private final Tracer tracer;

public Flux<OutboxEvent> onWorkflowCloseAndCreateTask(ApprovalFlow workflow, ApprovalStatus status, int closeStepIndex, List<String> approverNos) {
String traceId = resolveNull(() -> tracer.currentSpan().context().traceId()).orElse(shortId());

Flux<OutboxEvent> taskCreate = onWorkflowCreateTask(workflow, traceId);
Flux<OutboxEvent> taskClose = onWorkflowCloseTask(workflow, status, closeStepIndex, approverNos, traceId);
return outboxEventRepository.saveAll(Flux.concat(taskClose, taskCreate));

}

--

--