Application Monitoring: Key Instrumentation to Add
In this article
To effectively monitor a modern application, you need to add instrumentation that captures three core types of telemetry: logs, metrics, and traces (often called the “three pillars” of observability). These should be supplemented with health checks, resource usage reporting, and custom business events. The specific instrumentation you add depends on your stack, but the goal is always the same: to answer what is happening, why it is happening, and what to fix before your users notice a problem.
Why Instrumentation Matters
Instrumentation is the code you add to your application to expose its internal state. Without it, you are effectively operating a black box. You can see inputs and outputs, but not the internal failures, slow queries, or memory leaks that degrade performance. Adding proper instrumentation turns that black box into a series of transparent layers, letting you observe request flows, database calls, and system resource usage in real time.
This is not just about fixing outages. Good instrumentation helps you understand normal behavior, plan capacity, and validate new releases. It also reduces the mean time to resolution (MTTR) when incidents do occur, because you can quickly pinpoint the failing component rather than guessing from user reports.
The Three Pillars: Logs, Metrics, and Traces
These three data types are complementary and together provide a complete picture of application health.
- Logs are discrete events with a timestamp and a message. They are the most detailed, capturing errors, warnings, and informational messages. Example: a line saying “User login failed: invalid password” with a timestamp and user ID.
- Metrics are numeric measurements over time, such as request count, error rate, or CPU usage. They are aggregated and used for dashboards and alerts. Example: a counter that increments on every HTTP 500 response.
- Traces represent the path of a single request through your services, showing each span (operation) with its duration. They are essential for microservices. Example: a trace showing that a request spent 800ms in the database and 200ms in the application code.
Modern observability platforms combine these into a single view, so you can start with a metric alert, drill into a trace, and then read the related logs for the exact error message.
Key Instrumentation to Add
Beyond the three pillars, you should instrument the following specific areas. The list below is a practical starting point for most web applications.
- HTTP endpoints: Record request count, latency (histogram), and error status codes for every route. This is your primary user-facing health signal.
- Database queries: Capture query execution time, number of rows returned, and connection pool usage. Slow queries are a common root cause of performance issues.
- External service calls: For any API you call (payment gateway, third-party service), record duration, success/failure, and retry counts. This helps you distinguish between your problem and theirs.
- Runtime metrics: For JVM, .NET, Node.js, or Python, expose garbage collection pauses, thread counts, event loop lag, and memory heap usage. These often indicate underlying issues before they affect requests.
- Infrastructure metrics: CPU, memory, disk I/O, and network I/O from the host or container. These are usually collected by an agent, but you should ensure they are correlated with application logs.
- Business events: Track meaningful user actions like sign-ups, purchases, or file uploads. This helps you correlate technical issues with business impact (e.g., a spike in failed checkouts).
- Health checks: A dedicated endpoint (e.g.,
/health) that verifies dependencies (database, cache) and returns a status code. This is essential for load balancers and orchestration systems.
How to Choose the Right Instrumentation
You do not need to add everything at once. Start with the “RED” method for services (Rate, Errors, Duration) and the “USE” method for resources (Utilization, Saturation, Errors). These two frameworks cover the most critical signals.
- Identify critical paths: What are the top three user journeys? Instrument those first.
- Use auto-instrumentation: Most APM tools (e.g., OpenTelemetry, Datadog, New Relic) provide agents that automatically capture HTTP calls, database queries, and runtime metrics with minimal code changes.
- Add manual instrumentation for business logic: For custom algorithms or complex workflows, add spans and metrics manually to get context that auto-instrumentation cannot infer.
- Define alert thresholds: Instrumentation is useless if you do not act on it. Set alerts for error rate above 1%, p95 latency above 500ms, or CPU above 80% for 5 minutes.
Common Instrumentation Mistakes
Even with the right tools, teams often make mistakes that reduce the value of their telemetry.
- Too much data: Logging every line of code or capturing high-cardinality metrics (e.g., including user IDs in metric tags) can overwhelm your storage and make queries slow. Sample or aggregate where possible.
- No correlation IDs: If you do not include a request ID in logs, traces, and metrics, you cannot connect them. Always propagate a trace ID across services.
- Ignoring the “why”: Metrics tell you something is wrong, but not why. You need traces and logs to get the full story. Invest in all three.
- Not testing instrumentation: Instrumentation is code. It can fail, be misconfigured, or add overhead. Test that your telemetry is actually being generated and received.
OpenTelemetry vs. Vendor-Specific Agents
A common question is whether to use OpenTelemetry (OTel) or a vendor’s proprietary agent. OpenTelemetry is an open-source standard for generating and collecting telemetry. It provides SDKs and agents for many languages, and it sends data to any backend that supports the OTLP protocol. Vendor agents (e.g., Datadog, Dynatrace) are often easier to set up and offer deeper integration with that vendor’s UI, but they lock you into that ecosystem.
For new projects, OpenTelemetry is the safer long-term choice because it is vendor-neutral. You can start with a free backend like Jaeger or Prometheus, and later switch to a commercial platform without changing your instrumentation code. For existing projects where you already use a vendor, their agent is often the fastest path to value.
Cost and Overhead Considerations
Instrumentation is not free. It consumes CPU, memory, and network bandwidth, and the storage for logs and traces can be expensive at scale. To manage this, you should:
- Use sampling: For traces, keep 100% of errors but only 10% of successful requests. This preserves detail for failures while controlling volume.
- Set log levels: Use DEBUG in development, but INFO in production. Avoid logging sensitive data like passwords or credit card numbers.
- Retention policies: Keep raw data for 30 days, and aggregated metrics for 13 months. This balances cost with the need for historical comparison.
Many observability platforms charge by data volume, so being selective about what you send is both a technical and financial decision.
Frequently Asked Questions
What is the difference between instrumentation and monitoring?
Instrumentation is the code that generates telemetry data, while monitoring is the process of collecting, visualizing, and alerting on that data. You need instrumentation before you can monitor; monitoring tools consume the output of instrumentation.
Can I use logs alone for application monitoring?
Logs alone are insufficient for modern distributed systems. They lack the structured timing information of traces and the aggregated view of metrics. You can use logs for simple applications, but for anything with multiple services, you need traces to follow a request’s path and metrics to alert on trends.
How do I instrument a legacy application that I cannot modify?
You can use a sidecar proxy or an agent that intercepts network traffic (e.g., a service mesh like Istio) to capture request-level metrics and traces without changing your application code. For runtime metrics, you can often use OS-level tools like Prometheus exporters. This gives you basic visibility, though you will miss business-specific events.
What is a health check endpoint, and why do I need it?
A health check endpoint is a simple HTTP route (like /health) that returns a 200 status when the application is healthy and a 503 when it is not. It is used by load balancers to route traffic away from unhealthy instances and by orchestration systems to restart failing containers. It should verify critical dependencies, but not perform expensive checks on every call.
How much overhead does instrumentation add?
Well-designed instrumentation adds less than 5% overhead to CPU and memory in most cases. Poorly designed instrumentation (e.g., logging every line, or using blocking I/O for telemetry) can add 20% or more. Use async exporters and sample aggressively to keep overhead minimal.