Azure Application Insights — How not to burn money using it (2024)

Azure Application Insights — How not to burn money using it (2)

As Developers, we tend to take things for granted. Especially when it comes to Cloud Services. They make everything seem so easy, you’d be forgiven for taking things for granted. In this blog post, I’m going to talk about Azure Application Insights and how I learned not to take certain things for granted — the hard way.

Disclaimer: I’m only going to be talking about monitoring Azure Functions, specifically using Node.js. I can’t say much about monitoring VMs or other services.

In Microsofts own words:

Application Insights, a feature of Azure Monitor, is an extensible Application Performance Management (APM) service for developers and DevOps professionals.

It basically allows you to monitor your applications during and after development for performance, exceptions and a lot of other things. It also stores the data, allows you to run queries over the data and get alerts.

If you’re interested, definitely check out the Microsoft Docs to learn more!

Like with most Cloud Services, the costs for Application Insights come from the data that’s ingested and stored. In the Azure Portal, Microsoft says that for every ingested Gigabyte of data they charge 1.94€ (or ~2.24$). That’s not cheap! If your app generates a Gigabyte of data per day (which isn’t unrealistic if you get a lot of traffic), that would set you back 60€ (or ~69.33$). Per month 😱 60€ per month and we haven’t even brought value to our users yet.

Azure Application Insights — How not to burn money using it (3)

For September 2021, Application Insights (aka Log Analytics) made up over 80% of the total cost of my app. Running my app like this is not profitable at all.

Let’s see how this came to be.

In the image above, you can see the cost overview for Application Insights of an app I developed. The chart on the right shows how much data was ingested on any given day. It also shows how much data of each type was ingested. remoteDependency and metric are the largest. remoteDependency metrics get collected when you access other Azure services, in this case it’s a Storage Account. Unfortunately, I’m still unsure what falls under metric .

You can also see the sudden explosion of ingested data (from 100 MB per day to over 500 MB). On those days, the requests per day jumped from 13.000 to over 80.000 🤯 That increase didn’t come from a bug in our code but because actual usage of the app increased.

I felt kind of helpless. The Azure Portal doesn’t provide any obvious way to change what gets ingested into Application Insights. So, let’s look at our options.

There are a couple of ways to reduce the costs, some work well others not so well. We’re going to look at them regardless.

Option #1: Using host.json (okay-ish)

This option is also known as “Codeless monitoring”or “Agent-based monitoring”. Basically, you let the Function Runtime (the Agent) do its magic. This option has the least flexibility in my opinion.

Every Azure Function App has a host.json file. The host.json file contains settings that affect all Functions in an Azure Function App (see Microsoft Docs). It has some options regarding Application Insights.

The most notable ones being:

  • logging.applicationInsights.samplingSettings
  • logging.logLevel

So I ended up with a host.json that looked something like this

What did I do?

  • I disabled Live Metrics (which are actually free but I don’t use them), Dependency Tracking and Performance Counters
  • I set Log Levels
  • I didn’t mess with any of the sampling settings (I didn’t have a lot of time playing with the settings and also because of this article).

What drawbacks does this have?
TL;DR: The reduction of costs wasn’t that great.

The largest chunk of data was still metric. At least the performance and remoteDependency metrics got disabled. Also, setting the Log Level for Function to "Error" causes only failed requests to show up within Application Insights, so you won’t actually know how many requests are made.

Azure Application Insights — How not to burn money using it (4)

Option #2: Application Insights SDK (great)

This option is also known as “Code-based monitoring”. You use the Application Insights SDK manually in your Azure Functions (or any other code for that matter). This gives us maximum flexibility but comes with a few code changes.

Step 1: Disable Agent-based monitoring
If you’ve enabled Agent-based monitoring, you have to disable it manually (either in the Azure Portal or in your Infrastructure-as-Code). To do that, you have to rename (or remove if you don’t want to use it at all) the APPINSIGHTS_INSTRUMENTATIONKEY App Settings in the Configuration section of your Function App

Azure Application Insights — How not to burn money using it (5)

I renamed mine to APP_INSIGHTS_KEY . Don’t forget to save the settings. After that, Application Insights will be disabled for the Function App which you can see in the Application Insights section.

Azure Application Insights — How not to burn money using it (6)

Note: Toggling the Enabled button in the Application Insights section will not work. You have to rename or remove the App setting for Application Insights to be disabled.

Step 2: Install Application Insights SDK
I’m using Node.js for our Azure Functions, so installing the SDK is as simple as executing npm install -S applicationinsights . The installation might differ if you’re not using Node.js. Follow the Microsoft Docs to get started for the Language you’re using.

Step 3: Setup Application Insights SDK
There are a couple ways to set this up. The way I did it is the simplest, if you have a lot of Functions and requires the least amount of code change.

This is the initial folder structure:

Azure Application Insights — How not to burn money using it (7)

Pretty standard. index.ts contains the Function code and index.spec.ts contains the unit tests. Now, if you look at the “Azure Function Example” in the GitHub repo for the Application Insights Node.js SDK, you’ll notice that those changes would a) be a nightmare to do for multiple Functions and b) would mean that we can no longer easily test our Function code. Also, maintaining the config for the Application Insights SDK in multiple places would definitely not be DRY 😉

So I ended up writing a wrapper that I could just pass my Function into.

I renamed the index.ts to func.ts and added a new index.ts. Don’t forget to update the imports.

I can also tell you from experience, that you don’t want to try naming them function.ts so you don’t spend an hour debugging your tests. You can probably figure out why.

So the folder structure now looks like this:

Azure Application Insights — How not to burn money using it (8)

I wrote two wrappers. One for HTTP triggered Functions and one for the rest of the triggers. I added comments so you can just check out the code below:

With the wrapper in place, we just need to populate each index.tsfile with the same code and we’re done. Keep in mind that you have full control over how the wrapper looks and what you enable or disable in the Application Insights SDK.

This is what the index.ts now looks like:

That’s it. If you deploy your Function App, you can see the changes in action.

The amount of ingested data in my app is now so little, that I’ll have to show another chart to actually see how much it is:

Azure Application Insights — How not to burn money using it (9)

One might get the impression that there’s a lot of metrics missing (or that it’s not working). But so far, I haven’t noticed any missing metrics.

Using the Application Insights SDK sounded scary at first, but I think my wrapper turned out quite well. Now, all of this obviously depends on your needs (and budget). In my case, the application is very much driven by cost. The cost for Application Insights as it is just doesn’t fit in my budget. Maybe you might be able to get away with what can be configured in the host.json file.

I hope you enjoyed this post. If you have suggestions or questions, hit me up! Cheers!

Azure Application Insights — How not to burn money using it (2024)

FAQs

How to reduce application insights cost? ›

Application Insights includes the following design considerations for cost optimization:
  1. Consider using sampling to reduce the amount of data that's sent: ...
  2. Consider turning off collection for unneeded modules: ...
  3. Consider limiting Asynchronous JavaScript and XML (AJAX) call tracing:
Nov 14, 2023

Does application insights cost money in Azure? ›

Application Insights is not a totally free service. Application Insights cost is normally very low and you can monitor it by going on the Azure Portal, select your instance and then in the Configure section select Usage and estimated costs.

How do I save money on Azure App Service? ›

Quick tips to reduce Azure App Service Cost
  1. Right size Azure App Service. ...
  2. Audit the unused resources. ...
  3. Find the alternative within same pricing tier. ...
  4. Auto scale resources based on demand. ...
  5. Beware of the associated cost. ...
  6. Consider Reservation for long-time commitments.
Feb 8, 2024

Does stopping an Azure App Service save money? ›

Re: Cost saving on App Service plan

You are still getting charged, even when the App Service Plan is stopped. The only way to avoid costs is to scale down to the "Free Tier".

What is the best practice of application insights? ›

Best Practice: Setting Up Alerts and Notifications

In Azure Application Insights, setting up alerts for key performance metrics and error conditions is a best practice. These alerts can trigger notifications or automated actions, ensuring immediate attention to critical issues.

Can you turn off application insights? ›

To resolve this issue, remove or disable Application Insights from your application. To remove the Application Insights Site Extension: Remove all settings related to Application Insights from Application > Settings > Application Settings and Save.

Why would you use Azure application Insights? ›

Application Insights collects telemetry about your app, including web server telemetry, web page telemetry, and performance counters. This data can be used to monitor your app's performance, health, and usage. You can select the location when you create a new Application Insights resource.

Why does Azure cost so much? ›

Scale and performance needs: Higher-tier services for better performance and increased scalability come with higher costs. For businesses requiring high-performance computing, large-scale storage, or extensive data processing capabilities, Azure can be costly.

Do application insights affect performance? ›

The Application Insights SDK and instrumentation is designed to be extremely lightweight and have minimal impact on the performance of your application.

How do I use Azure without paying? ›

When you create your Azure free account, you start getting monthly free amounts of certain types of services. If you move to pay-as-you-go pricing within 30 days or after you've used your credit, you'll continue to receive monthly free amounts of popular services until 12 months after you created your account.

How to make Azure cheaper? ›

Buy an Azure savings plan to save money on a variety of compute services. Buy reserved virtual machine instances to save money over pay-as-you-go costs. Optimize virtual machine spend by resizing or shutting down underutilized instances. Use Standard Storage to store Managed Disks snapshots.

How do I reduce my Azure bill? ›

8 ways to optimize costs today
  1. Shut down unused resources. Identify idle virtual machines (VMs), ExpressRoute circuits, and other resources with Azure Advisor. ...
  2. Right-size underused resources. ...
  3. Add an Azure savings plan for compute for dynamic workloads. ...
  4. Reserve instances for consistent workloads.

How does Azure save money? ›

Add an Azure savings plan for compute for dynamic workloads

Save up to 65 percent off pay-as-you-go pricing when you commit to spend a fixed hourly amount on compute services for one or three years.

Does shutting down Azure VM save money? ›

Use Auto-Shutdown

If you have VMs that are only needed during certain hours of the day, consider using Auto-Shutdown to save money. Auto-Shutdown is a feature that allows you to automatically shut down VMs at a specified time each day. By shutting down VMs when they're not in use, you can save money on VM costs.

Which five factors affect the cost of an app service? ›

In this post, we will help you identify 6 of the top key factors that can affect the cost of app development in 2023.
  • Type & Size of The App.
  • Platforms & Devices.
  • Location & Structure of The Development Team.
  • Design.
  • Features & Functionality.
  • Cost Of Maintenance & Marketing.
Feb 14, 2023

How can log analytics reduce cost? ›

One of the easiest ways to reduce your data ingestion costs is to monitor only what you need and avoid collecting unnecessary or redundant data. For example, you can use filters, sampling, or custom fields to reduce the amount of data that you send from your applications or resources to a Log Analytics Workspace.

How to reduce app engine cost? ›

To limit the costs of your App Engine app, you can use any of the following mechanisms:
  1. Specify the maximum number of instances.
  2. Create budget alerts.
  3. Disable your app manually.
  4. Disable your app programmatically.

How do I reduce telemetry traffic in app Insights? ›

Sampling is a feature in Application Insights. It's the recommended way to reduce telemetry traffic, data costs, and storage costs, while preserving a statistically correct analysis of application data. Sampling also helps you avoid Application Insights throttling your telemetry.

How do I lower my Azure cost? ›

8 ways to optimize costs today
  1. Shut down unused resources. Identify idle virtual machines (VMs), ExpressRoute circuits, and other resources with Azure Advisor. ...
  2. Right-size underused resources. ...
  3. Add an Azure savings plan for compute for dynamic workloads. ...
  4. Reserve instances for consistent workloads.

Top Articles
The nose knows: Where does the smell of rust come from?
Challenges associated with the QA engineer role | quality engineer career
Pikes Suwanee
Fbsm St Louis
Christine Paduch Howell Nj
Christine Paduch Howell Nj
Woman who fled Saudi Arabia reaches her new home in Canada
Pjstar Obits Legacy
Frivlegends.com Unblocked
Indianapolis Star Obituary
Loss Payee And Lienholder Addresses And Contact Information Updated Daily Free List Bank Of America
Argus911
Die eID-Karte für Bürgerinnen und Bürger der EU und des EWR
Michelle_Barbelle
Snohomish Hairmasters
Best Pizza In Westlake
Shadow Under The Mountain Skyrim
Oviedo Anonib
Sprinter Tyrone's Unblocked Games
Craigs List Rochester
Southern Food Buffet Near Me
2068032104
Sevierville, Tennessee: Idyllisches Reiseziel in den Great Smoky Mountains
Will Certifier Crossword Clue
Pge Outage Map Beaverton
Reahub 1 Twitter
Berklee College Of Music Academic Calendar
Forza Horizon 5: 8 Best Cars For Rally Racing
Dynasty League Forum
Understanding The Payment Structure Behind Online Slot Machines
Panty Note 33
Brake Masters 228
Craigslist Pets Seattle Tacoma Washington
Craigslist Ct Apartments For Rent
Restaurants Near 275 Tremont St Boston
R/Sandiego
Gabrielle Abbate Obituary
Sparkle Nails Phillipsburg
Lily Starfire White Christmas
Weekly Math Review Q4 4 Answer Key | airSlate SignNow
Wv Mugshots 2023
Burlington Antioch Ca
Sarah Colman-Livengood Park Raytown Photos
Sierra At Tahoe Season Pass Costco
Norwegian Luna | Cruise Ship
Gun Show Deridder La
Watch Wrestling.up
Nuefliks.com
MERRY AND MARRIED MERRY & MARRIED MERRY + MARRIED MERRY E MARRIED MERRY ; MARRIED MERRY, MARRIED MERRY - MARRIED Trademark Application of Nexus Integrity Group - Serial Number 98485054 :: Justia Trademarks
1V1 Google Classroom
Bourbon Moth Magnolia
What Is Opm1 Treas 310 Deposit
Latest Posts
Article information

Author: Foster Heidenreich CPA

Last Updated:

Views: 5442

Rating: 4.6 / 5 (56 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Foster Heidenreich CPA

Birthday: 1995-01-14

Address: 55021 Usha Garden, North Larisa, DE 19209

Phone: +6812240846623

Job: Corporate Healthcare Strategist

Hobby: Singing, Listening to music, Rafting, LARPing, Gardening, Quilting, Rappelling

Introduction: My name is Foster Heidenreich CPA, I am a delightful, quaint, glorious, quaint, faithful, enchanting, fine person who loves writing and wants to share my knowledge and understanding with you.