Skip to content

APM: application performance monitoring in production

B2Bnetwork team · · 6 min

System performance

In brief

APM (application performance monitoring) is a class of tools that measure, in production, the time of every request across all services, the database and external systems, and show where that time goes. A good APM rollout consists of service instrumentation (today most often through OpenTelemetry), trace sampling that keeps slow and failed requests, measurement in the user's browser, alerts based on SLOs instead of CPU, and control over data cost. Without it, the team learns about slowdowns from customers.

What APM shows that server metrics do not

Server metrics tell you CPU is at 40% and memory at 70%. They do not tell you why a payment takes four seconds today instead of one. APM answers the second question because it looks from the request's point of view:

APM featureWhat it showsExample question
Distributed tracesthe request's path through services, with the time of each stepwhich service made the payment slower?
Service mapdependencies and their latency, built from traceswhat does the scoring system call, and how fast?
Database queriesthe slowest and most frequent queries, with calls per requestis the customer screen running 300 queries?
Errorsexceptions linked to the request and the application versionsince which deployment have errors been rising?
Real user monitoring (RUM)load and interaction times in the customer's browserdoes the problem affect only one browser or region?
Synthetic testsa robot walking through a journey on a scheduledoes login work at three in the morning?

The theory of logs, metrics and traces is covered in Observability. Here we deal with how to build APM that helps in day-to-day production work.

Instrumentation: vendor agent or OpenTelemetry

APM data is collected by instrumentation inside the application: an agent that automatically measures HTTP calls, database queries and messages, plus manually added measurements for important business operations. There are two routes:

  • The APM vendor's agent. A quick start and deep integration with the dashboard, but the data is in the vendor's format, and changing tools means replacing agents in every service.
  • OpenTelemetry. An open standard for instrumentation and data transport. Services send data to a collector, and the collector forwards it to the chosen tool, commercial or open source. Changing tools means changing the collector configuration, not the code.

Most APM vendors now accept data in the OpenTelemetry format, so for new systems it is a sensible default. The trace context passed between services in HTTP headers is defined by the W3C Trace Context standard. The standard itself is covered in OpenTelemetry.

Sampling and data cost

APM that stores every request from every service quickly becomes the most expensive system in the company. Cost usually depends on the number of monitored hosts or services, the volume of ingested data and retention time. That is why traces are sampled:

  1. Head sampling decides at the first service whether a trace will be kept, for example 10% of requests. It is cheap, but it can lose a rare slow request.
  2. Tail sampling decides after the whole trace is collected. It lets you keep all errors and all requests above a time threshold, and only a sample of the rest. It needs a collector that holds traces in memory for a while.
  3. Metrics from all requests, traces from a sample. Response time percentiles and error rates are calculated from complete data, and traces are used to explain the cause.

Add policies on top: shorter retention for detailed traces, longer for metrics, limits on attributes and logs per request. How to allocate monitoring cost to teams is covered in FinOps.

Alerts: from SLOs, not from CPU

The most common mistake after rolling out APM is alerting on everything: CPU above 80%, memory, thread count. The team receives dozens of notifications, most of which mean nothing to customers. Alerts based on service level objectives (SLOs) work better: the share of successful requests and the share of requests faster than a threshold, calculated for the most important journeys.

An alert fires when the error budget burns faster than the objective allows, meaning when customers really feel the problem. Resource metrics stay on the dashboard for diagnosis, not as a source of notifications. How to set SLOs and an error budget is covered in SLOs and error budgets.

Where to start: a plan for the first weeks

  1. Pick three to five key business journeys, for example login, search, payment.
  2. Instrument the services on those journeys, with automatic HTTP, database and message measurement plus business attributes (operation type, channel, no personal data).
  3. Set up sampling that keeps errors and slow requests.
  4. Build one dashboard per journey: traffic, errors, response time percentiles, saturation.
  5. Define SLOs and alerts for those journeys.
  6. Mark deployments in APM so you can immediately see whether a new version changed response times.
  7. Use the same APM in performance tests, so test and production results can be compared.

Watch out for personal data: trace attributes, query parameters and error messages can contain national ID numbers, email addresses or account numbers. Masking is configured in the instrumentation or the collector, before the data leaves the company. When APM points to a service but not to a specific piece of code, the next step is covered in Profiling applications in production.

An example of a platform with observability and SLOs for payment operations is the case study A cloud platform and DevOps for a payments fintech. Monitoring is part of the platform B2Bnetwork builds as part of its Platform and DevOps service.

Questions and answers

How does APM differ from observability?

APM is a category of tools focused on application performance: traces, timings, errors and user experience. Observability is a broader property of a system: the ability to answer new questions about its state from logs, metrics and traces. Good APM is one element of observability, but it does not cover all of it.

How much does APM cost?

It depends on the tool's pricing model: number of hosts or services, data volume, number of dashboard users and retention time. Trace sampling and log volume have the biggest effect on the bill. Before choosing a tool, calculate the data volume from one service and multiply it by the target number of services.

Does APM slow down the application?

Instrumentation adds overhead, usually small with a sensible configuration. It grows when you measure every method in the code, store large attributes or send data synchronously. Measure the overhead in a performance test: the same test with and without instrumentation shows the difference for your system.

Is APM enough without performance testing?

No. APM shows what happens at today's traffic. A performance test shows what will happen at traffic you have not seen yet: at peak, after a migration, after a new campaign. The two complement each other, and using the same APM in testing and production makes results easier to compare.

What it looks like in a project

Your system slows down under load? We'll find where it loses time.

Let's talk

Read more: System performance

All in System performance →