The microservice architecture brought many complexities along with its advantages. In my point of view, the biggest of these complexities is debugging and tracing.
In this tutorial series, I will show simple and efficient ways for simplifying the debugging and tracing of the applications in the microservice architecture.
Here we go…
We are all familiar with the user-agent header. According to MDN documents,
The User-Agent request header contains a characteristic string that allows the network protocol peers to identify the application type, operating system, software vendor or software version of the requesting software user agent.
The purpose of the user-agent header is simple. Identifying the client. Therefore, we can use the user-agent header to identify the client applications in the microservice architecture. This use complies with HTTP standard and simplifies the debugging and tracing of our applications.
The content of the header may vary according to your business requirements. For example, if your application is distributed across many logical regions, then passing the region info to the user-agent header may be meaningful for this case.
In most cases, it is sufficient to use the following fields in the user-agent header:
- the name of the application.
- the version of the application.
But real-world problems showed me that a few extra areas may be useful.
Here are some problems that I faced at least one time:
- Some frameworks or libraries may work perfect almost all operating systems except the operating system that your applications run on it.
- Some machines or containers may be misconfigured or may be faulty.
Therefore, I strongly recommend adding the following fields to the user-agent header:
- Host operating system.
- Machine or container name.
A standard syntax also defined for the user-agent header in MDN documents.
User-Agent: <product> / <product-version> <comment>
As a developer, I like this syntax. It is quite simple and efficient. By using this syntax and additional fields we mention above, we can create own user-agent header syntax for our requirements in many ways. But it is important that all applications should use only one convention that all team members agreed on.
User-Agent: <product> / <product-version> (<os-name>) <container>
And here is a sample output of syntax above;
User-Agent: awesome-api/1.0.2 (alpine-node) awesome-api-6878685746
Do you have a user-agent header convention that you use in your company? Feel free to share. Thanks.
Hello there, I'm on Medium as well. Check it out here