Lowering your azure bill - Log Analytics

Go into Log Analytics workspace and in each run query 

Usage | where IsBillable == true | summarize BillableDataGB = sum(Quantity) / 1024 by DataType | sort by BillableDataGB desc 

 above query will tell you which type of log analytics is eating your budget the most for instance AppDependencies 25GB

1. Reduce Data Sampling Got to your application insight that is associated with Log Analytics workspace then choose Configure -> Usage and estimated costs -> Data sampling and choose 8.3% as an example to drastically reduce the costs.

2. Add custom Dependency Filter in your code.
If you are using function app in .net you can add custom Telemtry Processor that can simply ignore successful dependencies

using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.DataContracts;

public class VlTechDependencyFilter : ITelemetryProcessor
{
    private ITelemetryProcessor Next { get; set; }

    // Next will point to the next TelemetryProcessor in the chain.
    public VlTechDependencyFilter(ITelemetryProcessor next)
    {
        this.Next = next;
    }

    public void Process(ITelemetry item)
    {
        // 1. Identify if this is a Dependency log
        if (item is DependencyTelemetry dependency)
        {
            // 2. If the call was successful, "Return" without calling Next (Drops the data)
            if (dependency.Success == true)
            {
                return;
            }
        }

        // 3. Send everything else (Errors, Spikes, Traces) to Azure
        this.Next.Process(item);
    }
}

in your Program.cs then you can register it

builder.Services.AddApplicationInsightsTelemetryProcessor<VlTechDependencyFilter>();

3. Lower the analytics retention policy

Go to you Log Analytics Workspace and choose specific table that you want to change the retention days, for instance from 90 to 30 days




Comments