Debugging Microservices Part I: The User-Agent Header

Soner Çökmen
2 min readJan 7, 2019
Debugging Microservices

The microservice architecture brought many complexities along with its advantages. From my point of view, the biggest of these complexities is debugging and tracing.

This tutorial series will show efficient and straightforward ways of simplifying the debugging and tracing of the applications in the microservice architecture.

Here we go…

The User-Agent Header

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 the 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 might be useful.

Here are some problems that I faced at least one time:

  • Some frameworks or libraries may work perfectly in almost all operating systems except the operating system your applications run on.
  • 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 Useful Convention

A standard syntax is 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 pretty simple and efficient. By using this syntax and the additional fields we mentioned above, we can create our user-agent header syntax for our requirements in many ways. But it is essential that all applications should use only one convention that all team members agreed on.

For example;

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.

--

--