Skip to content

Commit f8b6fa0

Browse files
authored
Merge pull request #172360 from ralarcon/func-prod-monitoring
Add clarification regarding log level changes and guidance for high volume telemetry
2 parents b57e68b + 97bd2c9 commit f8b6fa0

9 files changed

+137
-1
lines changed

articles/azure-functions/configure-monitoring.md

Lines changed: 137 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ms.custom: "contperf-fy21q2"
1111

1212
Azure Functions integrates with Application Insights to better enable you to monitor your function apps. Application Insights, a feature of Azure Monitor, is an extensible Application Performance Management (APM) service that collects data generated by your function app, including information your app writes to logs. Application Insights integration is typically enabled when your function app is created. If your app doesn't have the instrumentation key set, you must first [enable Application Insights integration](#enable-application-insights-integration).
1313

14-
You can use Application Insights without any custom configuration. The default configuration can result in high volumes of data. If you're using a Visual Studio Azure subscription, you might hit your data cap for Application Insights. To learn more about Application Insights costs, see [Manage usage and costs for Application Insights](../azure-monitor/app/pricing.md).
14+
You can use Application Insights without any custom configuration. The default configuration can result in high volumes of data. If you're using a Visual Studio Azure subscription, you might hit your data cap for Application Insights. To learn more about Application Insights costs, see [Manage usage and costs for Application Insights](../azure-monitor/app/pricing.md). For more information, see [Solutions with high-volume of telemetry](#solutions-with-high-volume-of-telemetry).
1515

1616
Later in this article, you learn how to configure and customize the data that your functions send to Application Insights. For a function app, logging is configured in the [host.json] file.
1717

@@ -137,6 +137,16 @@ If [host.json] includes multiple logs that start with the same string, the more
137137

138138
You can use a log level setting of `None` prevent any logs from being written for a category.
139139

140+
> [!CAUTION]
141+
> Azure Functions integrates with Application Insights by storing telemetry events in Application Insights tables, setting a category log level to any value different from `Information` will prevent the telemetry to flow to those tables, as outcome, you will not be able to see the related data in Application Insights or Function Monitor tab.
142+
>
143+
> From above samples:
144+
> * If `Host.Results` category is set to `Error` log level, it will only gather host execution telemetry events in the `requests` table for failed function executions, preventing to display host execution details of success executions in both Application Insights and Function Monitor tab.
145+
> * If `Function` category is set to `Error` log level, it will stop gathering function telemetry data related to `dependencies`, `customMetrics`, and `customEvents` for all the functions, preventing to see any of this data in Application Insights. It will only gather `traces` logged with `Error` level.
146+
>
147+
> In both cases you will continue to collect errors and exceptions data in Application Insights and Function Monitor tab. For more information, see [Solutions with high-volume of telemetry](#solutions-with-high-volume-of-telemetry).
148+
149+
140150
## Configure the aggregator
141151

142152
As noted in the previous section, the runtime aggregates data about function executions over a period of time. The default period is 30 seconds or 1,000 runs, whichever comes first. You can configure this setting in the [host.json] file. Here's an example:
@@ -276,6 +286,132 @@ When you enable Application Insights, disable the built-in logging that uses Azu
276286

277287
To disable built-in logging, delete the `AzureWebJobsDashboard` app setting. For information about how to delete app settings in the Azure portal, see the **Application settings** section of [How to manage a function app](functions-how-to-use-azure-function-app-settings.md#settings). Before you delete the app setting, make sure no existing functions in the same function app use the setting for Azure Storage triggers or bindings.
278288

289+
## Solutions with high volume of telemetry
290+
291+
Your function apps can be an essential part of solutions that by nature cause high volumes of telemetry (IoT solutions, event driven based solutions, high load financial systems, integration systems...). In this case, you should consider extra configuration to reduce costs while maintaining observability.
292+
293+
Depending on how the telemetry generated is going to be consumed, real-time dashboards, alerting, detailed diagnostics, and so on, you will need to define a strategy to reduce the volume of data generated. That strategy will allow you to properly monitor, operate, and diagnose your function apps in production. You can consider the following options:
294+
295+
* **Use sampling**: as mentioned [earlier](#configure-sampling), it will help to dramatically reduce the volume of telemetry events ingested while maintaining a statistically correct analysis. It could happen that even using sampling you still get high volume of telemetry. Inspect the options that [Adaptive sampling](../azure-monitor/app/sampling.md#configuring-adaptive-sampling-for-aspnet-applications) provides to you, for example set the `maxTelemetryItemsPerSecond` to a value that balances the volume generated with your monitoring needs. Keep in mind that the telemetry sampling is applied per host executing your function app.
296+
297+
* **Default log level**: use `Warning` or `Error` as the default value for all telemetry categories. Now you can decide which [categories](#configure-categories) you want to set at `Information` so you can monitor and diagnose your functions properly.
298+
299+
* **Tune your functions telemetry**: with the default log level set to `Error` or `Warning`, no detailed information from each function will be gathered (dependencies, custom metrics, custom events, and traces). For those functions that are key for production monitoring, define an explicit entry for `Function.<YOUR_FUNCTION_NAME>` category and set it to `Information`, so you can gather detailed information. At this point, to avoid gathering [user-generated logs](functions-monitoring.md#writing-to-logs) at `Information` level, set the `Function.<YOUR_FUNCTION_NAME>.User` category to `Error` or `Warning` log level.
300+
301+
* **Host.Aggregator category**: as described in [Configure categories](#configure-categories), this category provides aggregated information of function invocations. The information from this category is gathered in Application Insights `customMetrics` table, and it's shown in the function Overview tab in the Azure portal. Depending on how you configure the aggregator, consider that there will be a delay, determined by the `flushTimeout`, in the telemetry gathered. If you set this category to other value different than `Information`, you will stop gathering the data in the `customMetrics` table and will not display metrics in the function Overview tab.
302+
303+
The following screenshot shows Host.Aggregator telemetry data displayed in the function Overview tab.
304+
:::image type="content" source="media/configure-monitoring/host-aggregator-function-overview.png" alt-text="Screenshot of Host.Aggregator telemetry displayed in function Overview tab." lightbox="media/configure-monitoring/host-aggregator-function-overview-big.png":::
305+
306+
The following screenshot shows Host.Aggregator telemetry data in Application Insights customMetrics table.
307+
:::image type="content" source="media/configure-monitoring/host-aggregator-custom-metrics.png" alt-text="Screenshot of Host.Aggregator telemetry in customMetrics Application Insights table." lightbox="media/configure-monitoring/host-aggregator-custom-metrics-big.png":::
308+
309+
* **Host.Results category**: as described in [Configure categories](#configure-categories), this category provides the runtime-generated logs indicating the success or failure of a function invocation. The information from this category is gathered in the Application Insights `requests` table, and it is shown in the function Monitor tab and in different Application Insights dashboards (Performance, Failures...). If you set this category to other value different than `Information`, you will only gather telemetry generated at the log level defined (or higher), for example, setting it to `error` results in tracking requests data only for failed executions.
310+
311+
The following screenshot shows the Host.Results telemetry data displayed in the function Monitor tab.
312+
:::image type="content" source="media/configure-monitoring/host-results-function-monitor.png" alt-text="Screenshot of Host.Results telemetry in function Monitor tab." lightbox="media/configure-monitoring/host-results-function-monitor-big.png":::
313+
314+
The following screenshot shows Host.Results telemetry data displayed in Application Insights Performance dashboard.
315+
:::image type="content" source="media/configure-monitoring/host-results-application-insights.png" alt-text="Screenshot of Host.Results telemetry in Application Insights Performance dashboard." lightbox="media/configure-monitoring/host-results-application-insights-big.png":::
316+
317+
* **Host.Aggregator vs Host.Results**: both categories provide good insights about function executions, if needed, you can remove the detailed information from one of these categories, so you can use the other for monitoring and alerting.
318+
Here's a sample:
319+
# [v2.x+](#tab/v2)
320+
321+
``` json
322+
{
323+
"version": "2.0",
324+
"logging": {
325+
"logLevel": {
326+
"default": "Warning",
327+
"Function": "Error",
328+
"Host.Aggregator": "Error",
329+
"Host.Results": "Information",
330+
"Function.Function1": "Information",
331+
"Function.Function1.User": "Error"
332+
},
333+
"applicationInsights": {
334+
"samplingSettings": {
335+
"isEnabled": true,
336+
"maxTelemetryItemsPerSecond": 1,
337+
"excludedTypes": "Exception"
338+
}
339+
}
340+
}
341+
}
342+
```
343+
# [v1.x](#tab/v1)
344+
```json
345+
{
346+
"logger": {
347+
"categoryFilter": {
348+
"defaultLevel": "Warning",
349+
"categoryLevels": {
350+
"Function": "Error",
351+
"Host.Aggregator": "Error",
352+
"Host.Results": "Information",
353+
"Host.Executor": "Warning"
354+
}
355+
}
356+
},
357+
"applicationInsights": {
358+
"sampling": {
359+
"isEnabled": true,
360+
"maxTelemetryItemsPerSecond" : 5
361+
}
362+
}
363+
}
364+
```
365+
---
366+
367+
With this configuration, you will have:
368+
369+
* The default value for all functions and telemetry categories is set to `Warning` (including Microsoft and Worker categories) so, by default, all errors and warnings generated by both, the runtime and custom logging, are gathered.
370+
371+
* The `Function` category log level is set to `Error`, so for all functions, by default, only exceptions and error logs will be gathered (dependencies, user-generated metrics, and user-generated events will be skipped).
372+
373+
* For the `Host.Aggregator` category, as it is set to `Error` log level, no aggregated information from function invocations will be gathered in the `customMetrics` Application Insights table, and no information about executions counts (total, successful, failed...) will be shown in the function overview dashboard.
374+
375+
* For the `Host.Results` category, all the host execution information is gathered in the `requests` Application Insights table. All the invocations results will be shown in the function Monitor dashboard and in Application Insights dashboards.
376+
377+
* For the function called `Function1`, we have set the log level to `Information` so, for this concrete function, all the telemetry is gathered (dependency, custom metrics, custom events). For the same function, the `Function1.User` category (user-generated traces) is set to `Error`, so only custom error logging will be gathered. Note that per function configuration is not supported in v1.x.
378+
379+
* Sampling is configured to send one telemetry item per second per type, excluding the exceptions. This sampling will happen for each server host running our function app, so if we have four instances, this configuration will emit four telemetry items per second per type and all the exceptions that might occur. Note that, for metrics counts such as request rate and exception rate are adjusted to compensate for the sampling rate, so that they show approximately correct values in Metric Explorer.
380+
381+
> [!TIP]
382+
> Experiment with different configurations to ensure you cover your requirements for logging, monitoring and alerting. Ensure you have detailed diagnostics in case of unexpected errors or malfunctioning.
383+
384+
### Overriding monitoring configuration at runtime
385+
Finally, there could be situations where you need to quickly change the logging behavior of a certain category in production, and you don't want to make a whole deployment just for a change in the `host.json` file. For such as cases, you can override the [host json values](functions-host-json.md#override-hostjson-values).
386+
387+
388+
To configure these values at App settings level (and avoid redeployment on just host.json changes), you should override specific `host.json` values by creating an equivalent value as an application setting. When the runtime finds an application setting in the format `AzureFunctionsJobHost__path__to__setting`, it overrides the equivalent `host.json` setting located at `path.to.setting` in the JSON. When expressed as an application setting, the dot (`.`) used to indicate JSON hierarchy is replaced by a double underscore (`__`). For example, you can use the below app settings to configure individual function log levels as in `host.json` above.
389+
390+
391+
| Host.json path | App setting |
392+
|----------------|-------------|
393+
| logging.logLevel.default | AzureFunctionsJobHost__logging__logLevel__default |
394+
| logging.logLeve.Host.Aggregator | AzureFunctionsJobHost__logging__logLevel__Host__Aggregator |
395+
| logging.logLevel.Function | AzureFunctionsJobHost__logging__logLevel__Function |
396+
| logging.logLevel.Function.Function1 | AzureFunctionsJobHost__logging__logLevel__Function1 |
397+
| logging.logLevel.Function.Function1.User | AzureFunctionsJobHost__logging__logLevel__Function1.User |
398+
399+
400+
You can override the settings directly at the Azure portal Function App Configuration blade or by using an Azure CLI or PowerShell script.
401+
402+
# [az cli](#tab/v2)
403+
```azurecli-interactive
404+
az functionapp config appsettings set --name MyFunctionApp --resource-group MyResourceGroup --settings "AzureFunctionsJobHost__logging__logLevel__Host__Aggregator=Information"
405+
```
406+
# [PowerShell](#tab/v1)
407+
```powershell
408+
Update-AzFunctionAppSetting -Name MyAppName -ResourceGroupName MyResourceGroupName -AppSetting @{"AzureFunctionsJobHost__logging__logLevel__Host__Aggregator" = "Information"}
409+
```
410+
---
411+
412+
> [!NOTE]
413+
> Overriding the `host.json` through changing app settings will restart your function app.
414+
279415
## Next steps
280416

281417
To learn more about monitoring, see:
535 KB
Loading
213 KB
Loading
414 KB
Loading
112 KB
Loading
493 KB
Loading
199 KB
Loading
352 KB
Loading
133 KB
Loading

0 commit comments

Comments
 (0)