Why we moved to Application Insights?
This case study explains why the team moved from New Relic to Application Insights, including Azure integration, telemetry features, cost controls and operational learnings.
Why we need to an APM?
Observability is one the significant architectural requirements for all software applications. Application Performance Monitoring (APM) is the key element in observability. We can’t imagine running hassle free operation for modern applications without an APM. Even, it could worsen the situation when you have distributed system to operate. In this article we are going to see the various aspect of APM.
TL;DR Summary:
- Lack of visibility on performance or reliability of an applications/infrastructure?
- Lots of blind spots?
- Client will discover the problem first?
- Only reactive action?
- No proactive action?
- To much time to resolve is longer time application outage or slowdowns?
- High mean time to resolve(MTTR) is bad?
- Customer satisfaction?
- Return of investment?
- High mean time to resolve(MTTR) is bad?
- Lack of holistic view across multiple components?
- Poor collaboration across the departments?
- Poor continuous improvement
Challenges:
Blind Spots:
All software has lots of operation blind spots and we only come know when issues are popping up. These blind spots can spread across all dimensions of operation like performance, reliability of application or infrastructure, security, etc. Client will have direct impact when there is any issue in the system and report to us to fix it and we will take reactive actions to client’s support calls. It reduces our customer experiences, sometimes situation become worser than expect. To avoid these kinds of situation we need to take proactive measures and actions.
Mean time to Resolve (MTTR)
In all business, SLA is important thing to ensure the business continuity of yours and your customer’s business. Mean time to resolve (MTTR) is the one the key reliability indicator to ensure the agreed SLA. When we don’t any observability practices in place then it is very difficult reduce the MTTR since Mean time to detect the issue will take longer time than usual and it will have direct impact on your system availability SLA. This is one of the classical examples for reactive approach. To ensure the SLA, you need to take necessary actions just before it impacting to your customers. A matured APM will help you to achieve it.
Poor/No Feedback
With no observability we can’t track the health of the overall system, since no data or visibility available we don’t what is happening currently in the system and what component or module causing issues. It makes IT ops and Developer life hard since they have zero knowledge on the current state of the system, and it will ripple effect in collaborating with other departments.
Mean time to Detect (MTTD)
Mean time to detect (MTTD) is the average time taken to find out that there is a problem in the system. MTTR always starts with MTTD, we can’t fix a problem which we don’t know about. Without an APM, most of the time our customers detect the problem before us and MTTD becomes the biggest part of the MTTR. A good APM brings the MTTD down from hours to minutes through alerts, health checks and anomaly detection, so that we get enough time to act before our customers notice it.
- Lack of visibility on performance or reliability of an applications/infrastructure?
- Lots of blind spots?
- Client will discover the problem first?
- Only reactive action?
- No proactive action?
- To much time to resolve is longer time application outage or slowdowns?
- High mean time to resolve(MTTR) is bad?
- Customer satisfaction?
- Return of investment?
- High mean time to resolve(MTTR) is bad?
- Lack of holistic view across multiple components?
- Poor collaboration across the departments?
- Poor continuous improvement
What is an APM?
Application performance monitoring (APM) is the monitoring and management of the performance and availability of software applications.
Simply put, application performance management is the art of managing the performance, availability, and user experience of software applications. APM monitors the speed at which transactions are performed both by end-users and by the systems and network infrastructure that support a software application, providing an end-to-end overview of potential bottlenecks and service interruptions
Why APM is important?
In case your application has many components to manage, inclusive of servers, VMs and hosted applications such as application servers, databases, web applications, etc. it is important that you implement a comprehensive app performance management tool. This will help monitor performance issues with applications, keep track of the health and availability of servers, and plan capacity based on incoming requests. Since the diagnosis and identification of issues is faster, troubleshooting is faster which otherwise would cost you valuable business hours and important leads
Why we moved to Application Insights?
Few years ago, we were implemented the New Relic (APM) for a small set of application which was hosted in On-premise. New Relic is well known APM in the market and still they are in the top of the list. It provides end to end monitoring except Real Time User Monitoring (RUM). Over the period we had moved to Application Insights (Microsoft’s APM) due to couple of reasons,
- Pricing model of New Relic
- As we moving to Azure, we were looked for a Native Solution.
TL;DR summary
- New Relic served us well for on-premise applications, but its pricing model was not a good fit when the number of hosts and applications grew.
- As we moved to Azure, we wanted a native APM which works seamlessly with Azure services and our .NET tech stack.
- Application Insights provides end-to-end monitoring, including Real User Monitoring (RUM), which was missing in our New Relic setup.
- Pay-as-you-go pricing based on data ingestion, with a daily cap to control the cost.
- Key features we use are Custom Metrics, Performance, Failures, Profiler, Application Map and RUM.
- Application Insights has its own limitations, we had to define our own best practices for naming, tracing and exception handling to get the most out of it.
Application Insights
Application Insights is an extensible APM service from Microsoft. It supports multiple platforms like .NET, Node.js, Java and JavaScript, and it works for applications hosted in Azure, on-premise or any other cloud. Once we instrument the application with the SDK, it automatically collects requests, dependencies, exceptions, page views and performance counters, and sends them to an Application Insights resource in Azure. We can analyze all this telemetry through the Azure portal or query it using Analytics (Analytics query language).
Key features
Application Insights has lots of features, here are the key features which helped us in our day to day operations.
Custom Metrics
Out of the box metrics are good to understand the health of the system, but they won’t tell us anything about our business. Custom metrics allow us to track business and technical measures which are specific to our application, such as number of orders processed, number of files imported, queue length, etc. We used TrackMetric and GetMetric APIs of the SDK to send custom metrics, and these metrics can be used in charts, dashboards and alerts similar to the standard metrics.
var telemetryClient = new TelemetryClient(TelemetryConfiguration.Active);
telemetryClient.GetMetric("FilesImported").TrackValue(1);
Performance
The Performance blade shows the response time, request count and dependency calls of all operations in one place. We can easily identify the slowest operations and slowest dependencies, and drill down to an individual request to see the end-to-end transaction details. It helped us to compare the performance of the current release with the previous release and find out the operations which are degraded after the deployment.
Failures
The Failures blade shows the failed requests, failed dependencies and exceptions along with the top response codes and exception types. From there, we can drill down to the individual failed request and see the complete stack trace, request properties and the related telemetry of the same operation. This reduced a lot of our time in identifying the root cause, as we don’t have to log in to the servers and search the log files anymore.
Profiler
Application Insights Profiler captures the detailed traces of the requests running in production with minimal overhead. It shows the hot path of the code, where most of the time is spent for a slow request. Profiler helped us to identify the performance issues which are very hard to reproduce in lower environments. Snapshot Debugger, which is a companion feature, captures the state of the local variables when an exception is thrown in production.
Application Map
Application Map visualizes all components of a distributed system and the dependencies between them, with the request count, average response time and failure rate of each call. It gives us a holistic view of the system and we can quickly spot which component or dependency is causing the issue. This was one of the major challenges we discussed earlier, and Application Map solved it to a great extent.
RUM
Real User Monitoring (RUM) was the missing piece in our New Relic implementation. With the Application Insights JavaScript SDK, we can track page views, browser timings, AJAX calls, client-side exceptions and user sessions. It helps us to understand how our users are using the application and their actual experience from the browser, not just from the server side. Server and browser telemetry are correlated, so we can trace a slow page right from the browser to the backend dependency.
Limitations
Application Insights is a great APM tool, but it is not without limitations. Here are some of the limitations we came across.
- Data retention - Raw telemetry is retained for 90 days by default. For longer retention, we have to export the data to a storage account or other data stores.
- Sampling - Adaptive sampling is enabled by default in the ASP.NET SDK to reduce the volume of telemetry. If it is not configured properly, we might miss some of the important requests and exceptions while investigating an issue.
- Cost on high volume - Pricing is based on data ingestion. For high traffic applications, the cost can grow very quickly unless we use sampling, filtering and a daily cap. When the daily cap is reached, the data collection is stopped for the rest of the day.
- Ingestion latency - Telemetry usually takes a few minutes to be available for querying, which is not suitable when we need real-time data. Live Metrics Stream can be used for real-time monitoring, but it doesn’t store any data.
- No out of the box Apdex score - Unlike New Relic, Application Insights doesn’t provide an Apdex score out of the box. We had to calculate it using Analytics queries and Azure dashboards.
- Profiler support - Profiler works well for the applications hosted in Azure App Services, Cloud Services and VMs, but the support is limited for on-premise environments.
Best practices
A good APM tool alone won’t provide better observability. How we instrument our applications is equally important as the tool. Here are some of the best practices we followed.
Naming
- Create a separate Application Insights resource for each environment (Dev, QA, Staging, Production), so that the telemetry of the lower environments won’t mix with the production telemetry.
- Follow a consistent naming convention for the Application Insights resources, for example,
ai-<product>-<environment>. - Set the cloud role name for each component of the system. Application Map, Performance and Failures use the role name to identify the components. Without it, all components will appear as one.
- Use meaningful names for custom events, metrics and operations, so that everyone in the team can understand them without any additional documentation.
public class CloudRoleNameInitializer : ITelemetryInitializer
{
public void Initialize(ITelemetry telemetry)
{
telemetry.Context.Cloud.RoleName = "orders-api";
}
}
Tracing
- Use the existing logging framework (ILogger, log4net, NLog, etc.) with the Application Insights adapters instead of writing traces directly in all places.
- Use the right log level (Verbose, Information, Warning, Error, Critical) and configure the minimum level per environment to control the volume and cost.
- Make sure the correlation context (operation id) is propagated across all components, including background jobs and message queues. It helps us to see the end-to-end transaction across multiple components.
- Add custom properties like customer id, tenant id or correlation id to the telemetry, so that it is easy to filter and search.
- Never log sensitive information like passwords, tokens, or personal data (PII) in the telemetry.
Exception
- Don’t swallow exceptions. If you catch an exception and handle it, track it with enough context before you move on.
- Use a global exception handler to make sure all unhandled exceptions are tracked.
- Add custom properties to the exceptions to make the root cause analysis easier.
- Don’t track expected business validation errors as exceptions, it creates noise and makes the real problems hard to find.
catch (Exception ex)
{
telemetryClient.TrackException(ex, new Dictionary<string, string>
{
["OrderId"] = orderId,
["Operation"] = "SubmitOrder"
});
throw;
}
Our Learnings
- We defined our own best practices for Application Insights implementation, one of the important things was setting the cloud role name for all components, without it Application Map was not useful for our distributed systems.
- Instrumentation is not a one-time activity. We have to review and improve the telemetry continuously as the application evolves.
- Configure sampling, filtering and daily cap from day one, otherwise the cost will surprise you at the end of the month.
- Alerts are only useful when they are actionable. Too many alerts lead to alert fatigue and the team will start ignoring them.
- Build Analytics queries and Azure dashboards for each product, so that Dev, Ops and business teams have the same view of the system health.
- Use deployment annotations from the CI/CD pipeline to correlate the performance changes and failures with the releases.
- Make APM data part of the post-release review and the incident retrospective, it helps the team to continuously improve the system.
Related Posts
How to configure New Relic for Azure Web Apps?
New Relic monitoring for Azure Web Apps explained through site extensions, NuGet installation, agent configuration, app settings, Apdex and alert verification.
How we simplified one of the complex filter pages with Azure Search?
An Azure Search case study showing how a complex filter page moved from dynamic SQL and slow queries to a derived search index and faster filtering.
How to build useful dashboards with Application Insights? Tools, queries and charts - Part 4
The tools, Kusto queries and dashboard charts which make Application Insights data useful, from web transactions to the application map.