Instrumenting asynchronous code
Using messaging between services is not the only way to implement asynchronous applications. Sometimes, the code within a single service is asynchronous. In environments like Node.js, it is the standard way of writing code and requires a different style of in-process context propagation.
In Java, the asynchronous code is often written with the use of futures and executors. In our Tracing Talk application, we have already used those APIs, only in the synchronous manner. For example, the KafkaService.sendMessage()
method calls the send()
function, which returns ListenableFuture
, a sign of the asynchronous API. We turn it back to synchronous by calling get()
and blocking until it is completed:
public void sendMessage(Message ...
Get Mastering Distributed Tracing now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.