Instrumenting web applications

Web applications are different from mobile and desktop applications in many ways—for instance, the fact that large parts of the application do not run on a client, but on a server. This allows developers to collect information on how the application is run for web applications more easily than for other types of applications. Doing so is called instrumenting an application.

Logs are text messages that are saved by the system to describe the execution path that the server follows. This helps developers go back in time and explore what has happened by examining the logging output. Structured logging is quickly becoming the standard for trace logging. Structured logging is a technique where logs are no longer only text messages. Instead, logs are parameterized text messages with a set of values for each parameter. This has two advantages—logs can be better compressed and they can be searched more quickly.

Metrics are values that are recorded for an application. They take the form of a timestamp, metric name, and value. One example is recording the percentage of CPU in use every second.

When instrumenting an application, it is easy to focus on many server-level types of logs and metrics. For example, many operators will, by default, start collecting metrics such as CPU usage, memory pressure, and I/O operations. While there is nothing wrong with these metrics, they are not always indicative of an application's performance from a user's point of view. Other metrics, such as response times or queue message processing delays, might yield better insights into the user experience. While there is nothing wrong with measuring system metrics (they are often great indicators of future issues), you should also try to gather user-centric metrics.

Azure offers the Application Insights service for instrumenting applications, with a focus on web applications. An Application Insights workspace can be created using the Azure portal, which opens up a workspace as in the following screenshot. One of the important things here is Instrumentation Key, which will be used in later sections. Even though this field is plainly shown, it is recommended that you treat this as an application secret:

If you want to experiment with Application Insights and Azure Monitor using a ready-made application, there is a link to an example at the end of this chapter in the Further reading section. The example is a simple URL shortning application that uses multiple application components and has logging and monitoring built-in and can be used to start experimenting with the concepts introduced in this section within minutes.

The following subsections will go into detail about logging, metrics, and investigating individual requests.

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

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