Handle logging in different locations and from different languages

Debugging always starts from logging. Due to a large number of microservices running in the system, if any problems occur in the system, the developer wants to dig in. However, as there are so many log files of different components, finding one call trace from this big data is not easy is rather time consuming. The solution to this problem is to use log-aggregation tools such as log stash with Kibana. Both of them are open source tools. Another example is Loggly, which is cloud-based log aggregator tool. Logstash collects the log file in one place, and Kibana allows you to search inside the logs. Both of the mentioned tools are explained in Chapter 9, Monitoring and Scaling. The problem is not always in the component; it can be in the supporting tool. Like Java service running in JVM, but someone has given very low RAM to JVM, which, in turn, slows down the processing of your component as JVM is frequently busy garbage collecting.

Another problem to handle is log format. All components should agree to one format. Normally, in these cases, all components start emitting the logs in a well-defined JSON format, which makes querying on the logs easy. It is more like storing data in Elasticsearch as JSON and querying over it, which makes it pretty fast. Loggly, a cloud-based log aggregator, supports the JSON-based logged. It also has a nice interface to show logs by tag or in a particular time frame, and so on.

Even though we have aggregated the logs, tracing a client call inside the platform is still an issue. If one service issues an API call to the next component, and that leads to another one, and so, on then it is very hard to understand what happens to a particular call in the next component. How can a developer figure out about one particular request and what happens to it? Flow ID/Composition ID/Correlation ID, whatever you may call it, this unique ID attaches to each call platform in the first place and that gets passed across calls, which allows you to track each request. This ID is attached per request initiated. This requires some effort in coding. One has to generate it and log it every time, and then pass it to another microservice; but it is a trade-off. This gives an overall picture of what is happening to a particular request. For any debugging, this can be a very good starting point.

Many commercial software packages, for example, Microsoft SharePoint, are using this pattern to help with problem solving.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset