Below is the code for kafka message consumed and published within lmax disruptor ring buffer, now i need to implement tracing for each event may goes through multiple sequence. Before publishing the event i should have the trace or mdc context added to event object, so it will logged in Handlers for tracing for an distributed system.
Create a new dynamic traceid, span and add to event object. So for all sequence the same traceid should propogate.
while (itr.hasNext()) {
ConsumerRecord<String, String> sourceRecord = itr.next();
RingBuffer<Event> ringBuffer = disruptor.getRingBuffer();
long sequence = ringBuffer.next();
Event event = ringBuffer.get(sequence);
event.setExtTriggerTime(LocalDateTimeUtil.getCurrentGMTLocalDateTime());
event.setMessageSource(messageSource());
event.setMessage(source);
event.setSource(this);
event.setFunctionality(functionality());
if (!itr.hasNext()) {
event.setLastMessage(true);
//event.setTrace(UUID)
setLastMessageProcessed(false);
consumer.pause(consumer.assignment());
}
ringBuffer.publish(sequence);
}
Handler :
This is current code, get the traceid from event object and set in MDC context in all handlers. Is there any other implementation to avoid manual coding to set in context and get the traceid in all handlers for the event.
@Override
public void onEvent(final Event event,
final long sequence,
final boolean endOfBatch) {
//Get mdc context from event for logging
MDC.put(event.getTrace())
}
I am looking for reference or solution to implement tracing in lmax ring buffer.