Home > OS >  Not sending data to Application Insights from Function App
Not sending data to Application Insights from Function App

Time:02-11

I have Function App and Application Insight services. I've noticed that amount of data which my application sends is big and generates big costs. Can I disable/completely stop sending data to AI without deleting APPINSIGHTS_INSTRUMENTATIONKEY or APPLICATIONINSIGHTS_CONNECTION_STRING? But of course I want keep the both services alive.

Should host.json be configured in some way?

CodePudding user response:

Here is the workaround I did for Optimizing the cost generated by Application Insights Logs:

  • To minimize the number of logs, you can use the higher logging level of logs in host.json as you can see in the below screenshot:

As you can see the minimization of logs here function information log is not produced and the output log is shown in the browser, only the manual logging is shown in the logs/terminal.

enter image description here

And the other ways of reducing the logs and optimizing the AI Cost for Azure Functions:

- Disable unneeded modules: Edit the ApplicationInsights.config to turn off collection modules which are not required.

- Disable telemetry dynamically: To disable telemetry conditionally and dynamically anywhere in the code, set the DisableTelemetry flag on it using TelemetryConfiguration instance.

This code sample prevents the sending of telemetry to Application Insights but not the automatic collection modules from colleting telemetry and in order to remove auto collection modules also, please refer this Microsoft Documentation.

- . Customize Logs Collection:

{
  "Logging": {
    "LogLevel": {
      "Default": "Warning"
    },
    "ApplicationInsights": {
      "LogLevel": {
        "Default": "Information"
      }
    }
  }
}

The following above configuration allows Application Insights to capture all Information logs and severe warning logs. To change this behavior, explicitly override the logging configuration for the provider ApplicationInsights as shown below:

{
  "Logging": {
    "LogLevel": {
      "Default": "Warning"
    }
  }
}

There are few more techniques to manage the data volume used for telemetry data optimizing also like:

  • Sampling:
  • Daily Cap:
  • Pre-aggregate metrics

Please check these references for more information:

  1. Resolve if logs shows twice in Application Insights
  2. Optimizing logging costs of Azure Functions
  3. Configuring or removing the necessary Telemetry Initializers

Also, Please visit my practical workarounds (Ref1, Ref2)to reduce the unnecessary logs and optimize the cost.

  • Related