Applications insights sampling not working for a C# function app

RobertTheBruce 51 Reputation points
2023-10-08T14:44:01.4066667+00:00

I have a C# function app. I am using Application Insights which is Workspace-based. I only want to keep Trace and Exception details. Everything else I don't want. I think the host.json file below is correct

{
  "version": "2.0",
    "logging": {
    "logging": {
      "logLevel": {
        "default": "Warning",
        "Function": "Warning",
        "Host.Aggregator": "Error",
        "Host.Results": "Warning",
        "Microsoft": "Error",
        "Worker": "Error"
      },
      "applicationInsights": {
        "samplingSettings": {
          "isEnabled": true,
          "initialSamplingPercentage": 0,
          "excludedTypes": "Trace;Exception"
        },
        "enableLiveMetrics": false,
        "enableDependencyTracking": false,
        "enablePerformanceCountersCollection": false,
        "httpAutoCollectionOptions": {
          "enableHttpTriggerExtendedInfoCollection": false,
          "enableW3CDistributedTracing": false,
          "enableResponseHeaderInjection": false
        }
      }
    }
  }
}

When I look at estimated costs within the workspace I am being billed for other things. The things I actually want are less than half my usage!

User's image

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Ryan Hill 30,326 Reputation points Microsoft Employee Moderator
    2023-10-10T21:58:29+00:00

    Hi @RobertTheBruce

    You actual configured sampleSettings incorrectly. To only keep trace and exception and trace details, it should be configured with includeTypes set:

    {
      "version": "2.0",
      "logging": {
        "applicationInsights": {
          "samplingSettings": {
            "isEnabled": true,
            "initialSamplingPercentage": 100,
            "maxSamplingPercentage": 100,
            "minSamplingPercentage": 100,
            "samplingPercentageIncreaseTimeout": "00:00:00",
            "samplingPercentageDecreaseTimeout": "00:00:00",
            "includedTypes": "Trace;Exception",
            "excludedTypes": ""
          }
        }
      }
    }
    

    In this example, the includedTypes property is set to Trace;Exception, which means that only trace and exception details will be included in the telemetry data. The excludedTypes property is set to an empty string, which means that no other telemetry types will be excluded.

    You can find more information about configuring sampling in Application Insights in the official documentation.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.